Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some more fixes for the communication optimization.
authorTom Cornebize <tom.cornebize@ensimag.grenoble-inp.fr>
Fri, 7 Apr 2017 13:42:15 +0000 (15:42 +0200)
committerTom Cornebize <tom.cornebize@ensimag.grenoble-inp.fr>
Fri, 7 Apr 2017 13:42:15 +0000 (15:42 +0200)
include/smpi/smpi_shared_malloc.hpp
src/smpi/smpi_global.cpp
src/smpi/smpi_shared.cpp
teshsuite/smpi/macro-partial-shared-communication/macro-partial-shared-communication.c
teshsuite/smpi/macro-partial-shared-communication/macro-partial-shared-communication.tesh

index 629d3f4..0f9f745 100644 (file)
@@ -12,7 +12,7 @@
 
 XBT_PUBLIC(int) smpi_is_shared(void* ptr, std::vector<std::pair<int, int>> &private_blocks, int *offset);
 
-std::vector<std::pair<int, int>> shift_private_blocks(const std::vector<std::pair<int, int>> vec, int offset);
+std::vector<std::pair<int, int>> shift_and_frame_private_blocks(const std::vector<std::pair<int, int>> vec, int offset, int buff_size);
 std::vector<std::pair<int, int>> merge_private_blocks(std::vector<std::pair<int, int>> src, std::vector<std::pair<int, int>> dst);
 
 #endif
index 1ad2a30..e2af2da 100644 (file)
@@ -117,17 +117,23 @@ void memcpy_private(void *dest, const void *src, size_t n, std::vector<std::pair
   }
 }
 
