From d9487a95cf3b33b9cce3a15de6f3f712f894f8f8 Mon Sep 17 00:00:00 2001 From: Tom Cornebize Date: Fri, 7 Apr 2017 16:33:02 +0200 Subject: [PATCH 1/1] Take the intersection of the private blocks instead of the union. --- src/smpi/smpi_shared.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/smpi/smpi_shared.cpp b/src/smpi/smpi_shared.cpp index e4f5491209..aa61be5490 100644 --- a/src/smpi/smpi_shared.cpp +++ b/src/smpi/smpi_shared.cpp @@ -375,35 +375,26 @@ std::vector> shift_and_frame_private_blocks(const std::vecto return result; } -void append_or_merge_block(std::vector> &vec, std::pair &block) { - if(vec.size() > 0 && block.first <= vec.back().second) { // overlapping with the last block inserted - vec.back().second = std::max(vec.back().second, block.second); - } - else { // not overlapping, we insert a new block - vec.push_back(block); - } -} - std::vector> merge_private_blocks(std::vector> src, std::vector> dst) { std::vector> result; unsigned i_src=0, i_dst=0; while(i_src < src.size() && i_dst < dst.size()) { std::pair block; - if(src[i_src].first < dst[i_dst].first) { - block = src[i_src]; - i_src ++; + if(src[i_src].second <= dst[i_dst].first) { + i_src++; } - else { - block = dst[i_dst]; - i_dst ++; + else if(dst[i_dst].second <= src[i_src].first) { + i_dst++; + } + else { // src.second > dst.first && dst.second > src.first → the blocks are overlapping + block = std::make_pair(std::max(src[i_src].first, dst[i_dst].first), + std::min(src[i_src].second, dst[i_dst].second)); + result.push_back(block); + if(src[i_src].second < dst[i_dst].second) + i_src ++; + else + i_dst ++; } - append_or_merge_block(result, block); - } - for(; i_src < src.size(); i_src++) { - append_or_merge_block(result, src[i_src]); - } - for(; i_dst < dst.size(); i_dst++) { - append_or_merge_block(result, dst[i_dst]); } return result; } -- 2.20.1