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
}
}
+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();
}
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 )
}
}
-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) {
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);
}
> [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