Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
modified [PATCH] Privatize data segment for SMPI process and share for MSG process
authorLuka Stanisic <luka.stanisic@imag.fr>
Thu, 3 Dec 2015 13:20:03 +0000 (14:20 +0100)
committerLuka Stanisic <luka.stanisic@imag.fr>
Thu, 3 Dec 2015 13:20:03 +0000 (14:20 +0100)
src/simix/smx_global.c
src/simix/smx_process.c
src/simix/smx_process_private.h
src/smpi/smpi_bench.c
src/smpi/smpi_global.c

index d3337a3..7c87387 100644 (file)
@@ -40,6 +40,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix,
 smx_global_t simix_global = NULL;
 static xbt_heap_t simix_timers = NULL;
 
+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 bc1a052..dd75293 100644 (file)
 #include "mc/mc_replay.h"
 #include "mc/mc_client.h"
 
+#ifdef HAVE_SMPI
+#include "smpi/private.h"
+#endif
+
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
                                 "Logging specific to SIMIX (process)");
 
@@ -255,9 +259,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;
      }
@@ -869,6 +884,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 */
@@ -1009,3 +1027,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 82a4190..cc86284 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);
     }
@@ -741,7 +741,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 263b191..580b02c 100644 (file)
@@ -82,11 +82,18 @@ void smpi_process_init(int *argc, char ***argv)
     proc->context->cleanup_func=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);
@@ -111,10 +118,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.");
@@ -647,6 +650,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();