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 24 of file parallel_point_test.C.

Member Function Documentation

ParallelPointTest::CPPUNIT_TEST ( testAllGatherPoint  )
ParallelPointTest::CPPUNIT_TEST ( testAllGatherPairPointPoint  )
ParallelPointTest::CPPUNIT_TEST ( testAllGatherPairRealPoint  )
ParallelPointTest::CPPUNIT_TEST ( testBroadcastVectorValueInt  )
ParallelPointTest::CPPUNIT_TEST ( testBroadcastVectorValueReal  )
ParallelPointTest::CPPUNIT_TEST ( testBroadcastPoint  )
ParallelPointTest::CPPUNIT_TEST ( testIsendRecv  )
ParallelPointTest::CPPUNIT_TEST ( testIrecvSend  )
ParallelPointTest::CPPUNIT_TEST_SUITE ( ParallelPointTest  )
ParallelPointTest::CPPUNIT_TEST_SUITE_END ( )
void ParallelPointTest::setUp ( )

Definition at line 42 of file parallel_point_test.C.

43  {}
void ParallelPointTest::tearDown ( )

Definition at line 45 of file parallel_point_test.C.

46  {}
void ParallelPointTest::testAllGatherPairPointPoint ( )

Definition at line 70 of file parallel_point_test.C.

References libMesh::Parallel::Communicator::allgather(), libMesh::Parallel::Communicator::rank(), libMesh::Real, libMesh::Parallel::Communicator::size(), and TestCommWorld.

71  {
72  std::vector<std::pair<Point, Point>> vals;
73  Real myrank = TestCommWorld->rank();
75  (std::make_pair(Point(myrank, myrank+0.125, myrank+0.25), Point(myrank+0.5, myrank+0.625, myrank+0.75)), vals);
76 
77  const std::size_t comm_size = TestCommWorld->size();
78  const std::size_t vec_size = vals.size();
79  CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
80 
81  for (processor_id_type i=0; i<vals.size(); i++)
82  {
83  Real theirrank = i;
84  CPPUNIT_ASSERT_EQUAL( theirrank, vals[i].first(0) );
85  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.125), vals[i].first(1) );
86  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i].first(2) );
87  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i].second(0) );
88  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.625), vals[i].second(1) );
89  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.75), vals[i].second(2) );
90  }
91  }
unsigned int size() const
Definition: parallel.h:726
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
uint8_t processor_id_type
Definition: id_types.h:99
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
void allgather(const T &send, std::vector< T > &recv) const
Take a vector of length this->size(), and fill in recv[processor_id] = the value of send on that proc...
void ParallelPointTest::testAllGatherPairRealPoint ( )

Definition at line 94 of file parallel_point_test.C.

References libMesh::Parallel::Communicator::allgather(), libMesh::Parallel::Communicator::rank(), libMesh::Real, libMesh::Parallel::Communicator::size(), and TestCommWorld.

95  {
96  std::vector<std::pair<Real, Point>> vals;
97  Real myrank = TestCommWorld->rank();
99  (std::make_pair(Real(myrank+0.75), Point(myrank, myrank+0.25, myrank+0.5)), vals);
100 
101  const std::size_t comm_size = TestCommWorld->size();
102  const std::size_t vec_size = vals.size();
103  CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
104 
105  for (processor_id_type i=0; i<vals.size(); i++)
106  {
107  Real theirrank = i;
108  CPPUNIT_ASSERT_EQUAL( theirrank, vals[i].second(0) );
109  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i].second(1) );
110  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i].second(2) );
111  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.75), vals[i].first );
112  }
113  }
unsigned int size() const
Definition: parallel.h:726
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
uint8_t processor_id_type
Definition: id_types.h:99
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
void allgather(const T &send, std::vector< T > &recv) const
Take a vector of length this->size(), and fill in recv[processor_id] = the value of send on that proc...
void ParallelPointTest::testAllGatherPoint ( )

Definition at line 50 of file parallel_point_test.C.

References libMesh::Parallel::Communicator::allgather(), libMesh::Parallel::Communicator::rank(), libMesh::Real, libMesh::Parallel::Communicator::size(), and TestCommWorld.

