-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.c
More file actions
45 lines (41 loc) · 834 Bytes
/
util.c
File metadata and controls
45 lines (41 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "spsa_sim.h"
void params_disp(const char *prompt, int num_params, params_t *p){
printf("%s",prompt);
for(int i=0;i<num_params;i++){
printf("%f ",(*p)[i]);
}
printf("\n");
}
void params_from_string(const char *str_in, params_t *p){
char *str_copy=strdup(str_in);
char *token;
double pp;
token=strtok(str_copy,":,");
pp=atof(token);
for(int i=0;i<MAX_PARAMS;i++){
(*p)[i]=pp;
if(token!=NULL){
token=strtok(NULL,":,");
if(token!=NULL){
pp=atof(token);
}
}
}
free(str_copy);
}
#define NPROC_COMMAND "nproc"
int nproc(void){
char *line=NULL;
size_t len=0;
ssize_t read;
int nproc_;
FILE *f=popen(NPROC_COMMAND,"r");
if(f==NULL){
return 0;
}
read=getline(&line,&len,f);
pclose(f);
nproc_=read>0?atoi(line):1;
free(line);
return nproc_;
}