libMesh
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ParallelPointTest Class Reference
Inheritance diagram for ParallelPointTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (ParallelPointTest)
 
 CPPUNIT_TEST (testAllGatherPoint)
 
 CPPUNIT_TEST (testAllGatherPairPointPoint)
 
 CPPUNIT_TEST (testAllGatherPairRealPoint)
 
 CPPUNIT_TEST (testMapUnionGradient)
 
 CPPUNIT_TEST (testMapUnionPoint)
 
 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 VecType >
void testMapUnionVec ()
 
void testMapUnionGradient ()
 
void testMapUnionPoint ()
 
template<typename T >
void testBroadcastVectorValue ()
 
void testBroadcastVectorValueInt ()
 
void testBroadcastVectorValueReal ()
 
void testBroadcastPoint ()
 
void testIsendRecv ()
 
void testIrecvSend ()
 

Detailed Description

Definition at line 11 of file parallel_point_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/10]

ParallelPointTest::CPPUNIT_TEST ( testAllGatherPairPointPoint  )

◆ CPPUNIT_TEST() [2/10]

ParallelPointTest::CPPUNIT_TEST ( testAllGatherPairRealPoint  )

◆ CPPUNIT_TEST() [3/10]

ParallelPointTest::CPPUNIT_TEST ( testAllGatherPoint  )

◆ CPPUNIT_TEST() [4/10]

ParallelPointTest::CPPUNIT_TEST ( testBroadcastPoint  )

◆ CPPUNIT_TEST() [5/10]

ParallelPointTest::CPPUNIT_TEST ( testBroadcastVectorValueInt  )

◆ CPPUNIT_TEST() [6/10]

ParallelPointTest::CPPUNIT_TEST ( testBroadcastVectorValueReal  )

◆ CPPUNIT_TEST() [7/10]

ParallelPointTest::CPPUNIT_TEST ( testIrecvSend  )

◆ CPPUNIT_TEST() [8/10]

ParallelPointTest::CPPUNIT_TEST ( testIsendRecv  )

◆ CPPUNIT_TEST() [9/10]

ParallelPointTest::CPPUNIT_TEST ( testMapUnionGradient  )

◆ CPPUNIT_TEST() [10/10]

ParallelPointTest::CPPUNIT_TEST ( testMapUnionPoint  )

◆ CPPUNIT_TEST_SUITE_END()

ParallelPointTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

ParallelPointTest::LIBMESH_CPPUNIT_TEST_SUITE ( ParallelPointTest  )

◆ setUp()

void ParallelPointTest::setUp ( )
inline

Definition at line 34 of file parallel_point_test.C.

35 {}

◆ tearDown()

void ParallelPointTest::tearDown ( )
inline

Definition at line 37 of file parallel_point_test.C.

38 {}

◆ testAllGatherPairPointPoint()

void ParallelPointTest::testAllGatherPairPointPoint ( )
inline

Definition at line 64 of file parallel_point_test.C.

65 {
66 LOG_UNIT_TEST;
67
68 std::vector<std::pair<Point, Point>> vals;
69 Real myrank = TestCommWorld->rank();
70 TestCommWorld->allgather
71 (std::make_pair(Point(myrank, myrank+0.125, myrank+0.25), Point(myrank+0.5, myrank+0.625, myrank+0.75)), vals);
72
73 const std::size_t comm_size = TestCommWorld->size();
74 const std::size_t vec_size = vals.size();
75 CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
76
77 for (processor_id_type i=0; i<vals.size(); i++)
78 {
79 Real theirrank = i;
80 CPPUNIT_ASSERT_EQUAL( theirrank, vals[i].first(0) );
81 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.125), vals[i].first(1) );
82 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i].first(2) );
83 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i].second(0) );
84 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.625), vals[i].second(1) );
85 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.75), vals[i].second(2) );
86 }
87 }
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
Communicator * TestCommWorld
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104

References libMesh::Real, and TestCommWorld.

◆ testAllGatherPairRealPoint()

void ParallelPointTest::testAllGatherPairRealPoint ( )
inline

Definition at line 90 of file parallel_point_test.C.

91 {
92 LOG_UNIT_TEST;
93
94 std::vector<std::pair<Real, Point>> vals;
95 Real myrank = TestCommWorld->rank();
96 TestCommWorld->allgather
97 (std::make_pair(Real(myrank+0.75), Point(myrank, myrank+0.25, myrank+0.5)), vals);
98
99 const std::size_t comm_size = TestCommWorld->size();
100 const std::size_t vec_size = vals.size();
101 CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
102
103 for (processor_id_type i=0; i<vals.size(); i++)
104 {
105 Real theirrank = i;
106 CPPUNIT_ASSERT_EQUAL( theirrank, vals[i].second(0) );
107 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i].second(1) );
108 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i].second(2) );
109 CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.75), vals[i].first );
110 }
111 }

References libMesh::Real, and TestCommWorld.

◆ testAllGatherPoint()

void ParallelPointTest::testAllGatherPoint ( )
inline

Definition at line 42 of file parallel_point_test.C.

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

References libMesh::Real, and TestCommWorld.

◆ testBroadcastPoint()

void ParallelPointTest::testBroadcastPoint ( )
inline

Definition at line 197 of file parallel_point_test.C.

