From: Michael P. <mpo...@pu...> - 2018-06-13 17:03:11
|
Hello John, I played with it, and this is what worked for me. #include <vector> #include <sstream> using namespace std; #define private public//to get access to libMesh::LibMeshInit._vtk_mpi_controller #include "libmesh/mesh_generation.h" #include "libmesh/mesh.h" #include "libmesh/vtk_io.h" #include "libmesh/libmesh.h" #include "vtkMPIController.h" int main(int argc, char ** argv) { MPI_Init(&argc, &argv); { libMesh::LibMeshInit init (argc, argv,MPI_COMM_WORLD); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); vtkMPICommunicator* mcomm = vtkMPICommunicator::GetWorldCommunicator()->NewInstance (); mcomm->SplitInitialize (mcomm, rank, 0); init._vtk_mpi_controller->SetCommunicator (mcomm); libMesh::Mesh mesh(libMesh::Parallel::Communicator(MPI_COMM_SELF)); libMesh::MeshTools::Generation::build_cube (mesh, 10, 10, 5, 0.0, 2.0, 0.0, 3.0, 0.0, 4.0,libMesh::HEX8); if (rank == 0) { libMesh::VTKIO out(mesh); out.write("mesh1.pvtu"); } } MPI_Finalize(); return 0; } What do you think? Can you provide an access to libMesh::LibMeshInit._vtk_mpi_controller? Or there is a better solution? Michael. On 06/13/2018 12:28 PM, John Peterson wrote: > > > On Wed, Jun 13, 2018 at 10:14 AM, Michael Povolotskyi > <mpo...@pu... <mailto:mpo...@pu...>> wrote: > > Thank you John, > > I do have some MPI code before LibMeshInit in my real application. > > Also, If I do not call MPI_Finalize at the very end I'm getting > warning messages from MPI. > > Thank you for you explanation with .pvtu, I have changed my code > to libMesh::VTKIO out(mesh); out.write("mesh1.pvtu"); and this > worked. > > Do you have any suggestions for the Problem #2 that I reported? > > It seems to me that the problem is that the communicator of the > Mesh object is smaller than the communicator of the VTK. This > causes a problem for me. > > > Hmm, I don't think we have considered this use case in the past, the > vtkMPIController is initialized in libmesh.C, and it must be assuming > MPI_COMM_WORLD... > > _vtk_mpi_controller = vtkMPIController::New(); > _vtk_mpi_controller->Initialize(&argc, const_cast<char ***>(&argv), > /*initialized_externally=*/1); > _vtk_mpi_controller->SetGlobalController(_vtk_mpi_controller); > > In order for the parallel VTK writer to work, the Mesh probably > therefore also needs to be using MPI_COMM_WORLD. > > -- > John |