00001 // 00002 //------------------------------------------------------------------------ 00003 // 00004 // File : Communicator.h 00005 // Author : Patrick McCormick (pat@acl.lanl.gov) 00006 // 00007 // $Date: 2003/09/09 10:12:57 $ 00008 // $Revision: 1.17 $ 00009 // 00010 // 00011 // This class forms the basis for a set of Communicator classes that 00012 // can be used to communicate via a messaging based interface. This 00013 // base class should define all the basic operations that are needed 00014 // to support basic communcation. This class may not be as flexible 00015 // as possible but is geared towards MPI-like support code. 00016 // 00017 // There are no real implementation details (so to speak) in this 00018 // class. The only true purpose it serves is to provide an interface 00019 // definition for sending messages. 00020 // 00021 // After recv. operations you can call the RecvMesgSize() method to 00022 // get the actual size of the message received. 00023 // 00024 //------------------------------------------------------------------------ 00025 00026 #ifndef _KOKO_COMMUNICATOR_H_ 00027 #define _KOKO_COMMUNICATOR_H_ 00028 00029 #include "koko.h" 00030 #include "KokoBuffer.h" 00031 00032 class Communicator 00033 { 00034 public: 00035 inline Communicator(void) 00036 { 00037 _nprocs = -1; 00038 _id = -1; 00039 _recv_bytes = 0; 00040 _recv_tag = KOKO_ANY_TAG; 00041 _recv_src = 0; 00042 00043 }; 00044 00045 inline ~Communicator(void) 00046 { }; 00047 00048 // Blocking send. Return of true = successful send, false = failure. 00049 virtual bool Send(KokoProcID id, KokoBuffer &buf, KokoTag tag) = 0; 00050 00051 // Blocking receive. Returns the number of bytes received. The nbytes 00052 // parameter is the number of bytes that can be stored in the buffer 00053 // not the expected size of the message. 00054 virtual int Recv(KokoProcID id, KokoBuffer &buf, KokoTag tag) = 0; 00055 00056 // SendRecv combination. 00057 virtual int SendRecv(KokoProcID to, KokoBuffer &sendbuf, 00058 KokoTag sendtag, KokoProcID from, KokoBuffer &recvbuf, 00059 KokoTag recvtag) = 0; 00060 00061 // Non-blocking send. 00062 virtual KokoMesgHandle ASend(KokoProcID id, KokoBuffer &buf, KokoTag tag) = 0; 00063 00064 // Non-blocking receive. 00065 virtual KokoMesgHandle ARecv(KokoProcID id, KokoBuffer &buf, KokoTag tag) = 0; 00066 00067 // Non-blocking completion operations. 00068 00069 // Return when the operation ID'ed by the given handle completes. Return 00070 // value indicates error condition -- true == error. 00071 virtual bool Wait(KokoMesgHandle &hand) = 0; 00072 00073 // Check to see if the operation ID'ed by the given handle completes. 00074 // Return value indicates if the operation is complete. Error 00075 // conditions are reported to std::cerr. 00076 virtual bool Test(KokoMesgHandle &hand) = 0; 00077 00078 00079 // Broadcast -- send the message to all nodes, including ourself. The 00080 // processor performing the broadcast should be specified by the root 00081 // argument. All other processors (!= root) will receive the broadcat. 00082 virtual bool Broadcast(KokoBuffer &buf, KokoProcID root, KokoTag tag) = 0; 00083 00084 // Barrier -- a standard barrier. 00085 virtual bool Barrier(void) = 0; 00086 00087 // What is our ID? 00088 inline virtual KokoProcID ID(void) 00089 { return _id; }; 00090 00091 inline virtual KokoProcID Rank(void) 00092 { return _id; }; 00093 00094 // Total number of processors in use. 00095 inline virtual unsigned int NumProcessors(void) 00096 { return _nprocs; }; 00097 00098 // You'll have to call this routine to determine how many 00099 // bytes were transfered during a receive operation. 00100 inline virtual int RecvSize(void) 00101 { return _recv_bytes; }; 00102 00103 // If you use an "any" tag request, this routine will give 00104 // you the tag used by a received message. 00105 inline virtual KokoTag RecvTag(void) 00106 { return _recv_tag; }; 00107 00108 inline virtual KokoProcID RecvSource(void) 00109 { return _recv_src; }; 00110 00111 protected: 00112 KokoProcID _id; // Processor/process ID. 00113 int _nprocs; // Total number of processors. 00114 KokoProcID _recv_src; // Who did we receive a message from. 00115 int _recv_bytes; // Total bytes received in a message. 00116 KokoTag _recv_tag; // The tag that was attached to the last 00117 // recv'ed message. 00118 }; 00119 00120 #endif 00121