Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix one, rename another
[simgrid.git] / src / smpi / smpi_global.cpp
index 9a8f5d2..3608667 100644 (file)
@@ -14,6 +14,8 @@
 #include "simgrid/sg_config.h"
 #include "src/mc/mc_replay.h"
 #include "src/msg/msg_private.h"
+#include "src/simix/SynchroComm.hpp"
+
 
 #include <float.h>              /* DBL_MAX */
 #include <stdint.h>
@@ -50,7 +52,6 @@ int* index_to_process_data = NULL;
 extern double smpi_total_benched_time;
 xbt_os_timer_t global_timer;
 MPI_Comm MPI_COMM_WORLD = MPI_COMM_UNINITIALIZED;
-
 MPI_Errhandler *MPI_ERRORS_RETURN = NULL;
 MPI_Errhandler *MPI_ERRORS_ARE_FATAL = NULL;
 MPI_Errhandler *MPI_ERRHANDLER_NULL = NULL;
@@ -78,7 +79,7 @@ void smpi_process_init(int *argc, char ***argv)
   if (argc && argv) {
     proc = SIMIX_process_self();
     //FIXME: dirty cleanup method to avoid using msg cleanup functions on these processes when using MSG+SMPI
-    SIMIX_process_set_cleanup_function(proc, SIMIX_process_cleanup);
+    SIMIX_process_set_cleanup_function(proc, MSG_process_cleanup_from_SIMIX);
     char* instance_id = (*argv)[1];
     int rank = xbt_str_parse_int((*argv)[2], "Invalid rank: %s");
     index = smpi_process_index_of_smx_process(proc);
@@ -336,34 +337,37 @@ void print_request(const char *message, MPI_Request request)
        message, request, request->buf, request->size, request->src, request->dst, request->tag, request->flags);
 }
 
-void smpi_comm_copy_buffer_callback(smx_synchro_t comm, void *buff, size_t buff_size)
+void smpi_comm_copy_buffer_callback(smx_synchro_t synchro, void *buff, size_t buff_size)
 {
   XBT_DEBUG("Copy the data over");
   void* tmpbuff=buff;
+  simgrid::simix::Comm *comm = dynamic_cast<simgrid::simix::Comm*>(synchro);
 
   if((smpi_privatize_global_variables) && ((char*)buff >= smpi_start_data_exe)
       && ((char*)buff < smpi_start_data_exe + smpi_size_data_exe )
     ){
        XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !");
-       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->comm.src_proc))->data))->index);
+
+
+       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->src_proc))->data))->index);
        tmpbuff = (void*)xbt_malloc(buff_size);
        memcpy(tmpbuff, buff, buff_size);
   }
 
-  if((smpi_privatize_global_variables) && ((char*)comm->comm.dst_buff >= smpi_start_data_exe)
-      && ((char*)comm->comm.dst_buff < smpi_start_data_exe + smpi_size_data_exe )){
+  if((smpi_privatize_global_variables) && ((char*)comm->dst_buff >= smpi_start_data_exe)
+      && ((char*)comm->dst_buff < smpi_start_data_exe + smpi_size_data_exe )){
        XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment");
-       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->comm.dst_proc))->data))->index);
+       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->dst_proc))->data))->index);
   }
 
-  memcpy(comm->comm.dst_buff, tmpbuff, buff_size);
-  if (comm->comm.detached) {
+  memcpy(comm->dst_buff, tmpbuff, buff_size);
+  if (comm->detached) {
     // if this is a detached send, the source buffer was duplicated by SMPI
     // sender to make the original buffer available to the application ASAP
     xbt_free(buff);
     //It seems that the request is used after the call there this should be free somewhere else but where???
     //xbt_free(comm->comm.src_data);// inside SMPI the request is kept inside the user data and should be free
-    comm->comm.src_buff = NULL;
+    comm->src_buff = NULL;
   }
 
   if(tmpbuff!=buff)xbt_free(tmpbuff);
@@ -471,11 +475,17 @@ void smpi_global_destroy(void)
   if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){
     smpi_comm_cleanup_smp(MPI_COMM_WORLD);
     smpi_comm_cleanup_attributes(MPI_COMM_WORLD);
+    if(smpi_coll_cleanup_callback!=NULL)
+      smpi_coll_cleanup_callback();
     xbt_free(MPI_COMM_WORLD);
   }
 
   MPI_COMM_WORLD = MPI_COMM_NULL;
 
+  if (!MC_is_active()) {
+    xbt_os_timer_free(global_timer);
+  }
+
   xbt_free(index_to_process_data);
   if(smpi_privatize_global_variables)
     smpi_destroy_global_memory_segments();
@@ -589,6 +599,7 @@ static void smpi_init_options(){
     int barrier_id = find_coll_description(mpi_coll_barrier_description, xbt_cfg_get_string("smpi/barrier"),"barrier");
     mpi_coll_barrier_fun = (int (*)(MPI_Comm comm)) mpi_coll_barrier_description[barrier_id].coll;
 
+    smpi_coll_cleanup_callback=NULL;
     smpi_cpu_threshold = xbt_cfg_get_double("smpi/cpu-threshold");
     smpi_running_power = xbt_cfg_get_double("smpi/running-power");
     smpi_privatize_global_variables = xbt_cfg_get_boolean("smpi/privatize-global-variables");