6 #if defined(COIN_HAS_MPI)
11 #define MPICH_SKIP_MPICXX
20 bool BCP_mpi_environment::mpi_init_called =
false;
21 int BCP_mpi_environment::num_proc = 0;
22 int BCP_mpi_environment::seqproc = 0;
26 int BCP_mpi_environment::is_mpi(
int argc,
char *argv[])
29 if (! mpi_init_called) {
30 MPI_Init(&argc, &argv);
33 if (MPI_Comm_size(MPI_COMM_WORLD, &num_proc) != MPI_SUCCESS) {
37 mpi_init_called =
true;
39 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
46 BCP_mpi_environment::BCP_mpi_environment(
int argc,
char *argv[])
54 BCP_mpi_environment::~BCP_mpi_environment()
57 mpi_init_called =
false;
63 BCP_mpi_environment::check_error(
const int code,
const char* str)
const
65 if (code != MPI_SUCCESS){
66 printf(
"%s returned error code %i.\n", str, code);
77 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
78 setvbuf(stdout, (
char *)NULL, _IOLBF, 0);
83 BCP_mpi_environment::parent_process()
86 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
95 BCP_mpi_environment::alive(
const int pid)
103 BCP_mpi_environment::alive(
int num,
const int* pids)
116 check_error(MPI_Send(&buf, 0, MPI_CHAR,
117 target, tag, MPI_COMM_WORLD),
"MPI_Send");
124 check_error(MPI_Send(const_cast<char*>(buf.
data()), buf.
size(), MPI_CHAR,
125 target, tag, MPI_COMM_WORLD),
"MPI_Send");
131 BCP_mpi_environment::multicast(
int num,
const int* targets,
135 for (
int i = 0; i < num; ++i) {
136 check_error(MPI_Send(&buf, 0, MPI_CHAR,
137 targets[i], tag, MPI_COMM_WORLD),
"MPI_Send");
142 BCP_mpi_environment::multicast(
int num,
const int* targets,
146 for (
int i = 0; i < num; ++i) {
147 check_error(MPI_Send(const_cast<char*>(buf.
data()), buf.
size(),
148 MPI_CHAR, targets[i], tag, MPI_COMM_WORLD),
156 BCP_mpi_environment::receive(
const int source,
158 const double timeout)
168 check_error(MPI_Probe(pid, msgtag, MPI_COMM_WORLD, &status),
172 check_error(MPI_Iprobe(pid, msgtag, MPI_COMM_WORLD, &flag, &status),
183 check_error(MPI_Get_count( &status, MPI_CHAR, &bytes ),
"MPI_Get_Count");
186 buf.
_sender = status.MPI_SOURCE;
190 check_error(MPI_Recv(buf.
_data, bytes, MPI_CHAR,
191 pid, msgtag, MPI_COMM_WORLD, &status),
"MPI_Recv");
199 BCP_mpi_environment::probe(
const int source,
const BCP_message_tag tag)
206 check_error(MPI_Iprobe(pid, msgtag, MPI_COMM_WORLD, &flag, &status),
214 BCP_mpi_environment::start_process(
const BCP_string& exe,
const bool debug)
218 printf(
"Sorry, MPI2 process spawning is not supported yet...\n");
227 BCP_mpi_environment::start_process(
const BCP_string& exe,
233 printf(
"Sorry, MPI2 process spawning is not supported yet...\n");
242 BCP_mpi_environment::start_processes(
const BCP_string& exe,
249 printf(
"Sorry, MPI2 process spawning is not supported yet...\n");
253 for (
int i = 0; i < proc_num; ++i) {
261 BCP_mpi_environment::start_processes(
const BCP_string& exe,
269 printf(
"Sorry, MPI2 process spawning is not supported yet...\n");
273 for (
int i = 0; i < proc_num; ++i) {
280 int BCP_mpi_environment::num_procs() {
286 struct MPIDI_BGLTS_Request {
287 MPIDI_Message_match
match;
288 MPI_Datatype datatype;
289 struct MPID_Datatype *datatype_ptr;
292 unsigned userbufcount;
295 MPID_Segment segment;
296 MPIDI_BGLTS_REQUEST_STATE state;
301 BGLML_Message msgdata;
303 struct MPID_Request *next;
311 #ifdef MPID_DEV_REQUEST_DECL
312 int MPIDI_BGLTS_get_num_messages()
314 register MPID_Request * rreq = MPIDI_Process.recv_posted_head;
315 register int cnt = 0;
316 while (rreq != NULL) {
318 rreq = rreq->bglts.next;
320 rreq = MPIDI_Process.recv_unexpected_head;
321 while (rreq != NULL) {
323 rreq = rreq->bglts.next;
328 int MPIDI_BGLTS_get_num_messages()
BCP_message_tag
This enumerative constant describes the message tags different processes of BCP understand.
Used when receiving, message with any message tag will be received.
void send(OSCommandLine *oscommandline, OSnl2OS *osnl2os)
Used to indicate that there is no message in the buffer of a process.
static int match(const char **sp, const char *t)
int _sender
The process id of the sender of the last received message.
This class is a very simple impelementation of a constant length string.
This class is an abstract base class for the initializer class the user has to provide.
char * _data
Pointer to the buffer itself.
void clear()
Completely clear the buffer.
Currently there isn't any error handling in BCP.
size_t _size
The current size of the message (the first _size bytes of the buffer).
This class describes the message buffer used for all processes of BCP.
void make_fit(const int add_size)
Reallocate the buffer if necessary so that at least add_size number of additional bytes will fit into...
const char * data() const
Return a const pointer to the data stored in the buffer.
BCP_message_tag _msgtag
The message tag of the last received message.
int size() const
Return the size of the current message in the buffer.