From 51c0d42aeda52ee352cba7301ffc067a845c2ff5 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Thu, 5 Jul 2018 15:56:30 -0600 Subject: [PATCH] Replace MPI_Comm functions by those of Utilities namespace. --- source/base/data_out_base.cc | 37 +++++++++++++----------------------- source/base/exceptions.cc | 3 +-- source/base/process_grid.cc | 3 +-- source/distributed/tria.cc | 20 ++++++------------- 4 files changed, 21 insertions(+), 42 deletions(-) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index a6f1f86197..43b975fa21 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -7273,14 +7273,10 @@ DataOutInterface::write_vtu_in_parallel(const char *filename, write_vtu(f); #else - int myrank, nproc; - int ierr = MPI_Comm_rank(comm, &myrank); - AssertThrowMPI(ierr); - ierr = MPI_Comm_size(comm, &nproc); - AssertThrowMPI(ierr); + const int myrank = Utilities::MPI::this_mpi_process(comm); MPI_Info info; - ierr = MPI_Info_create(&info); + int ierr = MPI_Info_create(&info); AssertThrowMPI(ierr); MPI_File fh; ierr = MPI_File_open(comm, @@ -7405,7 +7401,6 @@ DataOutInterface::create_xdmf_entry( MPI_Comm comm) const { unsigned int local_node_cell_count[2], global_node_cell_count[2]; - int myrank; #ifndef DEAL_II_WITH_HDF5 // throw an exception, but first make sure the compiler does not warn about @@ -7425,18 +7420,17 @@ DataOutInterface::create_xdmf_entry( // And compute the global total #ifdef DEAL_II_WITH_MPI - int ierr = MPI_Comm_rank(comm, &myrank); - AssertThrowMPI(ierr); - ierr = MPI_Allreduce(local_node_cell_count, - global_node_cell_count, - 2, - MPI_UNSIGNED, - MPI_SUM, - comm); + const int myrank = Utilities::MPI::this_mpi_process(comm); + int ierr = MPI_Allreduce(local_node_cell_count, + global_node_cell_count, + 2, + MPI_UNSIGNED, + MPI_SUM, + comm); AssertThrowMPI(ierr); #else (void)comm; - myrank = 0; + const int myrank = 0; global_node_cell_count[0] = local_node_cell_count[0]; global_node_cell_count[1] = local_node_cell_count[1]; #endif @@ -7477,14 +7471,11 @@ DataOutInterface::write_xdmf_file( const std::string & filename, MPI_Comm comm) const { - int myrank; - #ifdef DEAL_II_WITH_MPI - const int ierr = MPI_Comm_rank(comm, &myrank); - AssertThrowMPI(ierr); + const int myrank = Utilities::MPI::this_mpi_process(comm); #else (void)comm; - myrank = 0; + const int myrank = 0; #endif // Only rank 0 process writes the XDMF file @@ -7780,9 +7771,7 @@ DataOutBase::write_hdf5_parallel( // If HDF5 is not parallel and we're using multiple processes, abort # ifndef H5_HAVE_PARALLEL # ifdef DEAL_II_WITH_MPI - int world_size; - ierr = MPI_Comm_size(comm, &world_size); - AssertThrowMPI(ierr); + int world_size = Utilities::MPI::n_mpi_processes(comm); AssertThrow( world_size <= 1, ExcMessage( diff --git a/source/base/exceptions.cc b/source/base/exceptions.cc index c9f83a897a..752980fca0 100644 --- a/source/base/exceptions.cc +++ b/source/base/exceptions.cc @@ -424,8 +424,7 @@ namespace { // do the same as in Utilities::MPI::n_mpi_processes() here, // but without error checking to not throw again. - int n_proc = 1; - MPI_Comm_size(MPI_COMM_WORLD, &n_proc); + const int n_proc = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); if (n_proc > 1) { std::cerr diff --git a/source/base/process_grid.cc b/source/base/process_grid.cc index d0fecc6e44..dcb77b7162 100644 --- a/source/base/process_grid.cc +++ b/source/base/process_grid.cc @@ -51,8 +51,7 @@ namespace // Below we always try to create 2D processor grids: - int n_processes; - MPI_Comm_size(mpi_comm, &n_processes); + const int n_processes = Utilities::MPI::n_mpi_processes(mpi_comm); // Get the total number of cores we can occupy in a rectangular dense matrix // with rectangular blocks when every core owns only a single block: diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index c4b959893b..5794e2c300 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -1493,16 +1493,12 @@ namespace parallel const std::string fname_fixed = std::string(filename) + "_fixed.data"; // ----- copied ----- - // from DataOutInterface::write_vtu_parallel + // from DataOutInterface::write_vtu_in_parallel // TODO: write general MPIIO interface - int myrank, nproc; - int ierr = MPI_Comm_rank(mpi_communicator, &myrank); - AssertThrowMPI(ierr); - ierr = MPI_Comm_size(mpi_communicator, &nproc); - AssertThrowMPI(ierr); + const int myrank = Utilities::MPI::this_mpi_process(mpi_communicator); MPI_Info info; - ierr = MPI_Info_create(&info); + int ierr = MPI_Info_create(&info); AssertThrowMPI(ierr); MPI_File fh; ierr = MPI_File_open(mpi_communicator, @@ -1573,16 +1569,12 @@ namespace parallel const std::string fname_fixed = std::string(filename) + "_fixed.data"; // ----- copied ----- - // from DataOutInterface::write_vtu_parallel + // from DataOutInterface::write_vtu_in_parallel // TODO: write general MPIIO interface - int myrank, nproc; - int ierr = MPI_Comm_rank(mpi_communicator, &myrank); - AssertThrowMPI(ierr); - ierr = MPI_Comm_size(mpi_communicator, &nproc); - AssertThrowMPI(ierr); + const int myrank = Utilities::MPI::this_mpi_process(mpi_communicator); MPI_Info info; - ierr = MPI_Info_create(&info); + int ierr = MPI_Info_create(&info); AssertThrowMPI(ierr); MPI_File fh; ierr = MPI_File_open(mpi_communicator, -- 2.39.5