libMesh
Public Member Functions | List of all members
ParallelPointTest Class Reference
Inheritance diagram for ParallelPointTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (ParallelPointTest)
 
 CPPUNIT_TEST (testAllGatherPoint)
 
 CPPUNIT_TEST (testAllGatherPairPointPoint)
 
 CPPUNIT_TEST (testAllGatherPairRealPoint)
 
 CPPUNIT_TEST (testBroadcastVectorValueInt)
 
 CPPUNIT_TEST (testBroadcastVectorValueReal)
 
 CPPUNIT_TEST (testBroadcastPoint)
 
 CPPUNIT_TEST (testIsendRecv)
 
 CPPUNIT_TEST (testIrecvSend)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testAllGatherPoint ()
 
void testAllGatherPairPointPoint ()
 
void testAllGatherPairRealPoint ()
 
template<typename T >
void testBroadcastVectorValue ()
 
void testBroadcastVectorValueInt ()
 
void testBroadcastVectorValueReal ()
 
void testBroadcastPoint ()
 
void testIsendRecv ()
 
void testIrecvSend ()
 

Detailed Description

Definition at line 10 of file parallel_point_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/8]

ParallelPointTest::CPPUNIT_TEST ( testAllGatherPairPointPoint  )

◆ CPPUNIT_TEST() [2/8]

ParallelPointTest::CPPUNIT_TEST ( testAllGatherPairRealPoint  )

◆ CPPUNIT_TEST() [3/8]

ParallelPointTest::CPPUNIT_TEST ( testAllGatherPoint  )

◆ CPPUNIT_TEST() [4/8]

ParallelPointTest::CPPUNIT_TEST ( testBroadcastPoint  )

◆ CPPUNIT_TEST() [5/8]

ParallelPointTest::CPPUNIT_TEST ( testBroadcastVectorValueInt  )

◆ CPPUNIT_TEST() [6/8]

ParallelPointTest::CPPUNIT_TEST ( testBroadcastVectorValueReal  )

◆ CPPUNIT_TEST() [7/8]

ParallelPointTest::CPPUNIT_TEST ( testIrecvSend  )

◆ CPPUNIT_TEST() [8/8]

ParallelPointTest::CPPUNIT_TEST ( testIsendRecv  )

◆ CPPUNIT_TEST_SUITE()

ParallelPointTest::CPPUNIT_TEST_SUITE ( ParallelPointTest  )

◆ CPPUNIT_TEST_SUITE_END()

ParallelPointTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void ParallelPointTest::setUp ( )
inline

Definition at line 31 of file parallel_point_test.C.

32  {}

◆ tearDown()

void ParallelPointTest::tearDown ( )
inline

Definition at line 34 of file parallel_point_test.C.

35  {}

◆ testAllGatherPairPointPoint()

void ParallelPointTest::testAllGatherPairPointPoint ( )
inline

Definition at line 59 of file parallel_point_test.C.

60  {
61  std::vector<std::pair<Point, Point>> vals;
62  Real myrank = TestCommWorld->rank();
63  TestCommWorld->allgather
64  (std::make_pair(Point(myrank, myrank+0.125, myrank+0.25), Point(myrank+0.5, myrank+0.625, myrank+0.75)), vals);
65 
66  const std::size_t comm_size = TestCommWorld->size();
67  const std::size_t vec_size = vals.size();
68  CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
69 
70  for (processor_id_type i=0; i<vals.size(); i++)
71  {
72  Real theirrank = i;
73  CPPUNIT_ASSERT_EQUAL( theirrank, vals[i].first(0) );
74  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.125), vals[i].first(1) );
75  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i].first(2) );
76  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i].second(0) );
77  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.625), vals[i].second(1) );
78  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.75), vals[i].second(2) );
79  }
80  }

References libMesh::Real, and TestCommWorld.

◆ testAllGatherPairRealPoint()

void ParallelPointTest::testAllGatherPairRealPoint ( )
inline

Definition at line 83 of file parallel_point_test.C.

84  {
85  std::vector<std::pair<Real, Point>> vals;
86  Real myrank = TestCommWorld->rank();
87  TestCommWorld->allgather
88  (std::make_pair(Real(myrank+0.75), Point(myrank, myrank+0.25, myrank+0.5)), vals);
89 
90  const std::size_t comm_size = TestCommWorld->size();
91  const std::size_t vec_size = vals.size();
92  CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
93 
94  for (processor_id_type i=0; i<vals.size(); i++)
95  {
96  Real theirrank = i;
97  CPPUNIT_ASSERT_EQUAL( theirrank, vals[i].second(0) );
98  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i].second(1) );
99  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i].second(2) );
100  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.75), vals[i].first );
101  }
102  }

References libMesh::Real, and TestCommWorld.

◆ testAllGatherPoint()

void ParallelPointTest::testAllGatherPoint ( )
inline

Definition at line 39 of file parallel_point_test.C.

40  {
41  std::vector<Point> vals;
42  Real myrank = TestCommWorld->rank();
43  TestCommWorld->allgather(Point(myrank, myrank+0.25, myrank+0.5),vals);
44 
45  const std::size_t comm_size = TestCommWorld->size();
46  const std::size_t vec_size = vals.size();
47  CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
48  for (processor_id_type i=0; i<vals.size(); i++)
49  {
50  Real theirrank = i;
51  CPPUNIT_ASSERT_EQUAL( theirrank, vals[i](0) );
52  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i](1) );
53  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i](2) );
54  }
55  }

