VTK
dox/Parallel/vtkMPICommunicator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkMPICommunicator.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00038 #ifndef __vtkMPICommunicator_h
00039 #define __vtkMPICommunicator_h
00040 
00041 #include "vtkCommunicator.h"
00042 
00043 class vtkMPIController;
00044 class vtkProcessGroup;
00045 
00046 class vtkMPICommunicatorOpaqueComm;
00047 class vtkMPICommunicatorOpaqueRequest;
00048 class vtkMPICommunicatorReceiveDataInfo;
00049 
00050 class VTK_PARALLEL_EXPORT vtkMPICommunicator : public vtkCommunicator
00051 {
00052 public:
00053 //BTX
00054 
00055   class VTK_PARALLEL_EXPORT Request
00056   {
00057   public:
00058     Request();
00059     Request( const Request& );
00060     ~Request();
00061     Request& operator = ( const Request& );
00062     int Test();
00063     void Cancel();
00064     void Wait();
00065     vtkMPICommunicatorOpaqueRequest* Req;
00066   };
00067 
00068 //ETX
00069 
00070   vtkTypeMacro( vtkMPICommunicator,vtkCommunicator);
00071   void PrintSelf(ostream& os, vtkIndent indent);
00072   
00074   static vtkMPICommunicator* New();
00075 
00078   static vtkMPICommunicator* GetWorldCommunicator();
00079   
00080 
00084   int Initialize(vtkProcessGroup *group);
00085 
00089   int SplitInitialize(vtkCommunicator *oldcomm, int color, int key);
00090 
00092 
00095   virtual int SendVoidArray(const void *data, vtkIdType length, int type,
00096                             int remoteProcessId, int tag);
00097   virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
00098                                int remoteProcessId, int tag);
00100 
00102 
00107   int NoBlockSend(const int* data, int length, int remoteProcessId, int tag,
00108                   Request& req);
00109   int NoBlockSend(const unsigned long* data, int length, int remoteProcessId,
00110                   int tag, Request& req);
00111   int NoBlockSend(const char* data, int length, int remoteProcessId, 
00112                   int tag, Request& req);
00113   int NoBlockSend(const float* data, int length, int remoteProcessId, 
00114                   int tag, Request& req);
00115   int NoBlockSend(const double* data, int length, int remoteProcessId, 
00116                   int tag, Request& req);
00118 
00120 
00124   int NoBlockReceive(int* data, int length, int remoteProcessId, 
00125                      int tag, Request& req);
00126   int NoBlockReceive(unsigned long* data, int length, 
00127                      int remoteProcessId, int tag, Request& req);
00128   int NoBlockReceive(char* data, int length, int remoteProcessId, 
00129                      int tag, Request& req);
00130   int NoBlockReceive(float* data, int length, int remoteProcessId, 
00131                      int tag, Request& req);
00132   int NoBlockReceive(double* data, int length, int remoteProcessId, 
00133                      int tag, Request& req);
00134 #ifdef VTK_USE_64BIT_IDS
00135   int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId, 
00136                      int tag, Request& req);
00137 #endif
00138 
00139 
00140 
00142 
00145   virtual void Barrier();
00146   virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
00147                                  int srcProcessId);
00148   virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
00149                               vtkIdType length, int type, int destProcessId);
00150   virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
00151                                vtkIdType sendLength, vtkIdType *recvLengths,
00152                                vtkIdType *offsets, int type, int destProcessId);
00153   virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
00154                                vtkIdType length, int type, int srcProcessId);
00155   virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
00156                                 vtkIdType *sendLengths, vtkIdType *offsets,
00157                                 vtkIdType recvLength, int type,
00158                                 int srcProcessId);
00159   virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
00160                                  vtkIdType length, int type);
00161   virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
00162                                   vtkIdType sendLength, vtkIdType *recvLengths,
00163                                   vtkIdType *offsets, int type);
00164   virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00165                               vtkIdType length, int type,
00166                               int operation, int destProcessId);
00167   virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00168                               vtkIdType length, int type,
00169                               Operation *operation, int destProcessId);
00170   virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00171                                  vtkIdType length, int type,
00172                                  int operation);
00173   virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00174                                  vtkIdType length, int type,
00175                                  Operation *operation);
00177 
00179 
00186   int Iprobe(int source, int tag, int* flag, int* actualSource);
00187   int Iprobe(int source, int tag, int* flag, int* actualSource,
00188              int* type, int* size);
00189   int Iprobe(int source, int tag, int* flag, int* actualSource,
00190              unsigned long* type, int* size);
00191   int Iprobe(int source, int tag, int* flag, int* actualSource,
00192              const char* type, int* size);
00193   int Iprobe(int source, int tag, int* flag, int* actualSource,
00194              float* type, int* size);
00195   int Iprobe(int source, int tag, int* flag, int* actualSource,
00196              double* type, int* size);
00198 
00199 //BTX
00200 
00201   friend class vtkMPIController;
00202 
00203   vtkMPICommunicatorOpaqueComm *GetMPIComm()
00204     {
00205     return this->MPIComm;
00206     }
00207 
00208   int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm);
00209 
00210 //ETX
00211 
00212   static char* Allocate(size_t size);
00213   static void Free(char* ptr);
00214 
00215 
00217 
00219   vtkSetClampMacro(UseSsend, int, 0, 1);
00220   vtkGetMacro(UseSsend, int);
00221   vtkBooleanMacro(UseSsend, int);
00223 
00225 
00229   void CopyFrom(vtkMPICommunicator* source);
00230 protected:
00231   vtkMPICommunicator();
00232   ~vtkMPICommunicator();
00234 
00235   // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
00236   // not be called if the current communicator does not include this process
00237   int InitializeNumberOfProcesses();
00238 
00240 
00247   vtkSetMacro(KeepHandle, int);
00248   vtkBooleanMacro(KeepHandle, int);
00250 
00251 
00252   static vtkMPICommunicator* WorldCommunicator;
00253 
00254   void InitializeCopy(vtkMPICommunicator* source);
00255 
00262   void Duplicate(vtkMPICommunicator* source);
00263 
00265 
00266   virtual int ReceiveDataInternal(
00267     char* data, int length, int sizeoftype, 
00268     int remoteProcessId, int tag,
00269     vtkMPICommunicatorReceiveDataInfo* info,
00270     int useCopy, int& senderId);
00272 
00273   vtkMPICommunicatorOpaqueComm* MPIComm;
00274 
00275   int Initialized;
00276   int KeepHandle;
00277 
00278   int LastSenderId;
00279   int UseSsend;
00280   static int CheckForMPIError(int err);
00281 
00282 private:
00283   vtkMPICommunicator(const vtkMPICommunicator&);  // Not implemented.
00284   void operator=(const vtkMPICommunicator&);  // Not implemented.
00285 };
00286 
00287 #endif