Add isRankZero() utility.

This commit is contained in:
Atgeirr Flø Rasmussen
2016-10-17 13:40:49 +02:00
parent 9e1ba49554
commit 5559fbd233
2 changed files with 23 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
#include <opm/autodiff/NewtonIterationUtilities.hpp>
#include <opm/autodiff/AutoDiffHelpers.hpp>
#include <opm/core/linalg/ParallelIstlInformation.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/utility/platform_dependent/disable_warnings.h>
@@ -288,5 +289,24 @@ namespace Opm
/// Return true if this is a serial run, or rank zero on an MPI run.
bool isRankZero(const boost::any& parallel_info)
{
#if HAVE_MPI
if (parallel_info.type() == typeid(ParallelISTLInformation)) {
const ParallelISTLInformation& info =
boost::any_cast<const ParallelISTLInformation&>(parallel_info);
return info.communicator().rank() == 0;
} else {
return true;
}
#else
static_cast<void>(parallel_info); // Suppress unused argument warning.
return true;
#endif
}
} // namespace Opm

View File

@@ -21,6 +21,7 @@
#define OPM_NEWTONITERATIONUTILITIES_HEADER_INCLUDED
#include <opm/autodiff/AutoDiffBlock.hpp>
#include <boost/any.hpp>
#include <vector>
namespace Opm
@@ -58,6 +59,8 @@ namespace Opm
Eigen::SparseMatrix<double, Eigen::RowMajor>& A,
AutoDiffBlock<double>::V& b);
/// Return true if this is a serial run, or rank zero on an MPI run.
bool isRankZero(const boost::any& parallel_info);
} // namespace Opm