From 710b214ab89d6cbb479256116ae74f8849b22482 Mon Sep 17 00:00:00 2001 From: Magdalena Schreter Date: Sun, 27 Nov 2022 20:27:42 +0100 Subject: [PATCH] imporve asserts of MPI::scatter --- include/deal.II/base/mpi.h | 49 ++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/include/deal.II/base/mpi.h b/include/deal.II/base/mpi.h index 45432ac0d2..49e41af38b 100644 --- a/include/deal.II/base/mpi.h +++ b/include/deal.II/base/mpi.h @@ -1287,8 +1287,9 @@ namespace Utilities * argument. * * @param[in] comm MPI communicator. - * @param[in] object_to_send a vector of objects, with size equal to the - * number of processes. + * @param[in] objects_to_send A vector of objects to send from the root + * process, with size equal to the number of processes. On all other + * processes the vector is empty. * @param[in] root_process The process, which sends the objects to all * processes. By default the process with rank 0 is the root process. * @@ -1297,7 +1298,7 @@ namespace Utilities template T scatter(const MPI_Comm & comm, - const std::vector &object_to_send, + const std::vector &objects_to_send, const unsigned int root_process = 0); /** @@ -2121,6 +2122,9 @@ namespace Utilities # ifndef DEAL_II_WITH_MPI (void)comm; (void)root_process; + + AssertDimension(objects_to_send.size(), 1); + return objects_to_send[0]; # else const auto n_procs = dealii::Utilities::MPI::n_mpi_processes(comm); @@ -2128,7 +2132,8 @@ namespace Utilities AssertIndexRange(root_process, n_procs); AssertThrow( - my_rank != root_process || objects_to_send.size() == n_procs, + (my_rank != root_process && objects_to_send.size() == 0) || + objects_to_send.size() == n_procs, ExcMessage( "The number of objects to be scattered must correspond to the number processes.")); @@ -2155,26 +2160,28 @@ namespace Utilities } int n_local_data; - MPI_Scatter(send_counts.data(), - 1, - MPI_INT, - &n_local_data, - 1, - MPI_INT, - root_process, - comm); + int ierr = MPI_Scatter(send_counts.data(), + 1, + MPI_INT, + &n_local_data, + 1, + MPI_INT, + root_process, + comm); + AssertThrowMPI(ierr); std::vector recv_buffer(n_local_data); - MPI_Scatterv(send_buffer.data(), - send_counts.data(), - send_displacements.data(), - MPI_CHAR, - recv_buffer.data(), - n_local_data, - MPI_CHAR, - root_process, - comm); + ierr = MPI_Scatterv(send_buffer.data(), + send_counts.data(), + send_displacements.data(), + MPI_CHAR, + recv_buffer.data(), + n_local_data, + MPI_CHAR, + root_process, + comm); + AssertThrowMPI(ierr); return Utilities::unpack(recv_buffer); # endif -- 2.39.5