@@ -24,19 +24,11 @@ TEST_CASE("test_communicate_split_one", "[message]")
2424 REQUIRE (c2->size () == c->size ());
2525 REQUIRE (c2->rank () == c->rank ());
2626
27- if (c->rank () == 0 )
28- {
29- REQUIRE (c2->isGroupLeader () == true );
30- auto GroupLeaderComm = c2->getGroupLeaderComm ();
31- REQUIRE (GroupLeaderComm != nullptr );
32- REQUIRE (GroupLeaderComm->size () == 1 );
33- REQUIRE (GroupLeaderComm->rank () == 0 );
34- }
35- else
36- {
37- REQUIRE (c2->isGroupLeader () == false );
38- REQUIRE (c2->getGroupLeaderComm () == nullptr );
39- }
27+ REQUIRE (c2->isGroupLeader () == (c->rank () == 0 ));
28+
29+ auto & inter_group_comm = c2->getInterGroupComm ();
30+ REQUIRE (inter_group_comm.size () == 1 );
31+ REQUIRE (inter_group_comm.rank () == 0 );
4032
4133 std::string real_name = c->getName ();
4234
@@ -66,37 +58,23 @@ TEST_CASE("test_communicate_split_two", "[message]")
6658 int new_group_id = c->rank () < midpoint ? 0 : 1 ;
6759 int new_rank = c->rank ();
6860 if (c->rank () >= midpoint)
69- {
7061 new_rank -= midpoint;
71- }
62+
7263 // Adjust for odd size - the last group has the extra process
7364 if (c->size () % 2 == 1 )
74- {
7565 new_size[1 ] = new_size[1 ] + 1 ;
76- }
66+
7767 REQUIRE (c2->size () == new_size[new_group_id]);
7868 REQUIRE (c2->rank () == new_rank);
7969
80- if (c->rank () == 0 || c->rank () == midpoint)
81- {
82- REQUIRE (c2->isGroupLeader () == true );
83- auto GroupLeaderComm = c2->getGroupLeaderComm ();
84- REQUIRE (GroupLeaderComm != nullptr );
85- REQUIRE (GroupLeaderComm->size () == 2 );
86- if (c->rank () == 0 )
87- {
88- REQUIRE (GroupLeaderComm->rank () == 0 );
89- }
90- else
91- {
92- REQUIRE (GroupLeaderComm->rank () == 1 );
93- }
94- }
70+ REQUIRE (c2->isGroupLeader () == (c->rank () == 0 || c->rank () == midpoint));
71+
72+ auto & inter_group_comm = c2->getInterGroupComm ();
73+ REQUIRE (inter_group_comm.size () == (c->rank () < midpoint * 2 ? 2 : 1 ));
74+ if (c->rank () < midpoint * 2 )
75+ REQUIRE (inter_group_comm.rank () == new_group_id);
9576 else
96- {
97- REQUIRE (c2->isGroupLeader () == false );
98- REQUIRE (c2->getGroupLeaderComm () == nullptr );
99- }
77+ REQUIRE (inter_group_comm.rank () == 0 );
10078 }
10179}
10280
@@ -108,24 +86,14 @@ TEST_CASE("test_communicate_split_four", "[message]")
10886 {
10987 auto c2 = std::make_unique<Communicate>(*c, 4 );
11088
111- REQUIRE (c2-> size () == c->size () / 4 ) ;
112- int group_size = c->size () / 4 ;
113- int new_rank = c-> rank () % group_size;
89+ const int group_size = c->size () / 4 ;
90+ const int new_rank = c->rank () % group_size ;
91+ REQUIRE (c2-> size () == group_size) ;
11492 REQUIRE (c2->rank () == new_rank);
115-
116- if (new_rank == 0 )
117- {
118- REQUIRE (c2->isGroupLeader () == true );
119- auto GroupLeaderComm = c2->getGroupLeaderComm ();
120- REQUIRE (GroupLeaderComm != nullptr );
121- REQUIRE (GroupLeaderComm->size () == 4 );
122- REQUIRE (GroupLeaderComm->rank () == c->rank () / group_size);
123- }
124- else
125- {
126- REQUIRE (c2->isGroupLeader () == false );
127- REQUIRE (c2->getGroupLeaderComm () == nullptr );
128- }
93+ REQUIRE (c2->isGroupLeader () == (new_rank == 0 ));
94+ auto & inter_group_comm = c2->getInterGroupComm ();
95+ REQUIRE (inter_group_comm.size () == 4 );
96+ REQUIRE (inter_group_comm.rank () == c->rank () / group_size);
12997 }
13098}
13199
0 commit comments