+void check_blocks(std::vector<std::pair<int, int>> &private_blocks, size_t buff_size) {
+  for(auto block : private_blocks) {
+    xbt_assert(block.first >= 0 && block.second <= buff_size, "Oops, bug in shared malloc.");
+  }
+}
+
 void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t buff_size)
 {
   simgrid::kernel::activity::Comm *comm = dynamic_cast<simgrid::kernel::activity::Comm*>(synchro);
   int src_shared=0, dst_shared=0;
-  int src_offset, dst_offset;
+  int src_offset=0, dst_offset=0;
   std::vector<std::pair<int, int>> src_private_blocks;
   std::vector<std::pair<int, int>> dst_private_blocks;
   XBT_DEBUG("Copy the data over");
   if(src_shared=smpi_is_shared(buff, src_private_blocks, &src_offset)) {
     XBT_DEBUG("Sender %p is shared. Let's ignore it.", buff);
-    src_private_blocks = shift_private_blocks(src_private_blocks, src_offset);
+    src_private_blocks = shift_and_frame_private_blocks(src_private_blocks, src_offset, buff_size);
   }
   else {
     src_private_blocks.clear();
@@ -135,13 +141,29 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b
   }
   if(dst_shared=smpi_is_shared((char*)comm->dst_buff, dst_private_blocks, &dst_offset)) {
     XBT_DEBUG("Receiver %p is shared. Let's ignore it.", (char*)comm->dst_buff);
-    dst_private_blocks = shift_private_blocks(dst_private_blocks, dst_offset);
+    dst_private_blocks = shift_and_frame_private_blocks(dst_private_blocks, dst_offset, buff_size);
   }
   else {
     dst_private_blocks.clear();
     dst_private_blocks.push_back(std::make_pair(0, buff_size));
   }
+/*
+  fprintf(stderr, "size: 0x%x\n", buff_size);
+  fprintf(stderr, "src: ");
+  print(src_private_blocks);
+  fprintf(stderr, "src_offset = 0x%x\n", src_offset);
+  fprintf(stderr, "dst: ");
+  print(dst_private_blocks);
+  fprintf(stderr, "dst_offset = 0x%x\n", dst_offset);
+*/
+  check_blocks(src_private_blocks, buff_size);
+  check_blocks(dst_private_blocks, buff_size);
   auto private_blocks = merge_private_blocks(src_private_blocks, dst_private_blocks);
+/*
+  fprintf(stderr, "Private blocks: ");
+  print(private_blocks);
+*/
+  check_blocks(private_blocks, buff_size);
   void* tmpbuff=buff;
   if((smpi_privatize_global_variables) && (static_cast<char*>(buff) >= smpi_start_data_exe)
       && (static_cast<char*>(buff) < smpi_start_data_exe + smpi_size_data_exe )
index e629da9..e4f5491 100644 (file)
@@ -364,14 +364,15 @@ int smpi_is_shared(void* ptr, std::vector<std::pair<int, int>> &private_blocks,
   }
 }
 
-std::vector<std::pair<int, int>> shift_private_blocks(const std::vector<std::pair<int, int>> vec, int offset) {
-  std::vector<std::pair<int, int>> result;
-  for(auto block: vec) {
-    auto new_block = std::make_pair(std::max(0, block.first-offset), std::max(0, block.second-offset));
-    if(new_block.second > 0)
-      result.push_back(new_block);
-  }
-  return result;
+std::vector<std::pair<int, int>> shift_and_frame_private_blocks(const std::vector<std::pair<int, int>> vec, int offset, int buff_size) {
+    std::vector<std::pair<int, int>> result;
+    for(auto block: vec) {
+        auto new_block = std::make_pair(std::min(std::max(0, block.first-offset), buff_size),
+                                        std::min(std::max(0, block.second-offset), buff_size));
+        if(new_block.second > 0 && new_block.first < buff_size)
+            result.push_back(new_block);
+    }
+    return result;
 }
 
 void append_or_merge_block(std::vector<std::pair<int, int>> &vec, std::pair<int, int> &block) {
index 2a93238..69841a8 100644 (file)
@@ -99,12 +99,12 @@ int main(int argc, char *argv[])
   MPI_Barrier(MPI_COMM_WORLD);
 
   // Then, even processes send a sub-part of their buffer their successor
-  // Note that the part (0, 0x10000) which is not sent is a shared part, so we do not care
+  // Note that the last block should not be copied entirely
   if(rank%2 == 0) {
-    MPI_Send(buf+0x10000, mem_size-0x10000, MPI_UINT8_T, rank+1, 0, MPI_COMM_WORLD);
+    MPI_Send(buf+0x10000, mem_size-0xa000000, MPI_UINT8_T, rank+1, 0, MPI_COMM_WORLD);
   }
   else {
-    MPI_Recv(buf+0x10000, mem_size-0x10000, MPI_UINT8_T, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+    MPI_Recv(buf+0x10000, mem_size-0xa000000, MPI_UINT8_T, rank-1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
   }
 
 
index 2cf32cf..661eff7 100644 (file)
@@ -17,9 +17,9 @@ $ ${bindir:=.}/../../../bin/smpirun -hostfile ../hostfile -platform ../../../exa
 > [3] The result of the (shifted) communication check for block (0x1300010, 0x3456789) is: 1
 > [3] The result of the (shifted) communication check for block (0x3457890, 0x4444444) is: 1
 > [3] The result of the (shifted) communication check for block (0x5555555, 0x5555565) is: 1
-> [3] The result of the (shifted) communication check for block (0x5600000, 0x8000000) is: 1
+> [3] The result of the (shifted) communication check for block (0x5600000, 0x8000000) is: 0
 > [1] The result of the (shifted) communication check for block (0x1234567, 0x1300000) is: 1
 > [1] The result of the (shifted) communication check for block (0x1300010, 0x3456789) is: 1
 > [1] The result of the (shifted) communication check for block (0x3457890, 0x4444444) is: 1
 > [1] The result of the (shifted) communication check for block (0x5555555, 0x5555565) is: 1
-> [1] The result of the (shifted) communication check for block (0x5600000, 0x8000000) is: 1
+> [1] The result of the (shifted) communication check for block (0x5600000, 0x8000000) is: 0