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 );
134 void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
135 char name[MPI_MAX_PROCESSOR_NAME];
137 MPI_Get_processor_name(name, &len);
138 if(file == NULL) file = stdout;
141 split_comm_intra_node(comm, &comm_node, 0);
143 char ** names = get_names(comm);
144 int* index = get_index( comm, comm_node);
145 MPI_Comm_free(&comm_node);
147 MPI_Comm_size(comm, &size);
150 fprintf(file, "#processor_name index USER ARGS (like the cpu binding ...)\n");
151 for(i = 0; i < size; i++){
152 if(default_options != NULL)
153 fprintf(file, "%s %d %s\n", names[i],index[i],default_options);
155 fprintf(file, "%s %d\n", names[i],index[i]);