Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : 19 : // Local includes 20 : #include "libmesh/mesh_serializer.h" 21 : #include "libmesh/mesh_base.h" 22 : #include "libmesh/parallel_only.h" 23 : 24 : namespace libMesh 25 : { 26 : 27 347147 : MeshSerializer::MeshSerializer(MeshBase & mesh, bool need_serial, bool serial_only_needed_on_proc_0) : 28 337127 : _mesh(mesh), 29 337127 : reparallelize(false), 30 347147 : resume_allow_remote_element_removal(false) 31 : { 32 5010 : libmesh_parallel_only(mesh.comm()); 33 347147 : if (need_serial && !_mesh.is_serial() && !serial_only_needed_on_proc_0) { 34 77409 : reparallelize = true; 35 77409 : _mesh.allgather(); 36 : } 37 269738 : 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 40 18032 : _mesh.gather_to_zero(); 41 : } 42 : 43 347147 : if (_mesh.allow_remote_element_removal()) 44 : { 45 309387 : resume_allow_remote_element_removal = true; 46 3892 : _mesh.allow_remote_element_removal(false); 47 : } 48 347147 : } 49 : 50 : 51 : 52 357167 : MeshSerializer::~MeshSerializer() 53 : { 54 347147 : if (reparallelize) 55 77409 : _mesh.delete_remote_elements(); 56 : 57 347147 : if (resume_allow_remote_element_removal) 58 309387 : _mesh.allow_remote_element_removal(true); 59 347147 : } 60 : 61 : } // namespace libMesh