Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[smpi] Change parallel arrays into array of structs
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 5 Sep 2014 09:48:31 +0000 (11:48 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 5 Sep 2014 10:30:06 +0000 (12:30 +0200)
src/mc/mc_checkpoint.c
src/smpi/private.h
src/smpi/smpi_bench.c

index cc4d219..2449821 100644 (file)
@@ -193,7 +193,7 @@ static void MC_get_memory_regions(mc_snapshot_t snapshot)
       mc_mem_region_t ref_reg =
         mc_model_checker->parent_snapshot ? mc_model_checker->parent_snapshot->privatization_regions[i] : NULL;
       snapshot->privatization_regions[i] =
       mc_mem_region_t ref_reg =
         mc_model_checker->parent_snapshot ? mc_model_checker->parent_snapshot->privatization_regions[i] : NULL;
       snapshot->privatization_regions[i] =
-        MC_region_new(-1, mc_binary_info->start_rw, mappings[i], size_data_exe, ref_reg);
+        MC_region_new(-1, mc_binary_info->start_rw, smpi_privatisation_regions[i].address, size_data_exe, ref_reg);
     }
     snapshot->privatization_index = smpi_loaded_page;
     snapshot->regions[2] = NULL;
     }
     snapshot->privatization_index = smpi_loaded_page;
     snapshot->regions[2] = NULL;
index 6010a59..ac6811a 100644 (file)
@@ -690,7 +690,14 @@ void TRACE_smpi_finalize(int rank);
 const char* encode_datatype(MPI_Datatype datatype);
 
 // TODO, make this static and expose it more cleanly
 const char* encode_datatype(MPI_Datatype datatype);
 
 // TODO, make this static and expose it more cleanly
-extern void** mappings;
+
+typedef struct s_smpi_privatisation_region {
+  void* address;
+  int file_descriptor;
+} *smpi_privatisation_region_t;
+
+extern smpi_privatisation_region_t smpi_privatisation_regions;
+
 extern int smpi_loaded_page;
 
 int SIMIX_process_get_PID(smx_process_t self);
 extern int smpi_loaded_page;
 
 int SIMIX_process_get_PID(smx_process_t self);
index 0a74d87..d35c50c 100644 (file)
@@ -73,13 +73,13 @@ xbt_dict_t calls = NULL;           /* Allocated on first use */
 double smpi_cpu_threshold;
 double smpi_running_power;
 
 double smpi_cpu_threshold;
 double smpi_running_power;
 
-static int* fds;
-void** mappings;
 int smpi_loaded_page = -1;
 char* start_data_exe = NULL;
 int size_data_exe = 0;
 int smpi_privatize_global_variables;
 
 int smpi_loaded_page = -1;
 char* start_data_exe = NULL;
 int size_data_exe = 0;
 int smpi_privatize_global_variables;
 
+smpi_privatisation_region_t smpi_privatisation_regions;
+
 typedef struct {
   int fd;
   int count;
 typedef struct {
   int fd;
   int count;
@@ -614,10 +614,10 @@ void smpi_switch_data_segment(int dest){
   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++){
   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++){
-      memcpy(mappings[i],TOPAGE(start_data_exe),size_data_exe);
+      memcpy(smpi_privatisation_regions[i].address,TOPAGE(start_data_exe),size_data_exe);
     }
   }
     }
   }
-  int current= fds[dest];
+  int current = smpi_privatisation_regions[dest].file_descriptor;
   XBT_VERB("Switching data frame to the one of process %d", dest);
   void* tmp = mmap (TOPAGE(start_data_exe), size_data_exe, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, current, 0);
   if (tmp != TOPAGE(start_data_exe))
   XBT_VERB("Switching data frame to the one of process %d", dest);
   void* tmp = mmap (TOPAGE(start_data_exe), size_data_exe, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, current, 0);
   if (tmp != TOPAGE(start_data_exe))
@@ -717,18 +717,19 @@ void smpi_initialize_global_memory_segments(){
     return;
   }
 
     return;
   }
 
-  fds= (int*)xbt_malloc((smpi_process_count())*sizeof(int));
-  mappings= (void**)xbt_malloc((smpi_process_count())*sizeof(void*));
-
+  smpi_privatisation_regions = (smpi_privatisation_region_t) malloc(
+    sizeof(struct s_smpi_privatisation_region) * sizeof(int));
 
   for (i=0; i< SIMIX_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";
       int status;
 
   for (i=0; i< SIMIX_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";
       int status;
+
       int file_descriptor= mkstemp (path);
       if (file_descriptor < 0)
         xbt_die("Impossible to create temporary file for memory mapping");
       int file_descriptor= mkstemp (path);
       if (file_descriptor < 0)
         xbt_die("Impossible to create temporary file for memory mapping");
+
       status = unlink (path);
       if (status)
         xbt_die("Impossible to unlink temporary file for memory mapping");
       status = unlink (path);
       if (status)
         xbt_die("Impossible to unlink temporary file for memory mapping");
@@ -739,7 +740,6 @@ void smpi_initialize_global_memory_segments(){
 
       /* Ask for a free region */
       address = mmap (NULL, size_data_exe, PROT_READ | PROT_WRITE, MAP_SHARED, file_descriptor, 0);
 
       /* Ask for a free region */
       address = mmap (NULL, size_data_exe, PROT_READ | PROT_WRITE, MAP_SHARED, file_descriptor, 0);
-
       if (address == MAP_FAILED)
         xbt_die("Couldn't find a free region for memory mapping");
 
       if (address == MAP_FAILED)
         xbt_die("Couldn't find a free region for memory mapping");
 
@@ -747,8 +747,8 @@ void smpi_initialize_global_memory_segments(){
       memcpy(address,TOPAGE(start_data_exe),size_data_exe);
 
       //store the address of the mapping for further switches
       memcpy(address,TOPAGE(start_data_exe),size_data_exe);
 
       //store the address of the mapping for further switches
-      fds[i]=file_descriptor;
-      mappings[i]= address;
+      smpi_privatisation_regions[i].file_descriptor = file_descriptor;
+      smpi_privatisation_regions[i].address = address;
   }
 
 #endif
   }
 
 #endif
@@ -761,14 +761,13 @@ void smpi_destroy_global_memory_segments(){
 #ifdef HAVE_MMAP
   int i;
   for (i=0; i< smpi_process_count(); i++){
 #ifdef HAVE_MMAP
   int i;
   for (i=0; i< smpi_process_count(); i++){
-    if(munmap(mappings[i],size_data_exe) < 0) {
-      XBT_WARN("Unmapping of fd %d failed: %s", fds[i], strerror(errno));
+    if(munmap(smpi_privatisation_regions[i].address,size_data_exe) < 0) {
+      XBT_WARN("Unmapping of fd %d failed: %s",
+        smpi_privatisation_regions[i].file_descriptor, strerror(errno));
     }
     }
-    close(fds[i]);
+    close(smpi_privatisation_regions[i].file_descriptor);
   }
   }
-  xbt_free(mappings);
-  xbt_free(fds);
-
+  xbt_free(smpi_privatisation_regions);
 #endif
 
 }
 #endif
 
 }