libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::MeshSerializer Class Reference

Temporarily serialize a DistributedMesh for non-distributed-mesh capable code paths. More...

#include <mesh_serializer.h>

Public Member Functions

 MeshSerializer (MeshBase &mesh, bool need_serial=true, bool serial_only_needed_on_proc_0=false)
 
 ~MeshSerializer ()
 

Private Attributes

MeshBase_mesh
 
bool reparallelize
 
bool resume_allow_remote_element_removal
 

Detailed Description

Temporarily serialize a DistributedMesh for non-distributed-mesh capable code paths.

A distributed mesh is allgathered by the MeshSerializer constructor if need_serial is true, in which case remote elements are deleted again by the destructor.

Serialization to processor 0 alone (e.g. for serial output from that processor) can be selected in the constructor.

If allow_remote_element_removal() is set to true, that will also be temporarily disabled by the serializer, to be reenabled after serializer destruction if so; this allows prepare_for_use() to be called safely from within serialized code.

If a mesh is explicitly distributed by a delete_remote_elements() call within serialized code, or if allow_remote_element_removal() is explicitly set to true within serialized code, the behavior is undefined.

Author
Roy Stogner
Date
2011-2022 Temporarily serializes a DistributedMesh for output.

Definition at line 55 of file mesh_serializer.h.

Constructor & Destructor Documentation

◆ MeshSerializer()

libMesh::MeshSerializer::MeshSerializer ( MeshBase mesh,
bool  need_serial = true,
bool  serial_only_needed_on_proc_0 = false 
)

Definition at line 27 of file mesh_serializer.C.

References _mesh, libMesh::MeshBase::allgather(), libMesh::MeshBase::allow_remote_element_removal(), libMesh::MeshBase::gather_to_zero(), libMesh::MeshBase::is_serial(), mesh, reparallelize, and resume_allow_remote_element_removal.

27  :
28  _mesh(mesh),
29  reparallelize(false),
31 {
32  libmesh_parallel_only(mesh.comm());
33  if (need_serial && !_mesh.is_serial() && !serial_only_needed_on_proc_0) {
34  reparallelize = true;
35  _mesh.allgather();
36  }
37  else if (need_serial && !_mesh.is_serial() && serial_only_needed_on_proc_0) {
38  // Note: NOT reparallelizing on purpose.
39  // Just waste a bit of space on processor 0 to speed things up
41  }
42 
44  {
47  }
48 }
virtual void allgather()
Gathers all elements and nodes of the mesh onto every processor.
Definition: mesh_base.h:234
MeshBase & mesh
virtual void gather_to_zero()
Gathers all elements and nodes of the mesh onto processor zero.
Definition: mesh_base.h:240
void allow_remote_element_removal(bool allow)
If false is passed in then this mesh will no longer have remote elements deleted when being prepared ...
Definition: mesh_base.h:1189
virtual bool is_serial() const
Definition: mesh_base.h:205

◆ ~MeshSerializer()

libMesh::MeshSerializer::~MeshSerializer ( )

Definition at line 52 of file mesh_serializer.C.

References _mesh, libMesh::MeshBase::allow_remote_element_removal(), libMesh::MeshBase::delete_remote_elements(), reparallelize, and resume_allow_remote_element_removal.

53 {
54  if (reparallelize)
56 
59 }
void allow_remote_element_removal(bool allow)
If false is passed in then this mesh will no longer have remote elements deleted when being prepared ...
Definition: mesh_base.h:1189
virtual void delete_remote_elements()
When supported, deletes all nonlocal elements of the mesh except for "ghosts" which touch a local ele...
Definition: mesh_base.h:247

Member Data Documentation

◆ _mesh

MeshBase& libMesh::MeshSerializer::_mesh
private

Definition at line 67 of file mesh_serializer.h.

Referenced by MeshSerializer(), and ~MeshSerializer().

◆ reparallelize

bool libMesh::MeshSerializer::reparallelize
private

Definition at line 73 of file mesh_serializer.h.

Referenced by MeshSerializer(), and ~MeshSerializer().

◆ resume_allow_remote_element_removal

bool libMesh::MeshSerializer::resume_allow_remote_element_removal
private

Definition at line 80 of file mesh_serializer.h.

Referenced by MeshSerializer(), and ~MeshSerializer().


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