Skip to content

Commit ecb9c0d

Browse files
committed
dash::copy: Pass local_chunks by the caller
This way one can call copy_impl multiple times, before triggering local copies.
1 parent 79b8ea0 commit ecb9c0d

File tree

1 file changed

+30
-23
lines changed
  • dash/include/dash/algorithm

1 file changed

+30
-23
lines changed

dash/include/dash/algorithm/Copy.h

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ template <
135135
typename ValueType,
136136
class GlobInputIt >
137137
ValueType * copy_impl(
138-
GlobInputIt begin,
139-
GlobInputIt end,
140-
ValueType * out_first,
141-
std::vector<dart_handle_t> * handles)
138+
GlobInputIt begin,
139+
GlobInputIt end,
140+
ValueType * out_first,
141+
std::vector<dart_handle_t> * handles,
142+
local_copy_chunks<ValueType> & local_chunks)
142143
{
143144
DASH_LOG_TRACE("dash::internal::copy_impl() global -> local",
144145
"in_first:", begin.pos(),
@@ -159,8 +160,6 @@ ValueType * copy_impl(
159160

160161
ContiguousRangeSet<GlobInputIt> range_set{begin, end};
161162

162-
local_copy_chunks<ValueType> local_chunks;
163-
164163
//
165164
// Copy elements from every unit:
166165
//
@@ -204,8 +203,6 @@ ValueType * copy_impl(
204203
num_elem_copied += num_copy_elem;
205204
}
206205

207-
do_local_copies(local_chunks);
208-
209206
DASH_ASSERT_EQ(num_elem_copied, num_elem_total,
210207
"Failed to find all contiguous subranges in range");
211208

@@ -226,10 +223,11 @@ template <
226223
typename ValueType,
227224
class GlobOutputIt >
228225
GlobOutputIt copy_impl(
229-
ValueType * begin,
230-
ValueType * end,
231-
GlobOutputIt out_first,
232-
std::vector<dart_handle_t> * handles)
226+
ValueType * begin,
227+
ValueType * end,
228+
GlobOutputIt out_first,
229+
std::vector<dart_handle_t> * handles,
230+
local_copy_chunks<ValueType> & local_chunks)
233231
{
234232

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

255253
ContiguousRangeSet<GlobOutputIt> range_set{out_first, out_last};
256254

257-
local_copy_chunks<value_type> local_chunks;
258-
259255
auto in_first = begin;
260256

261257
//
@@ -300,8 +296,6 @@ GlobOutputIt copy_impl(
300296
num_elem_copied += num_copy_elem;
301297
}
302298

303-
do_local_copies(local_chunks);
304-
305299
DASH_ASSERT_EQ(num_elem_copied, num_elem_total,
306300
"Failed to find all contiguous subranges in range");
307301

@@ -338,9 +332,10 @@ dash::Future<ValueType *> copy_async(
338332
}
339333

340334
auto handles = std::make_shared<std::vector<dart_handle_t>>();
341-
342-
auto out_last = dash::internal::copy_impl(in_first, in_last,
343-
out_first, handles.get());
335+
dash::internal::local_copy_chunks<ValueType> local_chunks;
336+
auto out_last = dash::internal::copy_impl(in_first, in_last, out_first,
337+
handles.get(), local_chunks);
338+
dash::internal::do_local_copies(local_chunks);
344339

345340
if (handles->empty()) {
346341
DASH_LOG_TRACE("dash::copy_async", "all transfers completed");
@@ -422,12 +417,15 @@ ValueType * copy(
422417
return out_first;
423418
}
424419

420+
dash::internal::local_copy_chunks<ValueType> local_chunks;
425421
#if DASH_COPY_USE_HANDLES
426422
std::vector<dart_handle_t> handles;
427423
auto out_last = dash::internal::copy_impl(in_first,
428424
in_last,
429425
out_first,
430-
&handles);
426+
&handles,
427+
local_chunks);
428+
dash::internal::do_local_copies(local_chunks);
431429
if (!handles.empty()) {
432430
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
433431
"num_handles: ", handles.size());
@@ -438,7 +436,9 @@ ValueType * copy(
438436
auto out_last = dash::internal::copy_impl(in_first,
439437
in_last,
440438
out_first,
441-
nullptr);
439+
nullptr,
440+
local_chunks);
441+
dash::internal::do_local_copies(local_chunks);
442442
dart_flush_local(in_first.dart_gptr());
443443
#endif // DASH_COPY_USE_HANDLES
444444

@@ -471,10 +471,13 @@ dash::Future<GlobOutputIt> copy_async(
471471
}
472472

473473
auto handles = std::make_shared<std::vector<dart_handle_t>>();
474+
dash::internal::local_copy_chunks<ValueType> local_chunks;
474475
auto out_last = dash::internal::copy_impl(in_first,
475476
in_last,
476477
out_first,
477-
handles.get());
478+
handles.get(),
479+
local_chunks);
480+
dash::internal::do_local_copies(local_chunks);
478481

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

550+
dash::internal::local_copy_chunks<ValueType> local_chunks;
547551
#if DASH_COPY_USE_HANDLES
548552
std::vector<dart_handle_t> handles;
549553
auto out_last = dash::internal::copy_impl(in_first,
550554
in_last,
551555
out_first,
552-
&handles);
556+
&handles,
557+
local_chunks);
558+
dash::internal::do_local_copies(local_chunks);
553559

554560
if (!handles.empty()) {
555561
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
@@ -562,6 +568,7 @@ GlobOutputIt copy(
562568
in_last,
563569
out_first,
564570
nullptr);
571+
dash::internal::do_local_copies(local_chunks);
565572
dart_flush(out_first.dart_gptr());
566573
#endif
567574
return out_last;

0 commit comments

Comments
 (0)