References libMesh::Real, and TestCommWorld.

◆ testBroadcastPoint()

void ParallelPointTest::testBroadcastPoint ( )
inline

Definition at line 144 of file parallel_point_test.C.

145  {
146  std::vector<Point> src(3), dest(3);
147 
148  {
149  Real val=0.;
150  for (unsigned int i=0; i<3; i++)
151  for (unsigned int j=0; j<LIBMESH_DIM; j++)
152  src[i](j) = val++;
153 
154  if (TestCommWorld->rank() == 0)
155  dest = src;
156  }
157 
158  TestCommWorld->broadcast(dest);
159 
160  for (unsigned int i=0; i<3; i++)
161  for (unsigned int j=0; j<LIBMESH_DIM; j++)
162  CPPUNIT_ASSERT_EQUAL (src[i](j), dest[i](j) );
163  }

References libMesh::Real, and TestCommWorld.

◆ testBroadcastVectorValue()

template<typename T >
void ParallelPointTest::testBroadcastVectorValue ( )
inline

Definition at line 107 of file parallel_point_test.C.

108  {
109  std::vector<VectorValue<T>> src(3), dest(3);
110 
111  {
112  T val=T(0);
113  for (unsigned int i=0; i<3; i++)
114  for (unsigned int j=0; j<LIBMESH_DIM; j++)
115  src[i](j) = val++;
116 
117  if (TestCommWorld->rank() == 0)
118  dest = src;
119  }
120 
121  TestCommWorld->broadcast(dest);
122 
123  for (unsigned int i=0; i<3; i++)
124  for (unsigned int j=0; j<LIBMESH_DIM; j++)
125  CPPUNIT_ASSERT_EQUAL (src[i](j), dest[i](j) );
126  }

References TestCommWorld.

◆ testBroadcastVectorValueInt()

void ParallelPointTest::testBroadcastVectorValueInt ( )
inline

Definition at line 130 of file parallel_point_test.C.

131  {
132  this->testBroadcastVectorValue<int>();
133  }

◆ testBroadcastVectorValueReal()

void ParallelPointTest::testBroadcastVectorValueReal ( )
inline

Definition at line 137 of file parallel_point_test.C.

138  {
139  this->testBroadcastVectorValue<Real>();
140  }

◆ testIrecvSend()

void ParallelPointTest::testIrecvSend ( )
inline

Definition at line 228 of file parallel_point_test.C.

229  {
230  unsigned int procup = (TestCommWorld->rank() + 1) %
231  TestCommWorld->size();
232  unsigned int procdown = (TestCommWorld->size() +
233  TestCommWorld->rank() - 1) %
234  TestCommWorld->size();
235 
236  std::vector<unsigned int> src_val(3), recv_val(3);
237 
238  src_val[0] = 0;
239  src_val[1] = 1;
240  src_val[2] = 2;
241 
242  Parallel::Request request;
243 
244  if (TestCommWorld->size() > 1)
245  {
246  // Default communication
247  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
248 
249  TestCommWorld->receive (procdown,
250  recv_val,
251  request);
252 
253  TestCommWorld->send (procup,
254  src_val);
255 
256  Parallel::wait (request);
257 
258  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
259 
260  for (std::size_t i=0; i<src_val.size(); i++)
261  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
262 
263  // Synchronous communication
264  TestCommWorld->send_mode(Parallel::Communicator::SYNCHRONOUS);
265  std::fill (recv_val.begin(), recv_val.end(), 0);
266 
267 
268  TestCommWorld->receive (procdown,
269  recv_val,
270  request);
271 
272  TestCommWorld->send (procup,
273  src_val);
274 
275  Parallel::wait (request);
276 
277  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
278 
279  for (std::size_t i=0; i<src_val.size(); i++)
280  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
281 
282  // Restore default communication
283  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
284  }
285  }

References TestCommWorld.

◆ testIsendRecv()

void ParallelPointTest::testIsendRecv ( )
inline

Definition at line 167 of file parallel_point_test.C.

168  {
169  unsigned int procup = (TestCommWorld->rank() + 1) %
170  TestCommWorld->size();
171  unsigned int procdown = (TestCommWorld->size() +
172  TestCommWorld->rank() - 1) %
173  TestCommWorld->size();
174 
175  std::vector<unsigned int> src_val(3), recv_val(3);
176 
177  src_val[0] = 0;
178  src_val[1] = 1;
179  src_val[2] = 2;
180 
181  Parallel::Request request;
182 
183  if (TestCommWorld->size() > 1)
184  {
185  // Default communication
186  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
187 
188  TestCommWorld->send (procup,
189  src_val,
190  request);
191 
192  TestCommWorld->receive (procdown,
193  recv_val);
194 
195  Parallel::wait (request);
196 
197  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
198 
199  for (std::size_t i=0; i<src_val.size(); i++)
200  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
201 
202 
203  // Synchronous communication
204  TestCommWorld->send_mode(Parallel::Communicator::SYNCHRONOUS);
205  std::fill (recv_val.begin(), recv_val.end(), 0);
206 
207  TestCommWorld->send (procup,
208  src_val,
209  request);
210 
211  TestCommWorld->receive (procdown,
212  recv_val);
213 
214  Parallel::wait (request);
215 
216  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
217 
218  for (std::size_t i=0; i<src_val.size(); i++)
219  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
220 
221  // Restore default communication
222  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
223  }
224  }

References TestCommWorld.


The documentation for this class was generated from the following file:
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121