26#include "b2ppconfig.h"
33#include "utils/b2comm.H"
41class B2mpi :
public Communicator {
47 B2mpi(
int argc,
char* argv[]);
49 explicit B2mpi() =
default;
52 explicit B2mpi(MPI_Comm comm);
57 explicit B2mpi(
bool participate);
61 static constexpr bool supported =
true;
64 int rank()
const override {
return rank_; }
67 int NumRanks()
const override {
return size_; }
70 bool IsRoot()
const override {
return 0 == rank_; }
79 int GetFcomm()
const override;
82 void Abort(
int errorcode)
override { MPI_Abort(comm_, errorcode); }
85 void Barrier()
override {
86 int error = MPI_Barrier(comm_);
87 check_mpi_error(error);
91 void Recv(
char buffer[], uint64_t length,
int source,
int tag) {
92 const int buflen =
static_cast<int>(length);
93 int error = MPI_Recv(buffer, buflen, MPI_BYTE, source, tag, comm_, &status_);
94 check_mpi_error(error);
98 void Send(
char buffer[], uint64_t length,
int target,
int tag) {
99 const int buflen =
static_cast<int>(length);
100 int error = MPI_Send(buffer, buflen, MPI_BYTE, target, tag, comm_);
101 check_mpi_error(error);
105 void Bcast(uint64_t buffer[], uint64_t length,
int root = 0)
override {
106 const int buflen =
static_cast<int>(length);
107 int error = MPI_Bcast(buffer, buflen, MPI_UNSIGNED_LONG, root, comm_);
108 check_mpi_error(error);
111 void Bcast(
int buffer[], uint64_t length,
int root = 0)
override {
112 int buflen =
static_cast<int>(length);
113 int error = MPI_Bcast(buffer, buflen, MPI_INT, root, comm_);
114 check_mpi_error(error);
117 void Bcast(
double buffer[], uint64_t length,
int root = 0)
override {
118 int buflen =
static_cast<int>(length);
119 int error = MPI_Bcast(buffer, buflen, MPI_DOUBLE, root, comm_);
120 check_mpi_error(error);
125 uint64_t ProbeByteCount(
int source,
int tag)
override {
127 int error = MPI_Probe(source, tag, comm_, &status_);
128 if (0 == error) {
error = MPI_Get_count(&status_, MPI_BYTE, &message_size); }
129 check_mpi_error(error);
130 return static_cast<uint64_t
>(message_size);
135 static constexpr int kMpiColor = 2000;
138 static constexpr int kFsiColor = 3000;
147 bool ismain_ =
false;
150 MPI_Comm comm_ = MPI_COMM_NULL;
163 void check_mpi_error(
int errorcode) {
164 if (errorcode != MPI_SUCCESS) {
165 char errormessage[MPI_MAX_ERROR_STRING + 1];
167 MPI_Error_string(errorcode, errormessage, &resultlen);
168 errormessage[resultlen] =
'\0';
169 Exception() <<
"MPI Error: " << errormessage <<
THROW;
182class B2mpi :
public Communicator {
184 static constexpr bool supported =
false;
190 int rank()
const override {
return 0; }
191 int NumRanks()
const override {
return 0; }
192 bool IsRoot()
const override {
return false; }
196 int GetFcomm()
const override {
return 0; }
197 void Abort(
int errorcode)
override {}
198 void Barrier()
override {}
200 void Recv(
char buffer[], uint64_t length,
int source,
int tag)
override {}
201 void Send(
char buffer[], uint64_t length,
int target,
int tag)
override {}
203 void Bcast(uint64_t buffer[], uint64_t length,
int root = 0)
override {}
204 void Bcast(
int buffer[], uint64_t length,
int root = 0)
override {}
205 void Bcast(
double buffer[], uint64_t length,
int root = 0)
override {}
207 uint64_t ProbeByteCount(
int source,
int tag)
override {
return 0; }
#define THROW
Definition b2exception.H:198
Definition b2cmdline.H:641
Contains the base classes for implementing Finite Elements.
Definition b2boundary_condition.H:32
GenericException< UnimplementedError_name > UnimplementedError
Definition b2exception.H:314