Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[examples,smpi,MM] remove a useless function
[simgrid.git] / examples / smpi / MM / param.c
index 3cab7f9..0d932fb 100644 (file)
@@ -1,8 +1,6 @@
 /*!
  * get the parameter specific to the process from a file
  *
- *
- * Authors: Quintin Jean-Noël
  */
 
 #include "topo.h"
@@ -15,6 +13,8 @@
 XBT_LOG_NEW_DEFAULT_CATEGORY(MM_param,
                              "Messages specific for this msg example");
 
+int match(const char *s, char p);
+char** get_list_param(const char* input);
 int match(const char *s, char p)
 {
   int c = 0;
@@ -43,7 +43,7 @@ char** get_list_param(const char* input){
   return list_param;
 }
 
-char** get_conf(MPI_Comm comm, char * filename, int mynoderank)
+char** get_conf(MPI_Comm comm, const char * filename, int mynoderank)
 {
   if(filename == NULL) return NULL;
   if(mynoderank == -1){
@@ -103,7 +103,8 @@ char** get_conf(MPI_Comm comm, char * filename, int mynoderank)
          * we rebuild the line to get every information*/
         char* line = NULL;
         number = 0;
-        getline(&line,&number,conf);
+        if (getline(&line,&number,conf) == -1)
+          xbt_die("Cannot get line");
         char* line1 = NULL;
         asprintf(&line1,"%s %s %s",name,char_index,line);
         return get_list_param(line1);
@@ -128,41 +129,6 @@ char** get_conf(MPI_Comm comm, char * filename, int mynoderank)
 }
 
 
-char*** get_conf_all(char * filename, int * nb_process){
-  if(filename == NULL) return NULL;
-
-  char *** all_conf = NULL;
-  FILE* conf;
-  int nb_line = 0;
-  char *line = NULL;
-  size_t linecap = 0;
-  ssize_t linelen;
-
-  conf = fopen(filename, "r");
-  if (conf == NULL) {
-    XBT_DEBUG(
-              "Try to open the configuration file %s\n", filename);
-    perror("fopen");
-    return NULL;
-  }
-
-  while ((linelen = getline(&line, &linecap, conf)) > 0)
-    nb_line++;
-  fclose(conf);
-  conf = fopen(filename, "r");
-
-  all_conf = malloc(sizeof(char**) * nb_line);
-  /* Try to find the line correponding to this processor */
-  nb_line = 0;
-  while ((linelen = getline(&line, &linecap, conf)) > 0){
-    if (strcmp(line,"") == 0) continue; //Skip blank line
-    if (line[0] == '#') continue; //Skip comment line
-    all_conf[nb_line] = get_list_param(line);
-    nb_line++;
-  }
-  if(nb_process != NULL) *nb_process = nb_line;
-  return all_conf;
-}
 
 
 void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
@@ -170,7 +136,6 @@ void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
   int len;
   MPI_Get_processor_name(name, &len);
   if(file == NULL) file = stdout;
-  if(default_options == NULL) default_options = "";
 
   MPI_Comm comm_node;
   split_comm_intra_node(comm, &comm_node, 0);
@@ -184,7 +149,10 @@ void print_conf(MPI_Comm comm, int rank, FILE* file, char * default_options){
   if(rank == 0){
     fprintf(file, "#processor_name index USER ARGS (like the cpu binding ...)\n");
     for(i = 0; i < size; i++){
-      fprintf(file, "%s %d %s\n", names[i],index[i],default_options);
+      if(default_options != NULL)
+        fprintf(file, "%s %d %s\n", names[i],index[i],default_options);
+      else
+        fprintf(file, "%s %d\n", names[i],index[i]);
     }
   }
   free(names);