Skip to content

Commit f2439c1

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 7babf03 commit f2439c1

File tree

1 file changed

+36
-24
lines changed
  • dash/include/dash/algorithm

1 file changed

+36
-24
lines changed

dash/include/dash/algorithm/Copy.h

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,13 @@ template <
141141
typename ValueType,
142142
typename GlobInputIt >
143143
ValueType * copy_impl(
144-
GlobInputIt begin,
145-
GlobInputIt end,
146-
ValueType * out_first,
147-
std::vector<dart_handle_t> * handles)
144+
GlobInputIt begin,
145+
GlobInputIt end,
146+
ValueType * out_first,
147+
std::vector<dart_handle_t> * handles,
148+
local_copy_chunks<
149+
typename GlobInputIt::value_type,
150+
ValueType> & local_chunks)
148151
{
149152
DASH_LOG_TRACE("dash::internal::copy_impl() global -> local",
150153
"in_first:", begin.pos(),
@@ -171,8 +174,6 @@ ValueType * copy_impl(
171174

172175
ContiguousRangeSet<GlobInputIt> range_set{begin, end};
173176

174-
local_copy_chunks<input_value_type, output_value_type> local_chunks;
175-
176177
//
177178
// Copy elements from every unit:
178179
//
@@ -216,8 +217,6 @@ ValueType * copy_impl(
216217
num_elem_copied += num_copy_elem;
217218
}
218219

219-
do_local_copies(local_chunks);
220-
221220
DASH_ASSERT_EQ(num_elem_copied, num_elem_total,
222221
"Failed to find all contiguous subranges in range");
223222

@@ -238,10 +237,13 @@ template <
238237
typename ValueType,
239238
typename GlobOutputIt >
240239
GlobOutputIt copy_impl(
241-
ValueType * begin,
242-
ValueType * end,
243-
GlobOutputIt out_first,
244-
std::vector<dart_handle_t> * handles)
240+
ValueType * begin,
241+
ValueType * end,
242+
GlobOutputIt out_first,
243+
std::vector<dart_handle_t> * handles,
244+
local_copy_chunks<
245+
ValueType,
246+
typename GlobOutputIt::value_type> & local_chunks)
245247
{
246248
DASH_LOG_TRACE("dash::copy_impl() local -> global",
247249
"in_first:", begin,
@@ -271,8 +273,6 @@ GlobOutputIt copy_impl(
271273

272274
ContiguousRangeSet<GlobOutputIt> range_set{out_first, out_last};
273275

274-
local_copy_chunks<input_value_type, output_value_type> local_chunks;
275-
276276
auto in_first = begin;
277277

278278
//
@@ -317,8 +317,6 @@ GlobOutputIt copy_impl(
317317
num_elem_copied += num_copy_elem;
318318
}
319319

320-
do_local_copies(local_chunks);
321-
322320
DASH_ASSERT_EQ(num_elem_copied, num_elem_total,
323321
"Failed to find all contiguous subranges in range");
324322

@@ -355,9 +353,10 @@ dash::Future<ValueType *> copy_async(
355353
}
356354

357355
auto handles = std::make_shared<std::vector<dart_handle_t>>();
358-
359-
auto out_last = dash::internal::copy_impl(in_first, in_last,
360-
out_first, handles.get());
356+
dash::internal::local_copy_chunks<typename GlobInputIt::value_type, ValueType> local_chunks;
357+
auto out_last = dash::internal::copy_impl(in_first, in_last, out_first,
358+
handles.get(), local_chunks);
359+
dash::internal::do_local_copies(local_chunks);
361360

362361
if (handles->empty()) {
363362
DASH_LOG_TRACE("dash::copy_async", "all transfers completed");
@@ -441,24 +440,29 @@ ValueType * copy(
441440
}
442441

443442
ValueType *out_last;
443+
dash::internal::local_copy_chunks<typename GlobInputIt::value_type, ValueType> local_chunks;
444444
if (UseHandles) {
445445
std::vector<dart_handle_t> handles;
446446
out_last = dash::internal::copy_impl(in_first,
447447
in_last,
448448
out_first,
449-
&handles);
449+
&handles,
450+
local_chunks);
450451
if (!handles.empty()) {
451452
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
452453
"num_handles: ", handles.size());
453454
dart_waitall_local(handles.data(), handles.size());
454455
}
456+
dash::internal::do_local_copies(local_chunks);
455457

456458
} else {
457459
out_last = dash::internal::copy_impl(in_first,
458460
in_last,
459461
out_first,
460-
nullptr);
462+
nullptr,
463+
local_chunks);
461464
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete");
465+
dash::internal::do_local_copies(local_chunks);
462466
dart_flush_local_all(in_first.dart_gptr());
463467
}
464468

@@ -491,10 +495,13 @@ dash::Future<GlobOutputIt> copy_async(
491495
}
492496

493497
auto handles = std::make_shared<std::vector<dart_handle_t>>();
498+
dash::internal::local_copy_chunks<ValueType, typename GlobOutputIt::value_type> local_chunks;
494499
auto out_last = dash::internal::copy_impl(in_first,
495500
in_last,
496501
out_first,
497-
handles.get());
502+
handles.get(),
503+
local_chunks);
504+
dash::internal::do_local_copies(local_chunks);
498505

499506
if (handles->empty()) {
500507
return dash::Future<GlobOutputIt>(out_last);
@@ -565,12 +572,15 @@ GlobOutputIt copy(
565572
DASH_LOG_TRACE("dash::copy()", "blocking, local to global");
566573
// handles to wait on at the end
567574
GlobOutputIt out_last;
575+
dash::internal::local_copy_chunks<ValueType, typename GlobOutputIt::value_type> local_chunks;
568576
if (UseHandles) {
569577
std::vector<dart_handle_t> handles;
570578
out_last = dash::internal::copy_impl(in_first,
571579
in_last,
572580
out_first,
573-
&handles);
581+
&handles,
582+
local_chunks);
583+
dash::internal::do_local_copies(local_chunks);
574584

575585
if (!handles.empty()) {
576586
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
@@ -581,8 +591,10 @@ GlobOutputIt copy(
581591
out_last = dash::internal::copy_impl(in_first,
582592
in_last,
583593
out_first,
584-
nullptr);
594+
nullptr,
595+
local_chunks);
585596
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete");
597+
dash::internal::do_local_copies(local_chunks);
586598
dart_flush_all(out_first.dart_gptr());
587599
}
588600
return out_last;

0 commit comments

Comments
 (0)