PFASST++
mpi_communicator.hpp
Go to the documentation of this file.
1 #ifndef _PFASST_MPI_COMMUNICATOR_HPP_
2 #define _PFASST_MPI_COMMUNICATOR_HPP_
3 
4 #include <stdexcept>
5 #include <vector>
6 using namespace std;
7 
8 #include <mpi.h>
9 
10 #include "pfasst/interfaces.hpp"
11 #include "pfasst/logging.hpp"
12 
13 
29 inline static MPI_Status MPI_Status_factory()
30 {
31  MPI_Status stat;
32  stat.MPI_ERROR = MPI_SUCCESS;
33  stat.MPI_SOURCE = MPI_ANY_SOURCE;
34  stat.MPI_TAG = MPI_ANY_TAG;
35  return stat;
36 }
37 
38 
39 namespace pfasst
40 {
41  namespace mpi
42  {
43  class MPIError
44  : public runtime_error
45  {
46  public:
47  MPIError(const string& msg="");
48  virtual const char* what() const throw();
49  static MPIError from_code(const int err_code);
50  };
51 
64  inline static void check_mpi_error(const int err_code)
65  {
66  if (err_code != MPI_SUCCESS) {
67  throw MPIError::from_code(err_code);
68  }
69  }
70 
71 
72  // forward declare for MPICommunicator
73  class MPIStatus;
74 
75 
77  : public ICommunicator
78  {
80  int _rank;
81  int _size;
82  string _name;
84 
85  public:
87  MPI_Comm comm;
89 
92  MPICommunicator(MPI_Comm comm);
94 
96  virtual void set_comm(MPI_Comm comm);
97  virtual int size();
98  virtual int rank();
99  virtual string name();
101  };
102 
103 
104  class MPIStatus
105  : public IStatus
106  {
107  protected:
108  vector<bool> converged;
110 
111  public:
112  virtual void set_comm(ICommunicator* comm);
113  virtual void clear() override;
114  virtual void set_converged(bool converged) override;
115  virtual bool get_converged(int rank) override;
116  virtual void post(int tag) override;
117  virtual void send(int tag) override;
118  virtual void recv(int tag) override;
119  };
120  } // ::pfasst::mpi
121 } // ::pfasst
122 
123 
124 inline MAKE_LOGGABLE(MPI_Status, mpi_status, os);
125 
127 
128 #endif
STL namespace.
Abstract interface for the current status of the algorithm.
Definition: interfaces.hpp:87
MAKE_LOGGABLE(MPI_Status, mpi_status, os)
interfaces for SDC/MLSDC/PFASST algorithms.
Abstract interface for communicators.
Definition: interfaces.hpp:70
static void check_mpi_error(const int err_code)
checks MPI error code
static MPI_Status MPI_Status_factory()
creates and initializes a new empty MPI_Status object