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 getline(&line,&number,conf);
110 asprintf(&line1,"%s %s %s",name,char_index,line);
111 return get_list_param(line1);
115 /*prepare for the next line*/
119 err = getline(&machine_name, &number, conf);
128 "No configuration for %s %d\n", name, mynoderank );
133 char*** get_conf_all(char * filename, int * nb_process){
134 if(filename == NULL) return NULL;
136 char *** all_conf = NULL;
143 conf = fopen(filename, "r");
146 "Try to open the configuration file %s\n", filename);
151 while ((linelen = getline(&line, &linecap, conf)) > 0)
154 conf = fopen(filename, "r");
156 all_conf = malloc(sizeof(char**) * nb_line);
157 /* Try to find the line correponding to this processor */
159 while ((linelen = getline(&line, &linecap, conf)) > 0){
160 if (strcmp(line,"") == 0) continue; //Skip blank line
161 if (line[0] == '#') continue; //Skip comment line
162 all_conf[nb_line] = get_list_param(line);
165 if(nb_process != NULL) *nb_process = nb_line;
170 void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
171 char name[MPI_MAX_PROCESSOR_NAME];
173 MPI_Get_processor_name(name, &len);
174 if(file == NULL) file = stdout;
177 split_comm_intra_node(comm, &comm_node, 0);
179 char ** names = get_names(comm);
180 int* index = get_index( comm, comm_node);
181 MPI_Comm_free(&comm_node);
183 MPI_Comm_size(comm, &size);
186 fprintf(file, "#processor_name index USER ARGS (like the cpu binding ...)\n");
187 for(i = 0; i < size; i++){
188 if(default_options != NULL)
189 fprintf(file, "%s %d %s\n", names[i],index[i],default_options);
191 fprintf(file, "%s %d\n", names[i],index[i]);