From e4e8d42ea64b94f771793e0e4d7cc9228de9131b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 14 Aug 2009 21:27:59 +0000 Subject: [PATCH] Utilities::System::job_supports_mpi. git-svn-id: https://svn.dealii.org/trunk@19268 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/utilities.h | 20 +++++++++++++++++++- deal.II/base/source/utilities.cc | 16 ++++++++++++++++ deal.II/doc/news/changes.h | 9 +++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/deal.II/base/include/base/utilities.h b/deal.II/base/include/base/utilities.h index 2e9da44e0e..bdc90f9c0c 100644 --- a/deal.II/base/include/base/utilities.h +++ b/deal.II/base/include/base/utilities.h @@ -23,7 +23,8 @@ #if defined(DEAL_II_COMPILER_SUPPORTS_MPI) || defined(DEAL_II_USE_PETSC) #include #else -typedef int MPI_Comm; +//typedef int MPI_Comm; +#include #endif #ifdef DEAL_II_USE_TRILINOS @@ -229,6 +230,23 @@ namespace Utilities */ std::string get_time (); + /** + * Return whether (i) deal.II has + * been compiled to support MPI + * (for example by compiling with + * CXX=mpiCC) and if + * so whether (ii) + * MPI_Init() has + * been called (for example using + * the + * Utilities::System::MPI_InitFinalize + * class). In other words, the + * result indicates whether the + * current job is running under + * MPI. + */ + bool job_supports_mpi (); + /** * Return the number of MPI processes * there exist in the given communicator diff --git a/deal.II/base/source/utilities.cc b/deal.II/base/source/utilities.cc index 93dfdb25ce..6a14aa3f33 100644 --- a/deal.II/base/source/utilities.cc +++ b/deal.II/base/source/utilities.cc @@ -445,6 +445,15 @@ namespace Utilities #ifdef DEAL_II_COMPILER_SUPPORTS_MPI + + bool job_supports_mpi () + { + int MPI_has_been_started = 0; + MPI_Initialized(&MPI_has_been_started); + + return (MPI_has_been_started > 0); + } + // Unfortunately, we have to work // around an oddity in the way PETSc // and some gcc versions interact. If @@ -506,6 +515,13 @@ namespace Utilities #else + bool job_supports_mpi () + { + return false; + } + + + unsigned int get_n_mpi_processes (const MPI_Comm &) { return 1; diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index bb51e567f1..b5944929ba 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -169,6 +169,15 @@ inconvenience this causes.

base

    +
  1. +

    + New: The Utilities::System::job_supports_mpi() can be used to query whether + the current job runs under MPI or not. +
    + (WB 2009/08/14) +

    +
  2. +
  3. New: The Utilities::Trilinos::comm_self function return an MPI -- 2.39.5