Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix MC builds
[simgrid.git] / src / smpi / smpi_memory.cpp
index 9296d97..0c56653 100644 (file)
@@ -1,11 +1,11 @@
-/* Copyright (c) 2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2015-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <cstdint>
 #include <climits>
+#include <cstring>
 
 #include <vector>
 
 #include <sys/types.h>
 #include <string.h>
 #include <stdio.h>
-#include "simgrid/sg_config.h"
 #include <fcntl.h>
+#include <sys/stat.h>
+#include <errno.h>
 
 #ifndef WIN32
 #include <sys/mman.h>
 #include <unistd.h>
 
-#include "../xbt/memory_map.hpp"
+#include "src/xbt/memory_map.hpp"
 
-#include "private.h"
 #include "private.hpp"
+#include "src/smpi/private.h"
+#include "src/smpi/private.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_memory, smpi, "Memory layout support for SMPI");
 
 int smpi_loaded_page = -1;
 char* smpi_start_data_exe = nullptr;
 int smpi_size_data_exe = 0;
-bool smpi_privatize_global_variables;
+int smpi_privatize_global_variables;
 
 static const int PROT_RWX = (PROT_READ | PROT_WRITE | PROT_EXEC);
 static const int PROT_RW  = (PROT_READ | PROT_WRITE );
@@ -90,22 +92,22 @@ void smpi_really_switch_data_segment(int dest)
 #if HAVE_PRIVATIZATION
   if(smpi_loaded_page==-1){//initial switch, do the copy from the real page here
     for (int i=0; i< smpi_process_count(); i++){
-      memcpy(smpi_privatisation_regions[i].address, TOPAGE(smpi_start_data_exe), smpi_size_data_exe);
+      memcpy(smpi_privatization_regions[i].address, TOPAGE(smpi_start_data_exe), smpi_size_data_exe);
     }
   }
 
   // FIXME, cross-process support (mmap across process when necessary)
-  int current = smpi_privatisation_regions[dest].file_descriptor;
+  int current = smpi_privatization_regions[dest].file_descriptor;
   XBT_DEBUG("Switching data frame to the one of process %d", dest);
   void* tmp =
       mmap(TOPAGE(smpi_start_data_exe), smpi_size_data_exe, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, current, 0);
   if (tmp != TOPAGE(smpi_start_data_exe))
-    xbt_die("Couldn't map the new region");
+    xbt_die("Couldn't map the new region (errno %d): %s", errno, strerror(errno));
   smpi_loaded_page = dest;
 #endif
 }
 
-int smpi_is_privatisation_file(char* file)
+int smpi_is_privatization_file(char* file)
 {
   return strncmp("/dev/shm/my-buffer-", file, std::strlen("/dev/shm/my-buffer-")) == 0;
 }
@@ -113,12 +115,7 @@ int smpi_is_privatisation_file(char* file)
 void smpi_initialize_global_memory_segments()
 {
 
-#if !HAVE_PRIVATIZATION
-  smpi_privatize_global_variables=false;
-  xbt_die("You are trying to use privatization on a system that does not support it. Don't.");
-  return;
-#else
-
+#if HAVE_PRIVATIZATION
   smpi_get_executable_global_size();
 
   XBT_DEBUG ("bss+data segment found : size %d starting at %p", smpi_size_data_exe, smpi_start_data_exe );
@@ -128,8 +125,8 @@ void smpi_initialize_global_memory_segments()
     return;
   }
 
-  smpi_privatisation_regions = static_cast<smpi_privatisation_region_t>(
-      xbt_malloc(smpi_process_count() * sizeof(struct s_smpi_privatisation_region)));
+  smpi_privatization_regions = static_cast<smpi_privatization_region_t>(
+      xbt_malloc(smpi_process_count() * sizeof(struct s_smpi_privatization_region)));
 
   for (int i=0; i< smpi_process_count(); i++){
     // create SIMIX_process_count() mappings of this size with the same data inside
@@ -178,9 +175,13 @@ Ask the Internet about tutorials on how to increase the files limit such as: htt
     memcpy(address, TOPAGE(smpi_start_data_exe), smpi_size_data_exe);
 
     // store the address of the mapping for further switches
-    smpi_privatisation_regions[i].file_descriptor = file_descriptor;
-    smpi_privatisation_regions[i].address         = address;
+    smpi_privatization_regions[i].file_descriptor = file_descriptor;
+    smpi_privatization_regions[i].address         = address;
   }
+#else /* ! HAVE_PRIVATIZATION */
+  smpi_privatize_global_variables = false;
+  xbt_die("You are trying to use privatization on a system that does not support it. Don't.");
+  return;
 #endif
 }
 
@@ -189,11 +190,11 @@ void smpi_destroy_global_memory_segments(){
     return;
 #if HAVE_PRIVATIZATION
   for (int i=0; i< smpi_process_count(); i++) {
-    if (munmap(smpi_privatisation_regions[i].address, smpi_size_data_exe) < 0)
-      XBT_WARN("Unmapping of fd %d failed: %s", smpi_privatisation_regions[i].file_descriptor, strerror(errno));
-    close(smpi_privatisation_regions[i].file_descriptor);
+    if (munmap(smpi_privatization_regions[i].address, smpi_size_data_exe) < 0)
+      XBT_WARN("Unmapping of fd %d failed: %s", smpi_privatization_regions[i].file_descriptor, strerror(errno));
+    close(smpi_privatization_regions[i].file_descriptor);
   }
-  xbt_free(smpi_privatisation_regions);
+  xbt_free(smpi_privatization_regions);
 #endif
 }