Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memory leaks in smpi.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 21 Feb 2013 13:41:40 +0000 (14:41 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 21 Feb 2013 15:46:39 +0000 (16:46 +0100)
12 files changed:
src/smpi/instr_smpi.c
src/smpi/smpi_base.c
src/smpi/smpi_bench.c
src/smpi/smpi_global.c
src/smpi/smpi_mpi_dt.c
src/smpi/smpi_replay.c
src/surf/network.c
src/xbt/xbt_replay.c
teshsuite/smpi/hvector_test.c
teshsuite/smpi/indexed_test.c
teshsuite/smpi/struct_test.c
teshsuite/smpi/vector_test.c

index b4239be..2aa3d53 100644 (file)
@@ -142,7 +142,7 @@ const char *TRACE_internal_smpi_get_category (void)
 
 void TRACE_smpi_alloc()
 {
 
 void TRACE_smpi_alloc()
 {
-  keys = xbt_dict_new_homogeneous(xbt_free);
+  keys = xbt_dict_new_homogeneous(xbt_dynar_free_voidp);
   process_category = xbt_dict_new_homogeneous(xbt_free);
 }
 
   process_category = xbt_dict_new_homogeneous(xbt_free);
 }
 
index 8cb1cc8..1d5e805 100644 (file)
@@ -119,10 +119,10 @@ static xbt_dynar_t parse_factor(const char *smpi_coef_string)
 
 static double smpi_os(double size)
 {
 
 static double smpi_os(double size)
 {
-  if (!smpi_os_values)
-    smpi_os_values =
-        parse_factor(sg_cfg_get_string("smpi/os"));
-
+  if (!smpi_os_values) {
+    smpi_os_values = parse_factor(sg_cfg_get_string("smpi/os"));
+    smpi_register_static(smpi_os_values, xbt_dynar_free_voidp);
+  }
   unsigned int iter = 0;
   s_smpi_factor_t fact;
   double current=0.0;
   unsigned int iter = 0;
   s_smpi_factor_t fact;
   double current=0.0;
@@ -141,10 +141,10 @@ static double smpi_os(double size)
 
 static double smpi_ois(double size)
 {
 
 static double smpi_ois(double size)
 {
-  if (!smpi_ois_values)
-    smpi_ois_values =
-        parse_factor(sg_cfg_get_string("smpi/ois"));
-
+  if (!smpi_ois_values) {
+    smpi_ois_values = parse_factor(sg_cfg_get_string("smpi/ois"));
+    smpi_register_static(smpi_ois_values, xbt_dynar_free_voidp);
+  }
   unsigned int iter = 0;
   s_smpi_factor_t fact;
   double current=0.0;
   unsigned int iter = 0;
   s_smpi_factor_t fact;
   double current=0.0;
@@ -163,10 +163,10 @@ static double smpi_ois(double size)
 
 static double smpi_or(double size)
 {
 
 static double smpi_or(double size)
 {
-  if (!smpi_or_values)
-    smpi_or_values =
-        parse_factor(sg_cfg_get_string("smpi/or"));
-
+  if (!smpi_or_values) {
+    smpi_or_values = parse_factor(sg_cfg_get_string("smpi/or"));
+    smpi_register_static(smpi_or_values, xbt_dynar_free_voidp);
+  }
   unsigned int iter = 0;
   s_smpi_factor_t fact;
   double current=0.0;
   unsigned int iter = 0;
   s_smpi_factor_t fact;
   double current=0.0;
index ca628b9..18e4205 100644 (file)
@@ -273,7 +273,7 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr
     data->benching = !sample_enough_benchs(data);
     XBT_DEBUG("XXXX Re-entering the benched nest %s. %s",loc, (data->benching?"more benching needed":"we have enough data, skip computes"));
   }
     data->benching = !sample_enough_benchs(data);
     XBT_DEBUG("XXXX Re-entering the benched nest %s. %s",loc, (data->benching?"more benching needed":"we have enough data, skip computes"));
   }
-  free(loc);
+  xbt_free(loc);
 }
 
 int smpi_sample_2(int global, const char *file, int line)
 }
 
 int smpi_sample_2(int global, const char *file, int line)
@@ -284,7 +284,7 @@ int smpi_sample_2(int global, const char *file, int line)
   xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   data = xbt_dict_get(samples, loc);
   XBT_DEBUG("sample2 %s",loc);
   xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   data = xbt_dict_get(samples, loc);
   XBT_DEBUG("sample2 %s",loc);
-  free(loc);
+  xbt_free(loc);
 
   if (data->benching==1) {
     // we need to run a new bench
 
   if (data->benching==1) {
     // we need to run a new bench
@@ -313,6 +313,7 @@ void smpi_sample_3(int global, const char *file, int line)
   xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   data = xbt_dict_get(samples, loc);
   XBT_DEBUG("sample3 %s",loc);
   xbt_assert(samples, "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   data = xbt_dict_get(samples, loc);
   XBT_DEBUG("sample3 %s",loc);
+  xbt_free(loc);
 
   if (data->benching==0) {
     THROW_IMPOSSIBLE;
 
   if (data->benching==0) {
     THROW_IMPOSSIBLE;
index 22f52d7..2722a17 100644 (file)
@@ -272,6 +272,7 @@ void smpi_global_destroy(void)
   smpi_comm_destroy(MPI_COMM_WORLD);
   MPI_COMM_WORLD = MPI_COMM_NULL;
   for (i = 0; i < count; i++) {
   smpi_comm_destroy(MPI_COMM_WORLD);
   MPI_COMM_WORLD = MPI_COMM_NULL;
   for (i = 0; i < count; i++) {
+    smpi_group_destroy(smpi_comm_group(process_data[i]->comm_self));
     smpi_comm_destroy(process_data[i]->comm_self);
     xbt_os_timer_free(process_data[i]->timer);
     simcall_rdv_destroy(process_data[i]->mailbox);
     smpi_comm_destroy(process_data[i]->comm_self);
     xbt_os_timer_free(process_data[i]->timer);
     simcall_rdv_destroy(process_data[i]->mailbox);
index 19f0228..06123eb 100644 (file)
@@ -311,6 +311,7 @@ void smpi_datatype_free(MPI_Datatype* type){
 
   if ((*type)->has_subtype == 1){
     ((s_smpi_subtype_t *)(*type)->substruct)->subtype_free(type);  
 
   if ((*type)->has_subtype == 1){
     ((s_smpi_subtype_t *)(*type)->substruct)->subtype_free(type);  
+    xbt_free((*type)->substruct);
   }
   xbt_free(*type);
 
   }
   xbt_free(*type);
 
index d7990bf..dfc0d22 100644 (file)
@@ -14,7 +14,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_replay,smpi,"Trace Replay with SMPI");
 
 int communicator_size = 0;
 static int active_processes = 0;
 
 int communicator_size = 0;
 static int active_processes = 0;
-xbt_dynar_t *reqq;
+xbt_dynar_t *reqq = NULL;
 
 MPI_Datatype MPI_DEFAULT_TYPE, MPI_CURRENT_TYPE;
 
 
 MPI_Datatype MPI_DEFAULT_TYPE, MPI_CURRENT_TYPE;
 
@@ -95,10 +95,12 @@ static void action_init(const char *const *action)
   /*initialize the number of active processes */
   active_processes = smpi_process_count();
 
   /*initialize the number of active processes */
   active_processes = smpi_process_count();
 
-  reqq=xbt_new0(xbt_dynar_t,active_processes);
+  if (!reqq) {
+    reqq=xbt_new0(xbt_dynar_t,active_processes);
   
   
-  for(i=0;i<active_processes;i++){
-    reqq[i]=xbt_dynar_new(sizeof(MPI_Request),NULL);
+    for(i=0;i<active_processes;i++){
+      reqq[i]=xbt_dynar_new(sizeof(MPI_Request),NULL);
+    }
   }
 }
 
   }
 }
 
@@ -623,13 +625,17 @@ int smpi_replay_finalize(){
   double sim_time= 1.;
   /* One active process will stop. Decrease the counter*/
   active_processes--;
   double sim_time= 1.;
   /* One active process will stop. Decrease the counter*/
   active_processes--;
+  XBT_DEBUG("There are %lu elements in reqq[*]",
+            xbt_dynar_length(reqq[smpi_comm_rank(MPI_COMM_WORLD)]));
+  xbt_dynar_free(&reqq[smpi_comm_rank(MPI_COMM_WORLD)]);
   if(!active_processes){
     /* Last process alive speaking */
     /* end the simulated timer */
   if(!active_processes){
     /* Last process alive speaking */
     /* end the simulated timer */
-    xbt_dynar_free(reqq);
     sim_time = smpi_process_simulated_elapsed();
     XBT_INFO("Simulation time %g", sim_time);
     _xbt_replay_action_exit();
     sim_time = smpi_process_simulated_elapsed();
     XBT_INFO("Simulation time %g", sim_time);
     _xbt_replay_action_exit();
+    xbt_free(reqq);
+    reqq = NULL;
   }
   return PMPI_Finalize();
 }
   }
   return PMPI_Finalize();
 }
index b83aeee..2eee39c 100644 (file)
@@ -665,10 +665,9 @@ static void net_finalize(void)
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
 
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
 
-  if (smpi_bw_factor)
-    xbt_dynar_free(&smpi_bw_factor);
-  if (smpi_lat_factor)
-    xbt_dynar_free(&smpi_lat_factor);
+  xbt_dict_free(&gap_lookup);
+  xbt_dynar_free(&smpi_bw_factor);
+  xbt_dynar_free(&smpi_lat_factor);
 }
 
 static void smpi_gap_append(double size, const link_CM02_t link,
 }
 
 static void smpi_gap_append(double size, const link_CM02_t link,
index 10435c4..d4937e8 100644 (file)
@@ -152,14 +152,13 @@ int xbt_replay_action_runner(int argc, char *argv[])
     xbt_replay_reader_t reader = xbt_replay_reader_new(argv[1]);
     while ((evt=xbt_replay_reader_get(reader))) {
       if (!strcmp(argv[0],evt[0])) {
     xbt_replay_reader_t reader = xbt_replay_reader_new(argv[1]);
     while ((evt=xbt_replay_reader_get(reader))) {
       if (!strcmp(argv[0],evt[0])) {
-        action_fun function =
-          (action_fun)xbt_dict_get(action_funs, evt[1]);
+        action_fun function = (action_fun)xbt_dict_get(action_funs, evt[1]);
         function(evt);
         function(evt);
-        free(evt);
       } else {
         XBT_WARN("%s: Ignore trace element not for me",
               xbt_replay_reader_position(reader));
       }
       } else {
         XBT_WARN("%s: Ignore trace element not for me",
               xbt_replay_reader_position(reader));
       }
+      free(evt);
     }
     xbt_replay_reader_free(&reader);
   }
     }
     xbt_replay_reader_free(&reader);
   }
index da16a74..f3cb04f 100644 (file)
@@ -35,7 +35,7 @@ int main(int argc, char **argv) {
     }
 
 
     }
 
 
-
+  MPI_Type_free(&columntype);
   MPI_Finalize();
   return 0;
 }
   MPI_Finalize();
   return 0;
 }
index 3afb440..5d2dac0 100644 (file)
@@ -42,6 +42,8 @@ int main(int argc, char *argv[])
         fflush(stdout);
     }
 
         fflush(stdout);
     }
 
+    MPI_Type_free(&type);
+    MPI_Type_free(&type2);
     MPI_Finalize();
     return 0;
 }
     MPI_Finalize();
     return 0;
 }
index 5c73e38..11827c6 100644 (file)
@@ -62,6 +62,7 @@ char **argv;
 
     /* Clean up the type */
     MPI_Type_free( &mystruct );
 
     /* Clean up the type */
     MPI_Type_free( &mystruct );
+    MPI_Type_free( &type2 );
     MPI_Finalize( );
     return 0;
 }
     MPI_Finalize( );
     return 0;
 }
index ce84eac..ea41ec2 100644 (file)
@@ -35,7 +35,7 @@ int main(int argc, char **argv) {
     }
 
 
     }
 
 
-
+  MPI_Type_free(&columntype);
   MPI_Finalize();
   return 0;
 }
   MPI_Finalize();
   return 0;
 }