Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] fixing some memory leaks in smpi instrumentation code
[simgrid.git] / src / smpi / smpi_pmpi.c
index 86cb9d2..c7c901f 100644 (file)
@@ -5,7 +5,6 @@
   * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "private.h"
-#include "smpi_coll_private.h"
 #include "smpi_mpi_dt_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
@@ -13,26 +12,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
 
 #ifdef HAVE_TRACING
 //this function need to be here because of the calls to smpi_bench
-int TRACE_smpi_set_category(const char *category)
+void TRACE_smpi_set_category(const char *category)
 {
   //need to end bench otherwise categories for execution tasks are wrong
   smpi_bench_end();
-  int ret;
-  if (!IS_TRACING){
-    ret = 1;
-  }else{
-    if (category != NULL) {
-      ret = TRACE_category(category);
-      TRACE_category_set(SIMIX_process_self(), category);
-    }else{
-      //if category is NULL, trace of platform is disabled for this process
-      TRACE_category_unset(SIMIX_process_self());
-      ret = 0;
-    }
-  }
+  TRACE_internal_smpi_set_category (category);
   //begin bench after changing process's category
   smpi_bench_begin();
-  return ret;
 }
 #endif
 
@@ -50,6 +36,7 @@ int PMPI_Init(int *argc, char ***argv)
 
 int PMPI_Finalize(void)
 {
+  smpi_process_finalize();
   smpi_bench_end();
 #ifdef HAVE_TRACING
   TRACE_smpi_finalize(smpi_process_index());
@@ -101,7 +88,7 @@ int PMPI_Abort(MPI_Comm comm, int errorcode)
   smpi_bench_end();
   smpi_process_destroy();
   // FIXME: should kill all processes in comm instead
-  SIMIX_process_kill(SIMIX_process_self());
+  SIMIX_req_process_kill(SIMIX_process_self());
   return MPI_SUCCESS;
 }
 
@@ -636,6 +623,8 @@ int PMPI_Comm_rank(MPI_Comm comm, int *rank)
   smpi_bench_end();
   if (comm == MPI_COMM_NULL) {
     retval = MPI_ERR_COMM;
+  } else if (rank == NULL) {
+    retval = MPI_ERR_ARG;
   } else {
     *rank = smpi_comm_rank(comm);
     retval = MPI_SUCCESS;
@@ -661,6 +650,23 @@ int PMPI_Comm_size(MPI_Comm comm, int *size)
   return retval;
 }
 
+int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
+{
+  int retval;
+
+  smpi_bench_end();
+  if (comm == MPI_COMM_NULL)  {
+    retval = MPI_ERR_COMM;
+  } else if (name == NULL || len == NULL)  {
+    retval = MPI_ERR_ARG;
+  } else {
+    smpi_comm_get_name(comm, name, len);
+    retval = MPI_SUCCESS;
+  }
+  smpi_bench_begin();
+  return retval;
+}
+
 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
 {
   int retval;
@@ -758,6 +764,25 @@ int PMPI_Comm_free(MPI_Comm * comm)
   return retval;
 }
 
+int PMPI_Comm_disconnect(MPI_Comm * comm)
+{
+  /* TODO: wait until all communication in comm are done */
+  int retval;
+
+  smpi_bench_end();
+  if (comm == NULL) {
+    retval = MPI_ERR_ARG;
+  } else if (*comm == MPI_COMM_NULL) {
+    retval = MPI_ERR_COMM;
+  } else {
+    smpi_comm_destroy(*comm);
+    *comm = MPI_COMM_NULL;
+    retval = MPI_SUCCESS;
+  }
+  smpi_bench_begin();
+  return retval;
+}
+
 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
 {
   int retval;
@@ -1088,9 +1113,9 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
 #ifdef HAVE_TRACING
   //save requests information for tracing
   int i;
-  xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), xbt_free);
-  xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), xbt_free);
-  xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), xbt_free);
+  xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
+  xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
+  xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
   for (i = 0; i < count; i++) {
     MPI_Request req = requests[i];      //already received requests are no longer valid
     if (req) {
@@ -1103,11 +1128,15 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
       xbt_dynar_insert_at(srcs, i, asrc);
       xbt_dynar_insert_at(dsts, i, adst);
       xbt_dynar_insert_at(recvs, i, arecv);
+      xbt_free(asrc);
+      xbt_free(adst);
+      xbt_free(arecv);
     } else {
       int *t = xbt_new(int, 1);
       xbt_dynar_insert_at(srcs, i, t);
       xbt_dynar_insert_at(dsts, i, t);
       xbt_dynar_insert_at(recvs, i, t);
+      xbt_free(t);
     }
   }
   int rank_traced = smpi_comm_rank(MPI_COMM_WORLD);
@@ -1129,9 +1158,9 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
   }
   TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
   //clean-up of dynars
-  xbt_free(srcs);
-  xbt_free(dsts);
-  xbt_free(recvs);
+  xbt_dynar_free(&srcs);
+  xbt_dynar_free(&dsts);
+  xbt_dynar_free(&recvs);
 #endif
   smpi_bench_begin();
   return retval;
@@ -1144,9 +1173,9 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
 #ifdef HAVE_TRACING
   //save information from requests
   int i;
-  xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), xbt_free);
-  xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), xbt_free);
-  xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), xbt_free);
+  xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
+  xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
+  xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
   for (i = 0; i < count; i++) {
     MPI_Request req = requests[i];      //all req should be valid in Waitall
     int *asrc = xbt_new(int, 1);
@@ -1158,6 +1187,9 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
     xbt_dynar_insert_at(srcs, i, asrc);
     xbt_dynar_insert_at(dsts, i, adst);
     xbt_dynar_insert_at(recvs, i, arecv);
+    xbt_free(asrc);
+    xbt_free(adst);
+    xbt_free(arecv);
   }
   int rank_traced = smpi_comm_rank (MPI_COMM_WORLD);
   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
@@ -1175,9 +1207,9 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
   }
   TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
   //clean-up of dynars
-  xbt_free(srcs);
-  xbt_free(dsts);
-  xbt_free(recvs);
+  xbt_dynar_free(&srcs);
+  xbt_dynar_free(&dsts);
+  xbt_dynar_free(&recvs);
 #endif
   smpi_bench_begin();
   return MPI_SUCCESS;