NetCDF4 C++ API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NcMPI.h
Go to the documentation of this file.
1 
13 #if !defined(INC_netCDF_NcMPI)
14 #define INC_netCDF_NcMPI
15 
16 #ifndef USE_PARALLEL
17  #error For parallel netCDF, define USE_PARALLEL during library compilation.
18 #endif
19 
20 #ifdef USE_PARALLEL
21 
22 #include "mpi.h"
23 #include "NcException.h"
24 #include <sstream>
25 
26 namespace netcdf {
27 
28 
29  class NcMPI
30  {
31  public:
32 
33  NcMPI ()
34  : pComm (0),
35  pInfo (0)
36  {
37  }
38 
40  MPI::Comm & mpiComm,
41  MPI::Info & mpiInfo)
42  : pComm (&mpiComm),
43  pInfo (&mpiInfo)
44  {
45  if ( pComm != 0 && !MPI::Is_initialized() )
46  NcEXCEPTION( "MPI has not been initialized." );
47  }
48 
49  NcMPI ( NcMPI const & rhs )
50  : pComm (rhs.pComm), pInfo (rhs.pInfo)
51  {
52  }
53 
54  MPI::Comm & Comm () { return *pComm; }
55  MPI::Info & Info () { return *pInfo; }
56 
57  bool IsInitialized () const
58  {
59  return pComm != 0 ? MPI::Is_initialized() : false;
60  }
61 
62  static std::string GetVersion ()
63  {
64  #if defined(MPICH_VERSION)
65  return std::string("MPICH ") + std::string(MPICH_VERSION);
66  #elif defined(OMPI_MAJOR_VERSION)
67  char const dot = '.';
68  std::stringstream os;
69  os << "OpenMPI "
70  << OMPI_MAJOR_VERSION << dot << OMPI_MINOR_VERSION << dot << OMPI_RELEASE_VERSION;
71  return os.str();
72  #else
73  std::stringstream os;
74  int version = 0, subversion = 0;
75  MPI::Get_version( version, subversion );
76  os << version << '.' << subversion;
77  return os.str();
78  #endif
79  }
80 
81  private:
82 
83  MPI::Comm * const pComm;
84  MPI::Info * const pInfo;
85 
86  // not used
87  NcMPI operator= ( NcMPI const & rhs );
88 
89  };
90 
91 
92 } // namespace netcdf
93 
94 #endif // USE_PARALLEL
95 
96 #endif // INC_netCDF_NcMPI
MPI::Info & Info()
Definition: NcMPI.h:55
NcMPI(MPI::Comm &mpiComm, MPI::Info &mpiInfo)
Definition: NcMPI.h:39
NcMPI(NcMPI const &rhs)
Definition: NcMPI.h:49
NcMPI()
Definition: NcMPI.h:33
Manages data related to the MPI implementation.
Definition: NcMPI.h:29
#define NcEXCEPTION(a_)
Definition: NcException.h:67
static std::string GetVersion()
Definition: NcMPI.h:62
MPI::Comm & Comm()
Definition: NcMPI.h:54
bool IsInitialized() const
Definition: NcMPI.h:57