Skip to content

Commit

Permalink
dash::copy: Pass local_chunks by the caller
Browse files Browse the repository at this point in the history
This way one can call copy_impl multiple times, before triggering local
copies.
  • Loading branch information
bertwesarg committed Jul 16, 2019
1 parent 79b8ea0 commit ecb9c0d
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions dash/include/dash/algorithm/Copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ template <
typename ValueType,
class GlobInputIt >
ValueType * copy_impl(
GlobInputIt begin,
GlobInputIt end,
ValueType * out_first,
std::vector<dart_handle_t> * handles)
GlobInputIt begin,
GlobInputIt end,
ValueType * out_first,
std::vector<dart_handle_t> * handles,
local_copy_chunks<ValueType> & local_chunks)
{
DASH_LOG_TRACE("dash::internal::copy_impl() global -> local",
"in_first:", begin.pos(),
Expand All @@ -159,8 +160,6 @@ ValueType * copy_impl(

ContiguousRangeSet<GlobInputIt> range_set{begin, end};

local_copy_chunks<ValueType> local_chunks;

//
// Copy elements from every unit:
//
Expand Down Expand Up @@ -204,8 +203,6 @@ ValueType * copy_impl(
num_elem_copied += num_copy_elem;
}

do_local_copies(local_chunks);

DASH_ASSERT_EQ(num_elem_copied, num_elem_total,
"Failed to find all contiguous subranges in range");

Expand All @@ -226,10 +223,11 @@ template <
typename ValueType,
class GlobOutputIt >
GlobOutputIt copy_impl(
ValueType * begin,
ValueType * end,
GlobOutputIt out_first,
std::vector<dart_handle_t> * handles)
ValueType * begin,
ValueType * end,
GlobOutputIt out_first,
std::vector<dart_handle_t> * handles,
local_copy_chunks<ValueType> & local_chunks)
{

DASH_LOG_TRACE("dash::copy_impl() local -> global",
Expand All @@ -254,8 +252,6 @@ GlobOutputIt copy_impl(

ContiguousRangeSet<GlobOutputIt> range_set{out_first, out_last};

local_copy_chunks<value_type> local_chunks;

auto in_first = begin;

//
Expand Down Expand Up @@ -300,8 +296,6 @@ GlobOutputIt copy_impl(
num_elem_copied += num_copy_elem;
}

do_local_copies(local_chunks);

DASH_ASSERT_EQ(num_elem_copied, num_elem_total,
"Failed to find all contiguous subranges in range");

Expand Down Expand Up @@ -338,9 +332,10 @@ dash::Future<ValueType *> copy_async(
}

auto handles = std::make_shared<std::vector<dart_handle_t>>();

auto out_last = dash::internal::copy_impl(in_first, in_last,
out_first, handles.get());
dash::internal::local_copy_chunks<ValueType> local_chunks;
auto out_last = dash::internal::copy_impl(in_first, in_last, out_first,
handles.get(), local_chunks);
dash::internal::do_local_copies(local_chunks);

if (handles->empty()) {
DASH_LOG_TRACE("dash::copy_async", "all transfers completed");
Expand Down Expand Up @@ -422,12 +417,15 @@ ValueType * copy(
return out_first;
}

dash::internal::local_copy_chunks<ValueType> local_chunks;
#if DASH_COPY_USE_HANDLES
std::vector<dart_handle_t> handles;
auto out_last = dash::internal::copy_impl(in_first,
in_last,
out_first,
&handles);
&handles,
local_chunks);
dash::internal::do_local_copies(local_chunks);
if (!handles.empty()) {
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
"num_handles: ", handles.size());
Expand All @@ -438,7 +436,9 @@ ValueType * copy(
auto out_last = dash::internal::copy_impl(in_first,
in_last,
out_first,
nullptr);
nullptr,
local_chunks);
dash::internal::do_local_copies(local_chunks);
dart_flush_local(in_first.dart_gptr());
#endif // DASH_COPY_USE_HANDLES

Expand Down Expand Up @@ -471,10 +471,13 @@ dash::Future<GlobOutputIt> copy_async(
}

auto handles = std::make_shared<std::vector<dart_handle_t>>();
dash::internal::local_copy_chunks<ValueType> local_chunks;
auto out_last = dash::internal::copy_impl(in_first,
in_last,
out_first,
handles.get());
handles.get(),
local_chunks);
dash::internal::do_local_copies(local_chunks);

if (handles->empty()) {
return dash::Future<GlobOutputIt>(out_last);
Expand Down Expand Up @@ -544,12 +547,15 @@ GlobOutputIt copy(
DASH_LOG_TRACE("dash::copy()", "blocking, local to global");
// handles to wait on at the end

dash::internal::local_copy_chunks<ValueType> local_chunks;
#if DASH_COPY_USE_HANDLES
std::vector<dart_handle_t> handles;
auto out_last = dash::internal::copy_impl(in_first,
in_last,
out_first,
&handles);
&handles,
local_chunks);
dash::internal::do_local_copies(local_chunks);

if (!handles.empty()) {
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
Expand All @@ -562,6 +568,7 @@ GlobOutputIt copy(
in_last,
out_first,
nullptr);
dash::internal::do_local_copies(local_chunks);
dart_flush(out_first.dart_gptr());
#endif
return out_last;
Expand Down

0 comments on commit ecb9c0d

Please sign in to comment.