2 * get the parameter specific to the process from a file
5 * Authors: Quintin Jean-Noël
15 XBT_LOG_NEW_DEFAULT_CATEGORY(MM_param,
16 "Messages specific for this msg example");
18 int match(const char *s, char p);
19 char** get_list_param(const char* input);
20 int match(const char *s, char p)
24 if (strncmp(s++, &p, 1)) continue;
30 char** get_list_param(const char* input){
31 if(input==NULL) return NULL;
32 char *line = strdup(input);
33 int size = match(line, ' ');
34 char **list_param = malloc(size*sizeof(char*));
35 char *pch = strtok (line," \t\n");
39 if(strcmp(pch,"") != 0 ) {
43 pch = strtok (NULL, " \t\n");
48 char** get_conf(MPI_Comm comm, const char * filename, int mynoderank)
50 if(filename == NULL) return NULL;
53 split_comm_intra_node(comm, &comm_node, -1);
54 MPI_Comm_rank ( comm_node, &mynoderank );
55 MPI_Comm_free(&comm_node);
57 char name[MPI_MAX_PROCESSOR_NAME];
59 MPI_Get_processor_name(name, &len);
61 conf = fopen(filename, "r");
64 "Try to open the configuration file %s\n", filename);
68 char *machine_name = NULL;
74 /* Try to find the line correponding to this processor */
75 while((err = getdelim(&machine_name, &number, ' ', conf)) != -1) {
77 err = getdelim(&machine_name, &number, ' ', conf);
81 "read: %s cmp to %s\n", machine_name, name);
82 /* the first element is in machine_name
83 it's normally a processor name */
84 /* remove the delimiter before doing the comparison*/
85 machine_name[strlen(machine_name)-1] = 0;
87 if(strcmp(machine_name,name) == 0){
88 /* the machine name match */
90 /* try to get for which process with the index*/
91 char* char_index=NULL;
92 err = getdelim(&char_index, &number, ' ', conf);
94 err = getdelim(&char_index, &number, ' ', conf);
98 index=atoi(char_index);
100 "read: %d cmp to %d\n",
103 if(index == mynoderank){
104 /* we have found the good line
105 * we rebuild the line to get every information*/
108 if (getline(&line,&number,conf) == -1)
109 xbt_die("Cannot get line");
111 asprintf(&line1,"%s %s %s",name,char_index,line);
112 return get_list_param(line1);
116 /*prepare for the next line*/
120 err = getline(&machine_name, &number, conf);
129 "No configuration for %s %d\n", name, mynoderank );
134 char*** get_conf_all(char * filename, int * nb_process){
135 if(filename == NULL) return NULL;
137 char *** all_conf = NULL;
144 conf = fopen(filename, "r");
147 "Try to open the configuration file %s\n", filename);
152 while ((linelen = getline(&line, &linecap, conf)) > 0)
155 conf = fopen(filename, "r");
157 all_conf = malloc(sizeof(char**) * nb_line);
158 /* Try to find the line correponding to this processor */
160 while ((linelen = getline(&line, &linecap, conf)) > 0){
161 if (strcmp(line,"") == 0) continue; //Skip blank line
162 if (line[0] == '#') continue; //Skip comment line
163 all_conf[nb_line] = get_list_param(line);
166 if(nb_process != NULL) *nb_process = nb_line;
171 void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
172 char name[MPI_MAX_PROCESSOR_NAME];
174 MPI_Get_processor_name(name, &len);
175 if(file == NULL) file = stdout;
178 split_comm_intra_node(comm, &comm_node, 0);
180 char ** names = get_names(comm);
181 int* index = get_index( comm, comm_node);
182 MPI_Comm_free(&comm_node);
184 MPI_Comm_size(comm, &size);
187 fprintf(file, "#processor_name index USER ARGS (like the cpu binding ...)\n");
188 for(i = 0; i < size; i++){
189 if(default_options != NULL)
190 fprintf(file, "%s %d %s\n", names[i],index[i],default_options);
192 fprintf(file, "%s %d\n", names[i],index[i]);