198 {
199 LOG_UNIT_TEST;
200
201 std::vector<Point> src(3), dest(3);
202
203 {
204 Real val=0.;
205 for (unsigned int i=0; i<3; i++)
206 for (unsigned int j=0; j<LIBMESH_DIM; j++)
207 src[i](j) = val++;
208
209 if (TestCommWorld->rank() == 0)
210 dest = src;
211 }
212
213 TestCommWorld->broadcast(dest);
214
215 for (unsigned int i=0; i<3; i++)
216 for (unsigned int j=0; j<LIBMESH_DIM; j++)
217 CPPUNIT_ASSERT_EQUAL (src[i](j), dest[i](j) );
218 }

References libMesh::Real, and TestCommWorld.

◆ testBroadcastVectorValue()

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

Definition at line 156 of file parallel_point_test.C.

157 {
158 std::vector<VectorValue<T>> src(3), dest(3);
159
160 {
161 T val=T(0);
162 for (unsigned int i=0; i<3; i++)
163 for (unsigned int j=0; j<LIBMESH_DIM; j++)
164 src[i](j) = val++;
165
166 if (TestCommWorld->rank() == 0)
167 dest = src;
168 }
169
170 TestCommWorld->broadcast(dest);
171
172 for (unsigned int i=0; i<3; i++)
173 for (unsigned int j=0; j<LIBMESH_DIM; j++)
174 CPPUNIT_ASSERT_EQUAL (src[i](j), dest[i](j) );
175 }

References TestCommWorld.

◆ testBroadcastVectorValueInt()

void ParallelPointTest::testBroadcastVectorValueInt ( )
inline

Definition at line 179 of file parallel_point_test.C.

180 {
181 LOG_UNIT_TEST;
182
183 this->testBroadcastVectorValue<int>();
184 }

◆ testBroadcastVectorValueReal()

void ParallelPointTest::testBroadcastVectorValueReal ( )
inline

Definition at line 188 of file parallel_point_test.C.

189 {
190 LOG_UNIT_TEST;
191
192 this->testBroadcastVectorValue<Real>();
193 }

◆ testIrecvSend()

void ParallelPointTest::testIrecvSend ( )
inline

Definition at line 285 of file parallel_point_test.C.

286 {
287 LOG_UNIT_TEST;
288
289 unsigned int procup = (TestCommWorld->rank() + 1) %
290 TestCommWorld->size();
291 unsigned int procdown = (TestCommWorld->size() +
292 TestCommWorld->rank() - 1) %
293 TestCommWorld->size();
294
295 std::vector<unsigned int> src_val(3), recv_val(3);
296
297 src_val[0] = 0;
298 src_val[1] = 1;
299 src_val[2] = 2;
300
301 Parallel::Request request;
302
303 if (TestCommWorld->size() > 1)
304 {
305 // Default communication
307
308 TestCommWorld->receive (procdown,
309 recv_val,
310 request);
311
312 TestCommWorld->send (procup,
313 src_val);
314
315 Parallel::wait (request);
316
317 CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
318
319 for (std::size_t i=0; i<src_val.size(); i++)
320 CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
321
322 // Synchronous communication
324 std::fill (recv_val.begin(), recv_val.end(), 0);
325
326
327 TestCommWorld->receive (procdown,
328 recv_val,
329 request);
330
331 TestCommWorld->send (procup,
332 src_val);
333
334 Parallel::wait (request);
335
336 CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
337
338 for (std::size_t i=0; i<src_val.size(); i++)
339 CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
340
341 // Restore default communication
343 }
344 }
MPI_Request request

References libMesh::Parallel::Communicator::DEFAULT, libMesh::Parallel::Communicator::SYNCHRONOUS, and TestCommWorld.

◆ testIsendRecv()

void ParallelPointTest::testIsendRecv ( )
inline

Definition at line 222 of file parallel_point_test.C.

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

References libMesh::Parallel::Communicator::DEFAULT, libMesh::Parallel::Communicator::SYNCHRONOUS, and TestCommWorld.

◆ testMapUnionGradient()

void ParallelPointTest::testMapUnionGradient ( )
inline

Definition at line 139 of file parallel_point_test.C.

140 {
141 LOG_UNIT_TEST;
142
143 testMapUnionVec<Gradient>();
144 }

◆ testMapUnionPoint()

void ParallelPointTest::testMapUnionPoint ( )
inline

Definition at line 147 of file parallel_point_test.C.

148 {
149 LOG_UNIT_TEST;
150
151 testMapUnionVec<Point>();
152 }

◆ testMapUnionVec()

template<typename VecType >
void ParallelPointTest::testMapUnionVec ( )
inline

Definition at line 116 of file parallel_point_test.C.

117 {
118 // std::map<processor_id_type , std::vector<Point>> vals;
119 std::map<processor_id_type , std::vector<VecType>> vals;
120
121 const processor_id_type myrank = TestCommWorld->rank();
122
123 vals[myrank*2].resize(1);
124 vals[myrank*2][0](0) = myrank+1;
125
126 TestCommWorld->set_union(vals);
127
128 const processor_id_type comm_size = TestCommWorld->size();
129
130 CPPUNIT_ASSERT_EQUAL(vals.size(), std::size_t(comm_size));
131 for (auto p : make_range(comm_size))
132 {
133 CPPUNIT_ASSERT_EQUAL(vals[p*2].size(), std::size_t(1));
134 CPPUNIT_ASSERT_EQUAL(Real(p+1), libmesh_real(vals[p*2][0](0)));
135 }
136 }
T libmesh_real(T a)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References libMesh::libmesh_real(), libMesh::make_range(), libMesh::Real, and TestCommWorld.


The documentation for this class was generated from the following file: