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)
22 if (strncmp(s++, &p, 1)) continue;
28 char** get_list_param(const char* input){
29 if(input==NULL) return NULL;
30 char *line = strdup(input);
31 int size = match(line, ' ');
32 char **list_param = malloc(size*sizeof(char*));
33 char *pch = strtok (line," \t\n");
37 if(strcmp(pch,"") != 0 ) {
41 pch = strtok (NULL, " \t\n");
46 char** get_conf(MPI_Comm comm, char * filename, int mynoderank)
48 if(filename == NULL) return NULL;
51 split_comm_intra_node(comm, &comm_node, -1);
52 MPI_Comm_rank ( comm_node, &mynoderank );
53 MPI_Comm_free(&comm_node);
55 char name[MPI_MAX_PROCESSOR_NAME];
57 MPI_Get_processor_name(name, &len);
59 conf = fopen(filename, "r");
62 "Try to open the configuration file %s\n", filename);
66 char *machine_name = NULL;
72 /* Try to find the line correponding to this processor */
73 while((err = getdelim(&machine_name, &number, ' ', conf)) != -1) {
75 err = getdelim(&machine_name, &number, ' ', conf);
79 "read: %s cmp to %s\n", machine_name, name);
80 /* the first element is in machine_name
81 it's normally a processor name */
82 /* remove the delimiter before doing the comparison*/
83 machine_name[strlen(machine_name)-1] = 0;
85 if(strcmp(machine_name,name) == 0){
86 /* the machine name match */
88 /* try to get for which process with the index*/
89 char* char_index=NULL;
90 err = getdelim(&char_index, &number, ' ', conf);
92 err = getdelim(&char_index, &number, ' ', conf);
96 index=atoi(char_index);
98 "read: %d cmp to %d\n",
101 if(index == mynoderank){
102 /* we have found the good line
103 * we rebuild the line to get every information*/
106 getline(&line,&number,conf);
108 asprintf(&line1,"%s %s %s",name,char_index,line);
109 return get_list_param(line1);
113 /*prepare for the next line*/
117 err = getline(&machine_name, &number, conf);
126 "No configuration for %s %d\n", name, mynoderank );
131 char*** get_conf_all(char * filename, int * nb_process){
132 if(filename == NULL) return NULL;
134 char *** all_conf = NULL;
141 conf = fopen(filename, "r");
144 "Try to open the configuration file %s\n", filename);
149 while ((linelen = getline(&line, &linecap, conf)) > 0)
152 conf = fopen(filename, "r");
154 all_conf = malloc(sizeof(char**) * nb_line);
155 /* Try to find the line correponding to this processor */
157 while ((linelen = getline(&line, &linecap, conf)) > 0){
158 if (strcmp(line,"") == 0) continue; //Skip blank line
159 if (line[0] == '#') continue; //Skip comment line
160 all_conf[nb_line] = get_list_param(line);
163 if(nb_process != NULL) *nb_process = nb_line;
168 void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
169 char name[MPI_MAX_PROCESSOR_NAME];
171 MPI_Get_processor_name(name, &len);
172 if(file == NULL) file = stdout;
173 if(default_options == NULL) default_options = "";
176 split_comm_intra_node(comm, &comm_node, 0);
178 char ** names = get_names(comm);
179 int* index = get_index( comm, comm_node);
180 MPI_Comm_free(&comm_node);
182 MPI_Comm_size(comm, &size);
185 fprintf(file, "#processor_name index USER ARGS (like the cpu binding ...)\n");
186 for(i = 0; i < size; i++){
187 fprintf(file, "%s %d %s\n", names[i],index[i],default_options);