51  {
52  std::vector<Point> vals;
53  Real myrank = TestCommWorld->rank();
54  TestCommWorld->allgather(Point(myrank, myrank+0.25, myrank+0.5),vals);
55 
56  const std::size_t comm_size = TestCommWorld->size();
57  const std::size_t vec_size = vals.size();
58  CPPUNIT_ASSERT_EQUAL( comm_size, vec_size );
59  for (processor_id_type i=0; i<vals.size(); i++)
60  {
61  Real theirrank = i;
62  CPPUNIT_ASSERT_EQUAL( theirrank, vals[i](0) );
63  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.25), vals[i](1) );
64  CPPUNIT_ASSERT_EQUAL( theirrank+Real(0.5), vals[i](2) );
65  }
66  }
unsigned int size() const
Definition: parallel.h:726
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
uint8_t processor_id_type
Definition: id_types.h:99
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int rank() const
Definition: parallel.h:724
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
void allgather(const T &send, std::vector< T > &recv) const
Take a vector of length this->size(), and fill in recv[processor_id] = the value of send on that proc...
void ParallelPointTest::testBroadcastPoint ( )

Definition at line 155 of file parallel_point_test.C.

References libMesh::Parallel::Communicator::broadcast(), libMesh::Parallel::Communicator::rank(), libMesh::Real, and TestCommWorld.

156  {
157  std::vector<Point> src(3), dest(3);
158 
159  {
160  Real val=0.;
161  for (unsigned int i=0; i<3; i++)
162  for (unsigned int j=0; j<LIBMESH_DIM; j++)
163  src[i](j) = val++;
164 
165  if (TestCommWorld->rank() == 0)
166  dest = src;
167  }
168 
169  TestCommWorld->broadcast(dest);
170 
171  for (unsigned int i=0; i<3; i++)
172  for (unsigned int j=0; j<LIBMESH_DIM; j++)
173  CPPUNIT_ASSERT_EQUAL (src[i](j), dest[i](j) );
174  }
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
void broadcast(T &data, const unsigned int root_id=0) const
Take a local value and broadcast it to all processors.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int rank() const
Definition: parallel.h:724
template<typename T >
void ParallelPointTest::testBroadcastVectorValue ( )

Definition at line 118 of file parallel_point_test.C.

References libMesh::Parallel::Communicator::broadcast(), libMesh::Parallel::Communicator::rank(), and TestCommWorld.

119  {
120  std::vector<VectorValue<T>> src(3), dest(3);
121 
122  {
123  T val=T(0);
124  for (unsigned int i=0; i<3; i++)
125  for (unsigned int j=0; j<LIBMESH_DIM; j++)
126  src[i](j) = val++;
127 
128  if (TestCommWorld->rank() == 0)
129  dest = src;
130  }
131 
132  TestCommWorld->broadcast(dest);
133 
134  for (unsigned int i=0; i<3; i++)
135  for (unsigned int j=0; j<LIBMESH_DIM; j++)
136  CPPUNIT_ASSERT_EQUAL (src[i](j), dest[i](j) );
137  }
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
void broadcast(T &data, const unsigned int root_id=0) const
Take a local value and broadcast it to all processors.
unsigned int rank() const
Definition: parallel.h:724
void ParallelPointTest::testBroadcastVectorValueInt ( )

Definition at line 141 of file parallel_point_test.C.

142  {
143  this->testBroadcastVectorValue<int>();
144  }
void ParallelPointTest::testBroadcastVectorValueReal ( )

Definition at line 148 of file parallel_point_test.C.

149  {
150  this->testBroadcastVectorValue<Real>();
151  }
void ParallelPointTest::testIrecvSend ( )

Definition at line 239 of file parallel_point_test.C.

References CPPUNIT_TEST_SUITE_REGISTRATION(), libMesh::Parallel::Communicator::DEFAULT, libMesh::Parallel::Communicator::rank(), libMesh::Parallel::Communicator::receive(), libMesh::Parallel::Communicator::send(), libMesh::Parallel::Communicator::send_mode(), libMesh::Parallel::Communicator::size(), libMesh::Parallel::Communicator::SYNCHRONOUS, TestCommWorld, and libMesh::Parallel::wait().

