Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge remote-tracking branch 'origin/master'
authorLuka Stanisic <luka.stanisic@imag.fr>
Fri, 11 Dec 2015 14:25:39 +0000 (15:25 +0100)
committerLuka Stanisic <luka.stanisic@imag.fr>
Fri, 11 Dec 2015 14:25:39 +0000 (15:25 +0100)
include/simgrid/simix.h
include/smpi/smpi.h
src/simix/smx_global.cpp
src/simix/smx_process.cpp
src/simix/smx_process_private.h
src/smpi/private.h
src/smpi/smpi_bench.c
src/smpi/smpi_global.c
src/smpi/smpi_pmpi.c

index 9505538..2c8bdf4 100644 (file)
@@ -230,6 +230,7 @@ XBT_PUBLIC(void) SIMIX_process_set_context(smx_process_t p,smx_context_t c);
 XBT_PUBLIC(int) SIMIX_process_has_pending_comms(smx_process_t process);
 XBT_PUBLIC(void) SIMIX_process_on_exit_runall(smx_process_t process);
 XBT_PUBLIC(void) SIMIX_process_on_exit(smx_process_t process, int_f_pvoid_pvoid_t fun, void *data);
+XBT_PUBLIC(xbt_main_func_t) SIMIX_process_get_code(void);
 
 /****************************** Communication *********************************/
 XBT_PUBLIC(void) SIMIX_comm_set_copy_data_callback(void (*callback) (smx_synchro_t, void*, size_t));
index 429f818..16e95d6 100644 (file)
@@ -830,6 +830,8 @@ MPI_CALL(XBT_PUBLIC(int),  MPI_Win_wait,(MPI_Win win));
 // smpi functions
 XBT_PUBLIC(int) smpi_global_size(void);
 XBT_PUBLIC(MPI_Comm) smpi_process_comm_self(void);
+XBT_PUBLIC(void*) smpi_process_get_user_data(void);
+XBT_PUBLIC(void) smpi_process_set_user_data(void *);
 /*
 XBT_PUBLIC(void) smpi_exit(int);
 */
index ea20087..3ba0e93 100644 (file)
@@ -55,6 +55,8 @@ typedef struct s_smx_timer {
   void* args;
 } s_smx_timer_t;
 
+void (*SMPI_switch_data_segment)(int) = NULL;
+
 static void* SIMIX_synchro_mallocator_new_f(void);
 static void SIMIX_synchro_mallocator_free_f(void* synchro);
 static void SIMIX_synchro_mallocator_reset_f(void* synchro);
index b56bae0..bc84eb7 100644 (file)
 #include "src/mc/mc_client.h"
 #include "src/simix/smx_private.hpp"
 
+#ifdef HAVE_SMPI
+#include "src/smpi/private.h"
+#endif
+
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
                                 "Logging specific to SIMIX (process)");
 
@@ -262,9 +266,20 @@ smx_process_t SIMIX_process_create(
     process->data = data;
     process->comms = xbt_fifo_new();
     process->simcall.issuer = process;
+    /* Initiliaze data segment to default value */
+    SIMIX_segment_index_set(process, -1);
 
-     if (parent_process) {
+     if (parent_process != NULL) {
        process->ppid = SIMIX_process_get_PID(parent_process);
+       /* SMPI process have their own data segment and
+          each other inherit from their father */
+       if(smpi_privatize_global_variables){
+         if( parent_process->pid != 0){
+           SIMIX_segment_index_set(process, parent_process->segment_index);
+         } else {
+           SIMIX_segment_index_set(process, process->pid - 1);
+         }
+       }
      } else {
        process->ppid = -1;
      }
@@ -655,6 +670,10 @@ sg_host_t SIMIX_process_get_host(smx_process_t process)
   return process->host;
 }
 
+xbt_main_func_t SIMIX_process_get_code(void){
+  return SIMIX_process_self()->code;
+}
+
 /* needs to be public and without simcall because it is called
    by exceptions and logging events */
 const char* SIMIX_process_self_get_name(void) {
@@ -875,6 +894,9 @@ void SIMIX_process_yield(smx_process_t self)
     SMX_THROW();
   }
 
+  if(SMPI_switch_data_segment && self->segment_index != -1){
+    SMPI_switch_data_segment(self->segment_index);
+  }
 }
 
 /* callback: context fetching */
