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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (CheckpointIOTest)
 This test verifies that we can write files with the CheckpointIO object. More...
 
 CPPUNIT_TEST (testAsciiDistRepSplitter)
 
 CPPUNIT_TEST (testBinaryDistRepSplitter)
 
 CPPUNIT_TEST (testAsciiRepDistSplitter)
 
 CPPUNIT_TEST (testBinaryRepDistSplitter)
 
 CPPUNIT_TEST (testAsciiRepRepSplitter)
 
 CPPUNIT_TEST (testBinaryRepRepSplitter)
 
 CPPUNIT_TEST (testAsciiDistDistSplitter)
 
 CPPUNIT_TEST (testBinaryDistDistSplitter)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
template<typename MeshA , typename MeshB >
void testSplitter (bool binary, bool using_distmesh, bool skip_partition=false)
 
void testAsciiDistRepSplitter ()
 
void testBinaryDistRepSplitter ()
 
void testAsciiRepDistSplitter ()
 
void testBinaryRepDistSplitter ()
 
void testAsciiRepRepSplitter ()
 
void testBinaryRepRepSplitter ()
 
void testAsciiDistDistSplitter ()
 
void testBinaryDistDistSplitter ()
 
void testAsciiDistDistSplitterCache ()
 

Detailed Description

Definition at line 14 of file checkpoint.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/8]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiDistRepSplitter  )

◆ CPPUNIT_TEST() [2/8]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryDistRepSplitter  )

◆ CPPUNIT_TEST() [3/8]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiRepDistSplitter  )

◆ CPPUNIT_TEST() [4/8]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryRepDistSplitter  )

◆ CPPUNIT_TEST() [5/8]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiRepRepSplitter  )

◆ CPPUNIT_TEST() [6/8]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryRepRepSplitter  )

◆ CPPUNIT_TEST() [7/8]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiDistDistSplitter  )

◆ CPPUNIT_TEST() [8/8]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryDistDistSplitter  )

◆ CPPUNIT_TEST_SUITE_END()

CheckpointIOTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

CheckpointIOTest::LIBMESH_CPPUNIT_TEST_SUITE ( CheckpointIOTest  )

This test verifies that we can write files with the CheckpointIO object.

◆ setUp()

void CheckpointIOTest::setUp ( )
inline

Definition at line 37 of file checkpoint.C.

38  {
39  }

◆ tearDown()

void CheckpointIOTest::tearDown ( )
inline

Definition at line 41 of file checkpoint.C.

42  {
43  }

◆ testAsciiDistDistSplitter()

void CheckpointIOTest::testAsciiDistDistSplitter ( )
inline

Definition at line 172 of file checkpoint.C.

173  {
174  LOG_UNIT_TEST;
175 
176  testSplitter<DistributedMesh, DistributedMesh>(false, true);
177  }

◆ testAsciiDistDistSplitterCache()

void CheckpointIOTest::testAsciiDistDistSplitterCache ( )
inline

Definition at line 186 of file checkpoint.C.

187  {
188  LOG_UNIT_TEST;
189 
190  testSplitter<DistributedMesh, DistributedMesh>(false, true, true);
191  }

◆ testAsciiDistRepSplitter()

void CheckpointIOTest::testAsciiDistRepSplitter ( )
inline

Definition at line 130 of file checkpoint.C.

131  {
132  LOG_UNIT_TEST;
133 
134  testSplitter<DistributedMesh, ReplicatedMesh>(false, true);
135  }

◆ testAsciiRepDistSplitter()

void CheckpointIOTest::testAsciiRepDistSplitter ( )
inline

Definition at line 144 of file checkpoint.C.

145  {
146  LOG_UNIT_TEST;
147 
148  testSplitter<ReplicatedMesh, DistributedMesh>(false, true);
149  }

◆ testAsciiRepRepSplitter()

void CheckpointIOTest::testAsciiRepRepSplitter ( )
inline

Definition at line 158 of file checkpoint.C.

159  {
160  LOG_UNIT_TEST;
161 
162  testSplitter<ReplicatedMesh, ReplicatedMesh>(false, false);
163  }

◆ testBinaryDistDistSplitter()

void CheckpointIOTest::testBinaryDistDistSplitter ( )
inline

Definition at line 179 of file checkpoint.C.

180  {
181  LOG_UNIT_TEST;
182 
183  testSplitter<DistributedMesh, DistributedMesh>(true, true);
184  }

◆ testBinaryDistRepSplitter()

void CheckpointIOTest::testBinaryDistRepSplitter ( )
inline

Definition at line 137 of file checkpoint.C.

138  {
139  LOG_UNIT_TEST;
140 
141  testSplitter<DistributedMesh, ReplicatedMesh>(true, true);
142  }

◆ testBinaryRepDistSplitter()

void CheckpointIOTest::testBinaryRepDistSplitter ( )
inline

Definition at line 151 of file checkpoint.C.

