@@ -429,26 +429,25 @@ qvi_hwsplit_s::split(void)
429
429
return rc;
430
430
}
431
431
432
- qvi_scope_split_coll_s::qvi_scope_split_coll_s (
433
- qv_scope_t *parent_a ,
434
- uint_t split_size_a ,
435
- int mycolor_a ,
436
- qv_hw_obj_type_t split_at_type_a
437
- ) : parent(parent_a )
438
- , mycolor(mycolor_a )
432
+ qvi_coll_hwsplit_s::qvi_coll_hwsplit_s (
433
+ qv_scope_t *parent ,
434
+ uint_t npieces ,
435
+ int color ,
436
+ qv_hw_obj_type_t split_at_type
437
+ ) : m_parent(parent )
438
+ , m_color(color )
439
439
{
440
- const qvi_group_t *const pgroup = parent ->group ;
441
- if (pgroup->rank () == qvi_scope_split_coll_s ::s_rootid) {
442
- hwsplit = qvi_hwsplit_s (
443
- parent , pgroup->size (), split_size_a, split_at_type_a
440
+ const qvi_group_t *const pgroup = m_parent ->group ;
441
+ if (pgroup->rank () == qvi_coll_hwsplit_s ::s_rootid) {
442
+ m_hwsplit = qvi_hwsplit_s (
443
+ m_parent , pgroup->size (), npieces, split_at_type
444
444
);
445
445
}
446
446
}
447
447
448
448
template <typename TYPE>
449
449
int
450
- qvi_scope_split_coll_s::scatter_values (
451
- int root,
450
+ qvi_coll_hwsplit_s::scatter_values (
452
451
const std::vector<TYPE> &values,
453
452
TYPE *value
454
453
) {
@@ -457,9 +456,9 @@ qvi_scope_split_coll_s::scatter_values(
457
456
int rc = QV_SUCCESS;
458
457
qvi_bbuff_t *rxbuff = nullptr ;
459
458
460
- qvi_group_t *const group = parent ->group ;
459
+ qvi_group_t *const group = m_parent ->group ;
461
460
std::vector<qvi_bbuff_t *> txbuffs (0 );
462
- if (root == group->rank ()) {
461
+ if (group->rank () == s_rootid ) {
463
462
const uint_t group_size = group->size ();
464
463
txbuffs.resize (group_size);
465
464
// Pack the values.
@@ -473,7 +472,7 @@ qvi_scope_split_coll_s::scatter_values(
473
472
if (qvi_unlikely (rc != QV_SUCCESS)) goto out;
474
473
}
475
474
476
- rc = group->scatter (txbuffs.data (), root , &rxbuff);
475
+ rc = group->scatter (txbuffs.data (), s_rootid , &rxbuff);
477
476
if (qvi_unlikely (rc != QV_SUCCESS)) goto out;
478
477
479
478
*value = *(TYPE *)rxbuff->data ();
@@ -491,30 +490,28 @@ qvi_scope_split_coll_s::scatter_values(
491
490
492
491
template <typename TYPE>
493
492
int
494
- qvi_scope_split_coll_s::bcast_value (
495
- int root,
493
+ qvi_coll_hwsplit_s::bcast_value (
496
494
TYPE *value
497
495
) {
498
496
static_assert (std::is_trivially_copyable<TYPE>::value, " " );
499
- qvi_group_t *const group = parent ->group ;
497
+ qvi_group_t *const group = m_parent ->group ;
500
498
501
499
std::vector<TYPE> values;
502
- if (root == group->rank ()) {
500
+ if (group->rank () == s_rootid ) {
503
501
values.resize (group->size ());
504
502
std::fill (values.begin (), values.end (), *value);
505
503
}
506
- return scatter_values (root, values, value);
504
+ return scatter_values (values, value);
507
505
}
508
506
509
507
template <typename TYPE>
510
508
int
511
- qvi_scope_split_coll_s::gather_values (
512
- int root,
509
+ qvi_coll_hwsplit_s::gather_values (
513
510
TYPE invalue,
514
511
std::vector<TYPE> &outvals
515
512
) {
516
513
static_assert (std::is_trivially_copyable<TYPE>::value, " " );
517
- qvi_group_t *const group = parent ->group ;
514
+ qvi_group_t *const group = m_parent ->group ;
518
515
const uint_t group_size = group->size ();
519
516
520
517
qvi_bbuff_t *txbuff = nullptr ;
@@ -529,18 +526,18 @@ qvi_scope_split_coll_s::gather_values(
529
526
// Gather the values to the root.
530
527
bool shared = false ;
531
528
qvi_bbuff_t **bbuffs = nullptr ;
532
- rc = group->gather (txbuff, root , &shared, &bbuffs);
529
+ rc = group->gather (txbuff, s_rootid , &shared, &bbuffs);
533
530
if (qvi_unlikely (rc != QV_SUCCESS)) goto out;
534
531
// The root fills in the output.
535
- if (group->rank () == root ) {
532
+ if (group->rank () == s_rootid ) {
536
533
outvals.resize (group_size);
537
534
// Unpack the values.
538
535
for (uint_t i = 0 ; i < group_size; ++i) {
539
536
outvals[i] = *(TYPE *)bbuffs[i]->data ();
540
537
}
541
538
}
542
539
out:
543
- if (!shared || (shared && (group->rank () == root ))) {
540
+ if (!shared || (shared && (group->rank () == s_rootid ))) {
544
541
if (bbuffs) {
545
542
for (uint_t i = 0 ; i < group_size; ++i) {
546
543
qvi_bbuff_delete (&bbuffs[i]);
@@ -557,12 +554,11 @@ qvi_scope_split_coll_s::gather_values(
557
554
}
558
555
559
556
int
560
- qvi_scope_split_coll_s::gather_hwpools (
561
- int root,
557
+ qvi_coll_hwsplit_s::gather_hwpools (
562
558
qvi_hwpool_s *txpool,
563
559
std::vector<qvi_hwpool_s *> &rxpools
564
560
) {
565
- qvi_group_t *const group = parent ->group ;
561
+ qvi_group_t *const group = m_parent ->group ;
566
562
const uint_t group_size = group->size ();
567
563
// Pack the hardware pool into a buffer.
568
564
qvi_bbuff_t txbuff;
@@ -571,10 +567,10 @@ qvi_scope_split_coll_s::gather_hwpools(
571
567
// Gather the values to the root.
572
568
bool shared = false ;
573
569
qvi_bbuff_t **bbuffs = nullptr ;
574
- rc = group->gather (&txbuff, root , &shared, &bbuffs);
570
+ rc = group->gather (&txbuff, s_rootid , &shared, &bbuffs);
575
571
if (rc != QV_SUCCESS) goto out;
576
572
577
- if (group->rank () == root ) {
573
+ if (group->rank () == s_rootid ) {
578
574
rxpools.resize (group_size);
579
575
// Unpack the hwpools.
580
576
for (uint_t i = 0 ; i < group_size; ++i) {
@@ -585,7 +581,7 @@ qvi_scope_split_coll_s::gather_hwpools(
585
581
}
586
582
}
587
583
out:
588
- if (!shared || (shared && (group->rank () == root ))) {
584
+ if (!shared || (shared && (group->rank () == s_rootid ))) {
589
585
if (bbuffs) {
590
586
for (uint_t i = 0 ; i < group_size; ++i) {
591
587
qvi_bbuff_delete (&bbuffs[i]);
@@ -601,33 +597,27 @@ qvi_scope_split_coll_s::gather_hwpools(
601
597
}
602
598
603
599
int
604
- qvi_scope_split_coll_s ::gather (void )
600
+ qvi_coll_hwsplit_s ::gather (void )
605
601
{
606
- int rc = gather_values (
607
- s_rootid, qvi_task_t::mytid (), hwsplit.m_taskids
608
- );
602
+ int rc = gather_values (qvi_task_t::mytid (), m_hwsplit.m_taskids );
609
603
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
610
604
// Note that the result hwpools are copies, so we can modify them freely.
611
- rc = gather_hwpools (
612
- s_rootid, parent->hwpool , hwsplit.m_hwpools
613
- );
605
+ rc = gather_hwpools (m_parent->hwpool , m_hwsplit.m_hwpools );
614
606
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
615
607
616
- rc = gather_values (
617
- s_rootid, mycolor, hwsplit.m_colors
618
- );
608
+ rc = gather_values (m_color, m_hwsplit.m_colors );
619
609
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
620
610
621
- const int myid = parent ->group ->rank ();
622
- const uint_t group_size = parent ->group ->size ();
623
- if (myid == qvi_scope_split_coll_s ::s_rootid) {
624
- hwsplit .m_affinities .resize (group_size);
611
+ const int myid = m_parent ->group ->rank ();
612
+ const uint_t group_size = m_parent ->group ->size ();
613
+ if (myid == qvi_coll_hwsplit_s ::s_rootid) {
614
+ m_hwsplit .m_affinities .resize (group_size);
625
615
for (uint_t tid = 0 ; tid < group_size; ++tid) {
626
616
hwloc_cpuset_t cpuset = nullptr ;
627
- rc = parent ->group ->task ()->bind_top (&cpuset);
617
+ rc = m_parent ->group ->task ()->bind_top (&cpuset);
628
618
if (qvi_unlikely (rc != QV_SUCCESS)) break ;
629
619
//
630
- rc = hwsplit .m_affinities [tid].set (cpuset);
620
+ rc = m_hwsplit .m_affinities [tid].set (cpuset);
631
621
// Clean up.
632
622
qvi_hwloc_bitmap_delete (&cpuset);
633
623
if (qvi_unlikely (rc != QV_SUCCESS)) break ;
@@ -637,18 +627,17 @@ qvi_scope_split_coll_s::gather(void)
637
627
}
638
628
639
629
int
640
- qvi_scope_split_coll_s::scatter_hwpools (
641
- int root,
630
+ qvi_coll_hwsplit_s::scatter_hwpools (
642
631
const std::vector<qvi_hwpool_s *> &pools,
643
632
qvi_hwpool_s **pool
644
633
) {
645
634
int rc = QV_SUCCESS;
646
635
std::vector<qvi_bbuff_t *> txbuffs (0 );
647
636
qvi_bbuff_t *rxbuff = nullptr ;
648
637
649
- qvi_group_t *const group = parent ->group ;
638
+ qvi_group_t *const group = m_parent ->group ;
650
639
651
- if (root == group->rank ()) {
640
+ if (group->rank () == s_rootid ) {
652
641
const uint_t group_size = group->size ();
653
642
txbuffs.resize (group_size);
654
643
// Pack the hwpools.
@@ -662,7 +651,7 @@ qvi_scope_split_coll_s::scatter_hwpools(
662
651
if (rc != QV_SUCCESS) goto out;
663
652
}
664
653
665
- rc = group->scatter (txbuffs.data (), root , &rxbuff);
654
+ rc = group->scatter (txbuffs.data (), s_rootid , &rxbuff);
666
655
if (rc != QV_SUCCESS) goto out;
667
656
668
657
rc = qvi_bbuff_rmi_unpack (rxbuff->data (), pool);
@@ -678,28 +667,26 @@ qvi_scope_split_coll_s::scatter_hwpools(
678
667
}
679
668
680
669
int
681
- qvi_scope_split_coll_s ::scatter (
670
+ qvi_coll_hwsplit_s ::scatter (
682
671
int *colorp,
683
672
qvi_hwpool_s **result
684
673
) {
685
- const int rc = scatter_values (s_rootid, hwsplit .m_colors , colorp);
674
+ const int rc = scatter_values (m_hwsplit .m_colors , colorp);
686
675
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
687
- return scatter_hwpools (s_rootid, hwsplit .m_hwpools , result);
676
+ return scatter_hwpools (m_hwsplit .m_hwpools , result);
688
677
}
689
678
690
679
int
691
- qvi_scope_split_coll_s ::barrier (void )
680
+ qvi_coll_hwsplit_s ::barrier (void )
692
681
{
693
- return parent ->group ->barrier ();
682
+ return m_parent ->group ->barrier ();
694
683
}
695
684
696
685
int
697
- qvi_scope_split_coll_s ::split (
686
+ qvi_coll_hwsplit_s ::split (
698
687
int *colorp,
699
688
qvi_hwpool_s **result
700
689
) {
701
- int rc2 = QV_SUCCESS;
702
- const int myid = parent->group ->rank ();
703
690
// First consolidate the provided information, as this is coming from a
704
691
// SPMD-like context (e.g., splitting a resource shared by MPI processes).
705
692
// In most cases it is easiest to have a single task calculate the split
@@ -708,28 +695,23 @@ qvi_scope_split_coll_s::split(
708
695
// whose id is equal to qvi_global_split_t::rootid after gather has
709
696
// completed.
710
697
int rc = gather ();
711
- if (rc != QV_SUCCESS) goto out ;
698
+ if (qvi_unlikely ( rc != QV_SUCCESS)) return rc ;
712
699
// The root does this calculation.
713
- if (myid == s_rootid) {
714
- rc2 = hwsplit.split ();
700
+ int rc2 = QV_SUCCESS;
701
+ if (m_parent->group ->rank () == s_rootid) {
702
+ rc2 = m_hwsplit.split ();
715
703
}
716
704
// Wait for the split information. Explicitly barrier here in case the
717
705
// underlying broadcast implementation polls heavily for completion.
718
706
rc = barrier ();
719
- if (rc != QV_SUCCESS) goto out ;
707
+ if (qvi_unlikely ( rc != QV_SUCCESS)) return rc ;
720
708
// To avoid hangs in split error paths, share the split rc with everyone.
721
- rc = bcast_value (s_rootid, &rc2);
722
- if (rc != QV_SUCCESS) goto out;
723
- // If the split failed, return the error to all callers.
724
- if (rc2 != QV_SUCCESS) {
725
- rc = rc2;
726
- goto out;
727
- }
709
+ rc = bcast_value (&rc2);
710
+ if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
711
+ // If the split failed, return the error to all participants.
712
+ if (qvi_unlikely (rc2 != QV_SUCCESS)) return rc2;
728
713
// Scatter the results.
729
- rc = scatter (colorp, result);
730
- if (rc != QV_SUCCESS) goto out;
731
- out:
732
- return rc;
714
+ return scatter (colorp, result);
733
715
}
734
716
735
717
/*
0 commit comments