QMCPACK
test_communciate.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2018 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 #include "Message/Communicate.h"
15 
16 namespace qmcplusplus
17 {
18 TEST_CASE("test_communicate_split_one", "[message]")
19 {
21 
22  auto c2 = std::make_unique<Communicate>(*c, 1);
23 
24  REQUIRE(c2->size() == c->size());
25  REQUIRE(c2->rank() == c->rank());
26 
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  }
40 
41  std::string real_name = c->getName();
42 
43  std::string name = "myname";
44  c->setName(name);
45  REQUIRE(c->getName() == name);
46 
47  std::string other_name = "myothername";
48  c->setName(other_name.data(), other_name.size());
49  REQUIRE(c->getName() == other_name);
50 
51  c->setName(real_name);
52 }
53 
54 TEST_CASE("test_communicate_split_two", "[message]")
55 {
57  if (c->size() >= 2)
58  {
59  auto c2 = std::make_unique<Communicate>(*c, 2);
60 
61  std::vector<int> new_size(2);
62  new_size[0] = c->size() / 2;
63  new_size[1] = c->size() / 2;
64 
65  int midpoint = c->size() / 2;
66  int new_group_id = c->rank() < midpoint ? 0 : 1;
67  int new_rank = c->rank();
68  if (c->rank() >= midpoint)
69  {
70  new_rank -= midpoint;
71  }
72  // Adjust for odd size - the last group has the extra process
73  if (c->size() % 2 == 1)
74  {
75  new_size[1] = new_size[1] + 1;
76  }
77  REQUIRE(c2->size() == new_size[new_group_id]);
78  REQUIRE(c2->rank() == new_rank);
79 
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  }
95  else
96  {
97  REQUIRE(c2->isGroupLeader() == false);
98  REQUIRE(c2->getGroupLeaderComm() == nullptr);
99  }
100  }
101 }
102 
103 TEST_CASE("test_communicate_split_four", "[message]")
104 {
106  // For simplicity, only test the case where the number of processes is divisible by 4.
107  if (c->size() % 4 == 0)
108  {
109  auto c2 = std::make_unique<Communicate>(*c, 4);
110 
111  REQUIRE(c2->size() == c->size() / 4);
112  int group_size = c->size() / 4;
113  int new_rank = c->rank() % group_size;
114  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  }
129  }
130 }
131 
132 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
int size() const
return the number of tasks
Definition: Communicate.h:118
Wrapping information on parallelism.
Definition: Communicate.h:68
REQUIRE(std::filesystem::exists(filename))