240  {
241  unsigned int procup = (TestCommWorld->rank() + 1) %
242  TestCommWorld->size();
243  unsigned int procdown = (TestCommWorld->size() +
244  TestCommWorld->rank() - 1) %
245  TestCommWorld->size();
246 
247  std::vector<unsigned int> src_val(3), recv_val(3);
248 
249  src_val[0] = 0;
250  src_val[1] = 1;
251  src_val[2] = 2;
252 
254 
255  if (TestCommWorld->size() > 1)
256  {
257  // Default communication
258  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
259 
260  TestCommWorld->receive (procdown,
261  recv_val,
262  request);
263 
264  TestCommWorld->send (procup,
265  src_val);
266 
267  Parallel::wait (request);
268 
269  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
270 
271  for (std::size_t i=0; i<src_val.size(); i++)
272  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
273 
274  // Synchronous communication
275  TestCommWorld->send_mode(Parallel::Communicator::SYNCHRONOUS);
276  std::fill (recv_val.begin(), recv_val.end(), 0);
277 
278 
279  TestCommWorld->receive (procdown,
280  recv_val,
281  request);
282 
283  TestCommWorld->send (procup,
284  src_val);
285 
286  Parallel::wait (request);
287 
288  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
289 
290  for (std::size_t i=0; i<src_val.size(); i++)
291  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
292 
293  // Restore default communication
294  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
295  }
296  }
Status wait(Request &r)
Wait for a non-blocking send or receive to finish.
Definition: parallel.h:565
unsigned int size() const
Definition: parallel.h:726
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
MPI_Request request
Request object for non-blocking I/O.
Definition: parallel.h:171
void send_mode(const SendMode sm)
Explicitly sets the SendMode type used for send operations.
Definition: parallel.h:761
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
Blocking-send to one processor with data-defined type.
Encapsulates the MPI_Request.
Definition: parallel.h:517
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
Blocking-receive from one processor with data-defined type.
unsigned int rank() const
Definition: parallel.h:724
void ParallelPointTest::testIsendRecv ( )

Definition at line 178 of file parallel_point_test.C.

References libMesh::Parallel::Communicator::DEFAULT, libMesh::Parallel::Communicator::rank(), libMesh::Parallel::Communicator::receive(), libMesh::Parallel::Communicator::send(), libMesh::Parallel::Communicator::send_mode(), libMesh::Parallel::Communicator::size(), libMesh::Parallel::Communicator::SYNCHRONOUS, TestCommWorld, and libMesh::Parallel::wait().

179  {
180  unsigned int procup = (TestCommWorld->rank() + 1) %
181  TestCommWorld->size();
182  unsigned int procdown = (TestCommWorld->size() +
183  TestCommWorld->rank() - 1) %
184  TestCommWorld->size();
185 
186  std::vector<unsigned int> src_val(3), recv_val(3);
187 
188  src_val[0] = 0;
189  src_val[1] = 1;
190  src_val[2] = 2;
191 
193 
194  if (TestCommWorld->size() > 1)
195  {
196  // Default communication
197  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
198 
199  TestCommWorld->send (procup,
200  src_val,
201  request);
202 
203  TestCommWorld->receive (procdown,
204  recv_val);
205 
206  Parallel::wait (request);
207 
208  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
209 
210  for (std::size_t i=0; i<src_val.size(); i++)
211  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
212 
213 
214  // Synchronous communication
215  TestCommWorld->send_mode(Parallel::Communicator::SYNCHRONOUS);
216  std::fill (recv_val.begin(), recv_val.end(), 0);
217 
218  TestCommWorld->send (procup,
219  src_val,
220  request);
221 
222  TestCommWorld->receive (procdown,
223  recv_val);
224 
225  Parallel::wait (request);
226 
227  CPPUNIT_ASSERT_EQUAL ( src_val.size() , recv_val.size() );
228 
229  for (std::size_t i=0; i<src_val.size(); i++)
230  CPPUNIT_ASSERT_EQUAL( src_val[i] , recv_val[i] );
231 
232  // Restore default communication
233  TestCommWorld->send_mode(Parallel::Communicator::DEFAULT);
234  }
235  }
Status wait(Request &r)
Wait for a non-blocking send or receive to finish.
Definition: parallel.h:565
unsigned int size() const
Definition: parallel.h:726
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
MPI_Request request
Request object for non-blocking I/O.
Definition: parallel.h:171
void send_mode(const SendMode sm)
Explicitly sets the SendMode type used for send operations.
Definition: parallel.h:761
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
Blocking-send to one processor with data-defined type.
Encapsulates the MPI_Request.
Definition: parallel.h:517
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
Blocking-receive from one processor with data-defined type.
unsigned int rank() const
Definition: parallel.h:724

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