@@ -1014,3 +1036,7 @@ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer)
   }
   return new_process;
 }
+
+void SIMIX_segment_index_set(smx_process_t proc, int index){
+  proc->segment_index = index;
+}
index f537925..febf7a5 100644 (file)
@@ -61,6 +61,7 @@ typedef struct s_smx_process {
   int argc;
   char **argv;
   smx_timer_t kill_timer;
+  int segment_index;    /*Reference to an SMPI process' data segment. Default value is -1 if not in SMPI context*/
 } s_smx_process_t;
 
 
@@ -108,6 +109,9 @@ XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_synchro_t synchro);
 XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart);
 XBT_PRIVATE smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer);
 
+void SIMIX_segment_index_set(smx_process_t, int);
+extern void (*SMPI_switch_data_segment)(int);
+
 SG_END_DECL()
 
 #endif
index eb7a5ae..6f65720 100644 (file)
@@ -169,8 +169,9 @@ XBT_PRIVATE int smpi_mpi_dims_create(int nnodes, int ndims, int dims[]);
 
 XBT_PRIVATE smpi_process_data_t smpi_process_data(void);
 XBT_PRIVATE smpi_process_data_t smpi_process_remote_data(int index);
-XBT_PRIVATE void smpi_process_set_user_data(void *);
-XBT_PRIVATE void* smpi_process_get_user_data(void);
+// smpi_process_[set/get]_user_data must be public
+/* XBT_PRIVATE void smpi_process_set_user_data(void *); */
+/* XBT_PRIVATE void* smpi_process_get_user_data(void); */
 XBT_PRIVATE int smpi_process_count(void);
 XBT_PRIVATE MPI_Comm smpi_process_comm_world(void);
 XBT_PRIVATE MPI_Comm smpi_process_get_comm_intra(void);