152  {
153  LOG_UNIT_TEST;
154 
155  testSplitter<ReplicatedMesh, DistributedMesh>(true, true);
156  }

◆ testBinaryRepRepSplitter()

void CheckpointIOTest::testBinaryRepRepSplitter ( )
inline

Definition at line 165 of file checkpoint.C.

166  {
167  LOG_UNIT_TEST;
168 
169  testSplitter<ReplicatedMesh, ReplicatedMesh>(true, false);
170  }

◆ testSplitter()

template<typename MeshA , typename MeshB >
void CheckpointIOTest::testSplitter ( bool  binary,
bool  using_distmesh,
bool  skip_partition = false 
)
inline

Definition at line 47 of file checkpoint.C.

References TIMPI::Communicator::barrier(), libMesh::CheckpointIO::binary(), libMesh::MeshTools::Generation::build_square(), libMesh::ParallelObject::comm(), libMesh::CheckpointIO::current_n_processors(), libMesh::CheckpointIO::current_processor_ids(), distance(), mesh, libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_partitions(), libMesh::ParallelObject::n_processors(), libMesh::CheckpointIO::parallel(), libMesh::MeshBase::partition(), libMesh::ParallelObject::processor_id(), libMesh::QUAD4, libMesh::CheckpointIO::read(), TIMPI::Communicator::size(), libMesh::MeshBase::skip_partitioning(), TIMPI::Communicator::sum(), TestCommWorld, and libMesh::CheckpointIO::write().

48  {
49  // The CheckpointIO-based splitter requires XDR.
50 #ifdef LIBMESH_HAVE_XDR
51 
52  // In this test, we partition the mesh into n_procs parts. Don't
53  // try to partition a DistributedMesh into more parts than we have
54  // processors, though.
55  const unsigned int n_procs = using_distmesh ?
56  std::min(static_cast<processor_id_type>(2), TestCommWorld->size()) :
57  2;
58 
59  // The number of elements in the original mesh. For verification
60  // later.
61  dof_id_type original_n_elem = 0;
62 
63  const std::string filename =
64  std::string("checkpoint_splitter.cp") + (binary ? "r" : "a");
65 
66  {
67  MeshA mesh(*TestCommWorld);
68 
70  4, 4,
71  0., 1.,
72  0., 1.,
73  QUAD4);
74 
75  // Store the number of elements that were in the original mesh.
76  original_n_elem = mesh.n_elem();
77 
78  // Partition the mesh into n_procs pieces
79  mesh.partition(n_procs);
80 
81  // Write out checkpoint files for each piece. Since on a
82  // ReplicatedMesh we might have more pieces than we do
83  // processors, some processors may have to write out more than
84  // one piece.
85  CheckpointIO cpr(mesh);
86  cpr.current_processor_ids().clear();
87  for (processor_id_type pid = mesh.processor_id(); pid < n_procs; pid += mesh.n_processors())
88  cpr.current_processor_ids().push_back(pid);
89  cpr.current_n_processors() = n_procs;
90  cpr.binary() = binary;
91  cpr.parallel() = true;
92  cpr.write(filename);
93  }
94 
96 
97  // Test that we can read in the files we wrote and sum up to the
98  // same total number of elements.
99  {
100  MeshB mesh(*TestCommWorld);
101  if (skip_partition)
102  mesh.skip_partitioning(true);
103 
104  CheckpointIO cpr(mesh);
105  cpr.current_n_processors() = n_procs;
106  cpr.binary() = binary;
107  cpr.read(filename);
108 
109  // If we decided to skip partitioning, then we shouldn't be
110  // waiting for a partition() call to get our n_partitions()
111  // cache in order
112  if (skip_partition)
113  CPPUNIT_ASSERT_EQUAL(mesh.n_partitions(), n_procs);
114 
115  std::size_t read_in_elements = 0;
116 
117  for (unsigned pid=mesh.processor_id(); pid<n_procs; pid += mesh.n_processors())
118  {
119  read_in_elements += std::distance(mesh.pid_elements_begin(pid),
120  mesh.pid_elements_end(pid));
121  }
122  mesh.comm().sum(read_in_elements);
123 
124  // Verify that we read in exactly as many elements as we started with.
125  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(read_in_elements), original_n_elem);
126  }
127 #endif // LIBMESH_HAVE_XDR
128  }
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
Definition: checkpoint_io.h:61
void skip_partitioning(bool skip)
If true is passed in then nothing on this mesh will be (re)partitioned.
Definition: mesh_base.h:1254
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
void sum(T &r) const
void barrier() const
MeshBase & mesh
const Parallel::Communicator & comm() const
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
Real distance(const Point &p)
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition: mesh_base.C:1576
processor_id_type size() const
uint8_t processor_id_type
processor_id_type n_processors() const
unsigned int n_partitions() const
Definition: mesh_base.h:1345
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
uint8_t dof_id_type
Definition: id_types.h:67

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