2 * get the parameter specific to the process from a file
13 XBT_LOG_NEW_DEFAULT_CATEGORY(MM_param,
14 "Messages specific for this msg example");
16 int match(const char *s, char p);
17 char** get_list_param(const char* input);
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, const 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 if (getline(&line,&number,conf) == -1)
107 xbt_die("Cannot get line");
109 asprintf(&line1,"%s %s %s",name,char_index,line);
110 return get_list_param(line1);
114 /*prepare for the next line*/
118 err = getline(&machine_name, &number, conf);
127 "No configuration for %s %d\n", name, mynoderank );
132 char*** get_conf_all(char * filename, int * nb_process){
133 if(filename == NULL) return NULL;
135 char *** all_conf = NULL;
142 conf = fopen(filename, "r");
145 "Try to open the configuration file %s\n", filename);
150 while ((linelen = getline(&line, &linecap, conf)) > 0)
153 conf = fopen(filename, "r");
155 all_conf = malloc(sizeof(char**) * nb_line);
156 /* Try to find the line correponding to this processor */
158 while ((linelen = getline(&line, &linecap, conf)) > 0){
159 if (strcmp(line,"") == 0) continue; //Skip blank line
160 if (line[0] == '#') continue; //Skip comment line
161 all_conf[nb_line] = get_list_param(line);
164 if(nb_process != NULL) *nb_process = nb_line;
169 void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
170 char name[MPI_MAX_PROCESSOR_NAME];
172 MPI_Get_processor_name(name, &len);
173 if(file == NULL) file = stdout;
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 if(default_options != NULL)
188 fprintf(file, "%s %d %s\n", names[i],index[i],default_options);
190 fprintf(file, "%s %d\n", names[i],index[i]);