OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
CommMPI.h
Go to the documentation of this file.
1 //
2 // CommMPI - MPI-specific communications object for use with the
3 // Ippl framework.
4 // Allows user to establish id's for available nodes, establish connections,
5 // and send/receive data.
6 //
7 // Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
8 //
9 // All rights reserved
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #ifndef COMM_MPI_H
22 #define COMM_MPI_H
23 
24 #include "Message/Communicate.h"
25 #include <mpi.h>
26 
27 
28 class CommMPI : public Communicate
29 {
30 
31 public:
32  // constructor and destructor
33  // constructor arguments: command-line args, and number of processes
34  // to start (if < 0, start the 'default' number, i.e. the number of
35  // hosts in a MPI virtual machine, the number of nodes in an O2K, etc)
36  CommMPI(int& argc, char**& argv, int procs = (-1), bool mpiinit = true,
37  MPI_Comm mpicomm = MPI_COMM_WORLD);
38  virtual ~CommMPI(void);
39 
40  // return the name of this item
41  virtual const char *name() const
42  {
43  return "MPI";
44  }
45 
46  //
47  // virtual routines to deal with memory management
48  //
49 
50  // clean up after a Message has been used (called by Message).
51  virtual void cleanupMessage(void *);
52 
53  virtual bool raw_send(void*, int size, int node, int tag);
54  virtual MPI_Request raw_isend(void *, int size, int node, int tag);
55  virtual MPI_Request raw_ireceive(char *buf, int size, int node, int tag);
56  virtual int raw_receive(char*, int size, int &node, int &tag);
57  virtual int raw_probe_receive(char *&, int &node, int &tag);
58 
59 protected:
60 
61  // implementation-specific routines (which begin with 'my')
62  // these should be provided in a derived class, and contain the
63  // comm-library-specific code
64 
65  // send a message ... arguments are the Message itself, the
66  // destination node, the 'user' tag, and the 'encoding' tag.
67  // Messages should be sent via the underlying mechanism by using the
68  // encoding tag (one of the COMM_ tags),
69  // and should embed the information about what the user
70  // tag is in the data sent between nodes. Return success.
71  virtual bool mysend(Message *, int node, int utag, int etag);
72 
73  // receive a message from the given node and user tag. Return a NEW
74  // Message object if a message arrives, or NULL if no message available.
75  // node will be set to the node from which the message was sent.
76  // tag will be set to the 'user tag' for that message.
77  // etag is the 'encoding' tag, and must be one of the COMM_ tags.
78  // Only message sent via the underlying mechanism with the
79  // given etag are checked. When one is found, the user tag and sending
80  // node are extracted from the sent data.
81  // If node = COMM_ANY_NODE, checks for messages from any node.
82  // If tag = COMM_ANY_TAG, checks for messages with any user tag.
83  virtual Message *myreceive(int& node, int& tag, int etag);
84 
85  // Synchronize all processors (everybody waits for everybody
86  // else to get here before returning to calling function).
87  virtual void mybarrier(void);
88 
89  // resent a message buffer that has been previously packed and copied
90  // into the provided buffer. Return success.
91  virtual bool resend(void *buf, int size, int node, int etag);
92 
93 private:
94  // an MPI communicator for this object to use, to avoid interfering
95  // with other MPI usage.
96  MPI_Comm communicator;
97 
98  // a flag indicating whether we initialized the communication or not.
100 
101  // take data from the given Message, and pack it into the current send buf
102  void *pack_message(Message *msg, int tag, int &buffsize, int node);
103 };
104 
105 
106 #endif // COMM_MPI_H
CommMPI(int &argc, char **&argv, int procs=(-1), bool mpiinit=true, MPI_Comm mpicomm=MPI_COMM_WORLD)
Definition: CommMPI.cpp:67
virtual bool raw_send(void *, int size, int node, int tag)
Definition: CommMPI.cpp:551
bool weInitialized
Definition: CommMPI.h:99
virtual bool resend(void *buf, int size, int node, int etag)
Definition: CommMPI.cpp:511
MPI_Comm communicator
Definition: CommMPI.h:96
virtual MPI_Request raw_isend(void *, int size, int node, int tag)
Definition: CommMPI.cpp:559
virtual const char * name() const
Definition: CommMPI.h:41
virtual Message * myreceive(int &node, int &tag, int etag)
Definition: CommMPI.cpp:413
virtual void mybarrier(void)
Definition: CommMPI.cpp:502
virtual MPI_Request raw_ireceive(char *buf, int size, int node, int tag)
Definition: CommMPI.cpp:586
virtual ~CommMPI(void)
Definition: CommMPI.cpp:215
virtual int raw_probe_receive(char *&, int &node, int &tag)
Definition: CommMPI.cpp:599
virtual bool mysend(Message *, int node, int utag, int etag)
Definition: CommMPI.cpp:311
void * pack_message(Message *msg, int tag, int &buffsize, int node)
Definition: CommMPI.cpp:289
virtual void cleanupMessage(void *)
Definition: CommMPI.cpp:544
virtual int raw_receive(char *, int size, int &node, int &tag)
Definition: CommMPI.cpp:569