OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
CommMPI.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef COMM_MPI_H
12 #define COMM_MPI_H
13 
14 /***************************************************************************
15  * CommMPI.h - MPI-specific communications object for use with the
16  * Ippl framework.
17  * Allows user to establish id's for available nodes, establish connections,
18  * and send/receive data.
19  ***************************************************************************/
20 
21 // include files
22 #include "Message/Communicate.h"
23 #include <mpi.h>
24 
25 
26 class CommMPI : public Communicate
27 {
28 
29 public:
30  // constructor and destructor
31  // constructor arguments: command-line args, and number of processes
32  // to start (if < 0, start the 'default' number, i.e. the number of
33  // hosts in a MPI virtual machine, the number of nodes in an O2K, etc)
34  CommMPI(int& argc, char**& argv, int procs = (-1), bool mpiinit = true,
35  MPI_Comm mpicomm = MPI_COMM_WORLD);
36  virtual ~CommMPI(void);
37 
38  // return the name of this item
39  virtual const char *name() const
40  {
41  return "MPI";
42  }
43 
44  //
45  // virtual routines to deal with memory management
46  //
47 
48  // clean up after a Message has been used (called by Message).
49  virtual void cleanupMessage(void *);
50 
51  virtual bool raw_send(void*, int size, int node, int tag);
52  virtual MPI_Request raw_isend(void *, int size, int node, int tag);
53  virtual MPI_Request raw_ireceive(char *buf, int size, int node, int tag);
54  virtual int raw_receive(char*, int size, int &node, int &tag);
55  virtual int raw_probe_receive(char *&, int &node, int &tag);
56 
57 protected:
58 
59  // implementation-specific routines (which begin with 'my')
60  // these should be provided in a derived class, and contain the
61  // comm-library-specific code
62 
63  // send a message ... arguments are the Message itself, the
64  // destination node, the 'user' tag, and the 'encoding' tag.
65  // Messages should be sent via the underlying mechanism by using the
66  // encoding tag (one of the COMM_ tags),
67  // and should embed the information about what the user
68  // tag is in the data sent between nodes. Return success.
69  virtual bool mysend(Message *, int node, int utag, int etag);
70 
71  // receive a message from the given node and user tag. Return a NEW
72  // Message object if a message arrives, or NULL if no message available.
73  // node will be set to the node from which the message was sent.
74  // tag will be set to the 'user tag' for that message.
75  // etag is the 'encoding' tag, and must be one of the COMM_ tags.
76  // Only message sent via the underlying mechanism with the
77  // given etag are checked. When one is found, the user tag and sending
78  // node are extracted from the sent data.
79  // If node = COMM_ANY_NODE, checks for messages from any node.
80  // If tag = COMM_ANY_TAG, checks for messages with any user tag.
81  virtual Message *myreceive(int& node, int& tag, int etag);
82 
83  // Synchronize all processors (everybody waits for everybody
84  // else to get here before returning to calling function).
85  virtual void mybarrier(void);
86 
87  // resent a message buffer that has been previously packed and copied
88  // into the provided buffer. Return success.
89  virtual bool resend(void *buf, int size, int node, int etag);
90 
91 private:
92  // an MPI communicator for this object to use, to avoid interfering
93  // with other MPI usage.
94  MPI_Comm communicator;
95 
96  // a flag indicating whether we initialized the communication or not.
98 
99  // take data from the given Message, and pack it into the current send buf
100  void *pack_message(Message *msg, int tag, int &buffsize, int node);
101 };
102 
103 
104 #endif // COMM_MPI_H
virtual MPI_Request raw_ireceive(char *buf, int size, int node, int tag)
Definition: CommMPI.cpp:601
virtual void cleanupMessage(void *)
Definition: CommMPI.cpp:559
bool weInitialized
Definition: CommMPI.h:97
virtual int raw_receive(char *, int size, int &node, int &tag)
Definition: CommMPI.cpp:584
virtual const char * name() const
Definition: CommMPI.h:39
virtual int raw_probe_receive(char *&, int &node, int &tag)
Definition: CommMPI.cpp:614
void * pack_message(Message *msg, int tag, int &buffsize, int node)
Definition: CommMPI.cpp:299
virtual bool mysend(Message *, int node, int utag, int etag)
Definition: CommMPI.cpp:321
virtual void mybarrier(void)
Definition: CommMPI.cpp:517
virtual Message * myreceive(int &node, int &tag, int etag)
Definition: CommMPI.cpp:423
virtual ~CommMPI(void)
Definition: CommMPI.cpp:225
virtual MPI_Request raw_isend(void *, int size, int node, int tag)
Definition: CommMPI.cpp:574
virtual bool raw_send(void *, int size, int node, int tag)
Definition: CommMPI.cpp:566
virtual bool resend(void *buf, int size, int node, int etag)
Definition: CommMPI.cpp:526
MPI_Comm communicator
Definition: CommMPI.h:94
CommMPI(int &argc, char **&argv, int procs=(-1), bool mpiinit=true, MPI_Comm mpicomm=MPI_COMM_WORLD)
Definition: CommMPI.cpp:77