From: Wolfgang Bangerth Date: Thu, 6 Aug 2009 16:03:27 +0000 (+0000) Subject: Utilities::Trilinos::duplicate_communicator. X-Git-Tag: v8.0.0~7375 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dc09e808c91abf871497eef1574f316b131312d;p=dealii.git Utilities::Trilinos::duplicate_communicator. git-svn-id: https://svn.dealii.org/trunk@19192 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/utilities.h b/deal.II/base/include/base/utilities.h index 72b2a63fff..5a9476aaed 100644 --- a/deal.II/base/include/base/utilities.h +++ b/deal.II/base/include/base/utilities.h @@ -365,6 +365,63 @@ namespace Utilities */ const Epetra_Comm& comm_world(); + /** + * Given a communicator, duplicate it. If + * the given communicator is serial, that + * means to just return a copy of + * itself. On the other hand, if it is + * parallel, we duplicate the underlying + * MPI_Comm object: we create a separate + * MPI communicator that contains the + * same processors and in the same order + * but has a separate identifier distinct + * from the given communicator. The + * function returns a pointer to a new + * object of a class derived from + * Epetra_Comm. The caller of this + * function needs to assume ownership of + * this function. + * + * This facility is used to separate + * streams of communication. For example, + * a program could simply use + * MPI_Comm_World for everything. But it + * is easy to come up with scenarios + * where sometimes not all processors + * participate in a communication that is + * intended to be global -- for example + * if we assemble a matrix on a coarse + * mesh with fewer cells than there are + * processors, some processors may not + * sync their matrices with the rest + * because they haven't written into it + * because they own no cells. That's + * clearly a bug. However, if these + * processors just continue their work, + * and the next parallel operation + * happens to be a sync on a different + * matrix, then the sync could succeed -- + * by accident, since different + * processors are talking about different + * matrices. + * + * This kind of situation can be avoided + * if we use different communicators for + * different matrices which reduces the + * likelihood that communications meant + * to be separate aren't recognized as + * such just because they happen on the + * same communicator. In addition, it is + * conceivable that some MPI operations + * can be parallelized using multiple + * threads because their communicators + * identifies the communication in + * question, not their relative timing as + * is the case in a sequential program + * that just uses a single communicator. + */ + Epetra_Comm * + duplicate_communicator (const Epetra_Comm &communicator); /** * Return the number of MPI processes diff --git a/deal.II/base/source/utilities.cc b/deal.II/base/source/utilities.cc index e7fd9fdf5b..7b791c0e23 100644 --- a/deal.II/base/source/utilities.cc +++ b/deal.II/base/source/utilities.cc @@ -32,6 +32,15 @@ # include #endif +#ifdef DEAL_II_USE_TRILINOS +# ifdef DEAL_II_COMPILER_SUPPORTS_MPI +# include +# endif +# include "Epetra_SerialComm.h" +#endif + + + DEAL_II_NAMESPACE_OPEN @@ -599,6 +608,32 @@ namespace Utilities } + + Epetra_Comm * + duplicate_communicator (const Epetra_Comm &communicator) + { +#ifdef DEAL_II_COMPILER_SUPPORTS_MPI + + // see if the communicator is in fact a + // parallel MPI communicator; if so, + // return a duplicate of it + Epetra_MpiComm + *mpi_comm = dynamic_cast(&communicator); + if (mpi_comm != 0) + return new Epetra_MpiComm(duplicate_communicator(mpi_comm->GetMpiComm())); +#endif + + // if we don't support MPI, or if the + // communicator in question was in fact + // not an MPI communicator, return a + // copy of the same object again + Assert (dynamic_cast(&communicator) + != 0, + ExcInternalError()); + return new Epetra_SerialComm(dynamic_cast(communicator)); + } + + unsigned int get_n_mpi_processes (const Epetra_Comm &mpi_communicator) { return mpi_communicator.NumProc(); diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 9109f128dc..6eafb7ac89 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -157,6 +157,16 @@ inconvenience this causes.

base

    +
  1. +

    + New: The Utilities::Trilinos::duplicate_communicator function allows to duplicate + an Epetra_Comm object to get a unique parallel MPI communicator out of an + existing one. +
    + (WB 2009/08/06) +

    +
  2. +
  3. New: There is now a specialization Tensor<0,dim> of tensors of rank 0. Since rank-0