From 6e758be9f91ed9a927eded537778829f09bb7a3a Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 30 Dec 2016 01:03:44 +0100 Subject: [PATCH] Fix compiling with non-MPI PETSc --- include/deal.II/base/exceptions.h | 3 +++ source/base/mpi.cc | 22 +++------------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index 4846a17ee7..5dfca28ebc 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -1204,11 +1204,14 @@ namespace StandardExceptions * exception of type ExcMPI is thrown with the given error code as an * argument. * + * @note Active only if deal.II is compiled with MPI * @ingroup Exceptions * @author David Wells, 2016 */ #define AssertThrowMPI(error_code) AssertThrow(error_code == MPI_SUCCESS, \ dealii::ExcMPI(error_code)) +#else +#define AssertThrowMPI(error_code) {} #endif // DEAL_II_WITH_MPI #ifdef DEAL_II_WITH_CUDA diff --git a/source/base/mpi.cc b/source/base/mpi.cc index b1c770a8a8..8ebab8f77a 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -35,13 +35,11 @@ #endif #ifdef DEAL_II_WITH_PETSC -# ifdef DEAL_II_WITH_MPI # include # include # include # include # include -# endif #endif #ifdef DEAL_II_WITH_SLEPC @@ -64,21 +62,6 @@ namespace Utilities namespace MPI { #ifdef DEAL_II_WITH_MPI - // Unfortunately, we have to work around an oddity in the way PETSc and - // some gcc versions interact. If we use PETSc's MPI dummy implementation, - // it expands the calls to the two MPI functions basically as ``(n_jobs=1, - // 0)'', i.e. it assigns the number one to the variable holding the number - // of jobs, and then uses the comma operator to let the entire expression - // have the value zero. The latter is important, since ``MPI_Comm_size'' - // returns an error code that we may want to check (we don't here, but one - // could in principle), and the trick with the comma operator makes sure - // that both the number of jobs is correctly assigned, and the return - // value is zero. Unfortunately, if some recent versions of gcc detect - // that the comma expression just stands by itself, i.e. the result is not - // assigned to another variable, then they warn ``right-hand operand of - // comma has no effect''. This unwanted side effect can be suppressed by - // casting the result of the entire expression to type ``void'' -- not - // beautiful, but helps calming down unwarranted compiler warnings... unsigned int n_mpi_processes (const MPI_Comm &mpi_communicator) { int n_jobs=1; @@ -324,12 +307,12 @@ namespace Utilities "in a program since it initializes the MPI system.")); - + int ierr; #ifdef DEAL_II_WITH_MPI // if we have PETSc, we will initialize it and let it handle MPI. // Otherwise, we will do it. int MPI_has_been_started = 0; - int ierr = MPI_Initialized(&MPI_has_been_started); + ierr = MPI_Initialized(&MPI_has_been_started); AssertThrowMPI(ierr); AssertThrow (MPI_has_been_started == 0, ExcMessage ("MPI error. You can only start MPI once!")); @@ -351,6 +334,7 @@ namespace Utilities // make sure the compiler doesn't warn about these variables (void)argc; (void)argv; + (void)ierr; #endif // we are allowed to call MPI_Init ourselves and PETScInitialize will -- 2.39.5