index 76bc438..5193693 100644 (file)
@@ -622,7 +622,7 @@ void smpi_really_switch_data_segment(int dest) {
 #ifdef HAVE_PRIVATIZATION
   int i;
   if(smpi_loaded_page==-1){//initial switch, do the copy from the real page here
-    for (i=0; i< SIMIX_process_count(); i++){
+    for (i=0; i< smpi_process_count(); i++){
       memcpy(smpi_privatisation_regions[i].address,
         TOPAGE(smpi_start_data_exe), smpi_size_data_exe);
     }
@@ -665,7 +665,7 @@ void smpi_initialize_global_memory_segments(){
   smpi_privatisation_regions = (smpi_privatisation_region_t) malloc(
     smpi_process_count() * sizeof(struct s_smpi_privatisation_region));
 
-  for (i=0; i< SIMIX_process_count(); i++){
+  for (i=0; i< smpi_process_count(); i++){
       //create SIMIX_process_count() mappings of this size with the same data inside
       void *address = NULL;
       char path[] = "/dev/shm/my-buffer-XXXXXX";
index 4001323..295ddfb 100644 (file)
@@ -13,6 +13,7 @@
 #include "src/simix/smx_private.h"
 #include "simgrid/sg_config.h"
 #include "src/mc/mc_replay.h"
+#include "src/msg/msg_private.h"
 
 #include <float.h>              /* DBL_MAX */
 #include <stdint.h>
@@ -82,11 +83,18 @@ void smpi_process_init(int *argc, char ***argv)
     SIMIX_process_set_cleanup_function(proc, SIMIX_process_cleanup);
     char* instance_id = (*argv)[1];
     int rank = atoi((*argv)[2]);
-    index = smpi_process_index_of_smx_process(proc);
+    /* Now using segment index of the process */
+    index = proc->segment_index;
 
     if(!index_to_process_data){
       index_to_process_data=(int*)xbt_malloc(SIMIX_process_count()*sizeof(int));
     }
+
+    if(smpi_privatize_global_variables){
+      /* Done at the process's creation */
+      SMPI_switch_data_segment(index);
+    }
+
     MPI_Comm* temp_comm_world;
     xbt_bar_t temp_bar;
     smpi_deployment_register_process(instance_id, rank, index, &temp_comm_world ,&temp_bar);
@@ -96,8 +104,11 @@ void smpi_process_init(int *argc, char ***argv)
     data->index = index;
     data->instance_id = instance_id;
     data->replaying = 0;
-    xbt_free(simcall_process_get_data(proc));
-    simcall_process_set_data(proc, data);
+    //xbt_free(simcall_process_get_data(proc));
+
+  simdata_process_t simdata = simcall_process_get_data(proc);
+  simdata->data = data;
+
     if (*argc > 3) {
       free((*argv)[1]);
       memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2));
@@ -111,10 +122,6 @@ void smpi_process_init(int *argc, char ***argv)
     simcall_rdv_set_receiver(data->mailbox_small, proc);
     XBT_DEBUG("<%d> New process in the game: %p", index, proc);
 
-    if(smpi_privatize_global_variables){
-      smpi_switch_data_segment(index);
-    }
-
   }
   if (smpi_process_data() == NULL)
     xbt_die("smpi_process_data() returned NULL. You probably gave a NULL parameter to MPI_Init. Although it's required by MPI-2, this is currently not supported by SMPI.");
@@ -162,9 +169,14 @@ int smpi_process_finalized()
  */
 int smpi_process_initialized(void)
 {
-  int index = smpi_process_index();
-  return ( (index != MPI_UNDEFINED)
-          && (process_data[index_to_process_data[index]]->state == SMPI_INITIALIZED));
+  if (!index_to_process_data){
+    return false;
+  }
+  else{
+    int index = smpi_process_index();
+    return ( (index != MPI_UNDEFINED)
+             && (process_data[index_to_process_data[index]]->state == SMPI_INITIALIZED));
+  }
 }
 
 /**
@@ -205,7 +217,8 @@ int smpi_global_size(void)
 
 smpi_process_data_t smpi_process_data(void)
 {
-  return SIMIX_process_self_get_data(SIMIX_process_self());
+  simdata_process_t simdata = SIMIX_process_self_get_data(SIMIX_process_self());
+  return simdata->data;
 }
 
 smpi_process_data_t smpi_process_remote_data(int index)
@@ -355,7 +368,7 @@ void smpi_comm_copy_buffer_callback(smx_synchro_t comm,
       && ((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)SIMIX_process_get_data(comm->comm.src_proc))->index);
+       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->comm.src_proc))->data))->index);
        tmpbuff = (void*)xbt_malloc(buff_size);
        memcpy(tmpbuff, buff, buff_size);
   }
@@ -366,7 +379,7 @@ void smpi_comm_copy_buffer_callback(smx_synchro_t comm,
       && ((char*)comm->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)SIMIX_process_get_data(comm->comm.dst_proc))->index);
+       smpi_switch_data_segment(((smpi_process_data_t)(((simdata_process_t)SIMIX_process_get_data(comm->comm.dst_proc))->data))->index);
   }
 
 
@@ -647,6 +660,9 @@ int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[])
   TRACE_add_end_function(TRACE_smpi_release);
 
   SIMIX_global_init(&argc, argv);
+  MSG_init(&argc,argv);
+
+  SMPI_switch_data_segment = smpi_switch_data_segment;
 
   smpi_init_options();
 
index fae3690..0583cfb 100644 (file)
@@ -25,16 +25,21 @@ void TRACE_smpi_set_category(const char *category)
 
 int PMPI_Init(int *argc, char ***argv)
 {
-  smpi_process_init(argc, argv);
-  smpi_process_mark_as_initialized();
-  int rank = smpi_process_index();
-  TRACE_smpi_init(rank);
-  TRACE_smpi_computing_init(rank);
-  instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
-  extra->type = TRACING_INIT;
-  TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
-  TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
-  smpi_bench_begin();
+  // PMPI_Init is call only one time by only by SMPI process
+  int already_init;
+  MPI_Initialized(&already_init);
+  if(!(already_init)){
+    smpi_process_init(argc, argv);
+    smpi_process_mark_as_initialized();
+    int rank = smpi_process_index();
+    TRACE_smpi_init(rank);
+    TRACE_smpi_computing_init(rank);
+    instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
+    extra->type = TRACING_INIT;
+    TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
+    TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
+    smpi_bench_begin();
+  }
   return MPI_SUCCESS;
 }