00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * 00004 * The IPPL Framework 00005 * 00006 * 00007 * Visit http://people.web.psi.ch/adelmann/ for more details 00008 * 00009 ***************************************************************************/ 00010 00011 #ifndef COMM_MPI_H 00012 #define COMM_MPI_H 00013 00014 /*************************************************************************** 00015 * CommMPI.h - MPI-specific communications object for use with the 00016 * Ippl framework. 00017 * Allows user to establish id's for available nodes, establish connections, 00018 * and send/receive data. 00019 ***************************************************************************/ 00020 00021 // include files 00022 #include "Message/Communicate.h" 00023 #include <mpi.h> 00024 00025 00026 class CommMPI : public Communicate { 00027 00028 public: 00029 // constructor and destructor 00030 // constructor arguments: command-line args, and number of processes 00031 // to start (if < 0, start the 'default' number, i.e. the number of 00032 // hosts in a MPI virtual machine, the number of nodes in an O2K, etc) 00033 CommMPI(int& argc, char**& argv, int procs = (-1), bool mpiinit = true); 00034 virtual ~CommMPI(void); 00035 00036 // return the name of this item 00037 virtual const char *name() const { return "MPI"; } 00038 00039 // 00040 // virtual routines to deal with memory management 00041 // 00042 00043 // clean up after a Message has been used (called by Message). 00044 virtual void cleanupMessage(void *); 00045 00046 protected: 00047 00048 // 00049 // implementation-specific routines (which begin with 'my') 00050 // these should be provided in a derived class, and contain the 00051 // comm-library-specific code 00052 // 00053 00054 // send a message ... arguments are the Message itself, the 00055 // destination node, the 'user' tag, and the 'encoding' tag. 00056 // Messages should be sent via the underlying mechanism by using the 00057 // encoding tag (one of the COMM_ tags), 00058 // and should embed the information about what the user 00059 // tag is in the data sent between nodes. Return success. 00060 virtual bool mysend(Message *, int node, int utag, int etag); 00061 00062 // receive a message from the given node and user tag. Return a NEW 00063 // Message object if a message arrives, or NULL if no message available. 00064 // node will be set to the node from which the message was sent. 00065 // tag will be set to the 'user tag' for that message. 00066 // etag is the 'encoding' tag, and must be one of the COMM_ tags. 00067 // Only message sent via the underlying mechanism with the 00068 // given etag are checked. When one is found, the user tag and sending 00069 // node are extracted from the sent data. 00070 // If node = COMM_ANY_NODE, checks for messages from any node. 00071 // If tag = COMM_ANY_TAG, checks for messages with any user tag. 00072 virtual Message *myreceive(int& node, int& tag, int etag); 00073 00074 // Synchronize all processors (everybody waits for everybody 00075 // else to get here before returning to calling function). 00076 virtual void mybarrier(void); 00077 00078 // resent a message buffer that has been previously packed and copied 00079 // into the provided buffer. Return success. 00080 virtual bool resend(void *buf, int size, int node, int etag); 00081 00082 private: 00083 // an MPI communicator for this object to use, to avoid interfering 00084 // with other MPI usage. 00085 MPI_Comm communicator; 00086 00087 // a flag indicating whether we initialized the communication or not. 00088 bool weInitialized; 00089 00090 // take data from the given Message, and pack it into the current send buf 00091 void *pack_message(Message *msg, int tag, int &buffsize, int node); 00092 }; 00093 00094 00095 #endif // COMM_MPI_H 00096 00097 /*************************************************************************** 00098 * $RCSfile: CommMPI.h,v $ $Author: adelmann $ 00099 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $ 00100 * IPPL_VERSION_ID: $Id: CommMPI.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $ 00101 ***************************************************************************/