Skip to content

Commit 91c36c9

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 cd90860 commit 91c36c9

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");
@@ -439,24 +438,29 @@ ValueType * copy(
439438
}
440439

441440
ValueType *out_last;
441+
dash::internal::local_copy_chunks<typename GlobInputIt::value_type, ValueType> local_chunks;
442442
if (UseHandles) {
443443
std::vector<dart_handle_t> handles;
444444
out_last = dash::internal::copy_impl(in_first,
445445
in_last,
446446
out_first,
447-
&handles);
447+
&handles,
448+
local_chunks);
448449
if (!handles.empty()) {
449450
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
450451
"num_handles: ", handles.size());
451452
dart_waitall_local(handles.data(), handles.size());
452453
}
454+
dash::internal::do_local_copies(local_chunks);
453455

454456
} else {
455457
out_last = dash::internal::copy_impl(in_first,
456458
in_last,
457459
out_first,
458-
nullptr);
460+
nullptr,
461+
local_chunks);
459462
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete");
463+
dash::internal::do_local_copies(local_chunks);
460464
dart_flush_local_all(in_first.dart_gptr());
461465
}
462466

@@ -489,10 +493,13 @@ dash::Future<GlobOutputIt> copy_async(
489493
}
490494

491495
auto handles = std::make_shared<std::vector<dart_handle_t>>();
496+
dash::internal::local_copy_chunks<ValueType, typename GlobOutputIt::value_type> local_chunks;
492497
auto out_last = dash::internal::copy_impl(in_first,
493498
in_last,
494499
out_first,
495-
handles.get());
500+
handles.get(),
501+
local_chunks);
502+
dash::internal::do_local_copies(local_chunks);
496503

497504
if (handles->empty()) {
498505
return dash::Future<GlobOutputIt>(out_last);
@@ -561,12 +568,15 @@ GlobOutputIt copy(
561568
DASH_LOG_TRACE("dash::copy()", "blocking, local to global");
562569
// handles to wait on at the end
563570
GlobOutputIt out_last;
571+
dash::internal::local_copy_chunks<ValueType, typename GlobOutputIt::value_type> local_chunks;
564572
if (UseHandles) {
565573
std::vector<dart_handle_t> handles;
566574
out_last = dash::internal::copy_impl(in_first,
567575
in_last,
568576
out_first,
569-
&handles);
577+
&handles,
578+
local_chunks);
579+
dash::internal::do_local_copies(local_chunks);
570580

571581
if (!handles.empty()) {
572582
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete,",
@@ -577,8 +587,10 @@ GlobOutputIt copy(
577587
out_last = dash::internal::copy_impl(in_first,
578588
in_last,
579589
out_first,
580-
nullptr);
590+
nullptr,
591+
local_chunks);
581592
DASH_LOG_TRACE("dash::copy", "Waiting for remote transfers to complete");
593+
dash::internal::do_local_copies(local_chunks);
582594
dart_flush_all(out_first.dart_gptr());
583595
}
584596
return out_last;

0 commit comments

Comments
 (0)