VTK
dox/Parallel/MPI/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 "vtkParallelMPIModule.h" // For export macro
00042 #include "vtkCommunicator.h"
00043 
00044 class vtkMPIController;
00045 class vtkProcessGroup;
00046 
00047 class vtkMPICommunicatorOpaqueComm;
00048 class vtkMPICommunicatorOpaqueRequest;
00049 class vtkMPICommunicatorReceiveDataInfo;
00050 
00051 class VTKPARALLELMPI_EXPORT vtkMPICommunicator : public vtkCommunicator
00052 {
00053 public:
00054 //BTX
00055 
00056   class VTKPARALLELMPI_EXPORT Request
00057   {
00058   public:
00059     Request();
00060     Request( const Request& );
00061     ~Request();
00062     Request& operator = ( const Request& );
00063     int Test();
00064     void Cancel();
00065     void Wait();
00066     vtkMPICommunicatorOpaqueRequest* Req;
00067   };
00068 
00069 //ETX
00070 
00071   vtkTypeMacro( vtkMPICommunicator,vtkCommunicator);
00072   void PrintSelf(ostream& os, vtkIndent indent);
00073 
00075   static vtkMPICommunicator* New();
00076 
00079   static vtkMPICommunicator* GetWorldCommunicator();
00080 
00081 
00085   int Initialize(vtkProcessGroup *group);
00086 
00090   int SplitInitialize(vtkCommunicator *oldcomm, int color, int key);
00091 
00093 
00096   virtual int SendVoidArray(const void *data, vtkIdType length, int type,
00097                             int remoteProcessId, int tag);
00098   virtual int ReceiveVoidArray(void *data, vtkIdType length, int type,
00099                                int remoteProcessId, int tag);
00101 
00103 
00108   int NoBlockSend(const int* data, int length, int remoteProcessId, int tag,
00109                   Request& req);
00110   int NoBlockSend(const unsigned long* data, int length, int remoteProcessId,
00111                   int tag, Request& req);
00112   int NoBlockSend(const char* data, int length, int remoteProcessId,
00113                   int tag, Request& req);
00114   int NoBlockSend(const unsigned char* data, int length, int remoteProcessId,
00115                     int tag, Request& req);
00116   int NoBlockSend(const float* data, int length, int remoteProcessId,
00117                   int tag, Request& req);
00118   int NoBlockSend(const double* data, int length, int remoteProcessId,
00119                   int tag, Request& req);
00121 
00123 
00127   int NoBlockReceive(int* data, int length, int remoteProcessId,
00128                      int tag, Request& req);
00129   int NoBlockReceive(unsigned long* data, int length,
00130                      int remoteProcessId, int tag, Request& req);
00131   int NoBlockReceive(char* data, int length, int remoteProcessId,
00132                      int tag, Request& req);
00133   int NoBlockReceive(unsigned char* data, int length, int remoteProcessId,
00134                      int tag, Request& req);
00135   int NoBlockReceive(float* data, int length, int remoteProcessId,
00136                      int tag, Request& req);
00137   int NoBlockReceive(double* data, int length, int remoteProcessId,
00138                      int tag, Request& req);
00139 #ifdef VTK_USE_64BIT_IDS
00140   int NoBlockReceive(vtkIdType* data, int length, int remoteProcessId,
00141                      int tag, Request& req);
00142 #endif
00143 
00144 
00145 
00147 
00150   virtual void Barrier();
00151   virtual int BroadcastVoidArray(void *data, vtkIdType length, int type,
00152                                  int srcProcessId);
00153   virtual int GatherVoidArray(const void *sendBuffer, void *recvBuffer,
00154                               vtkIdType length, int type, int destProcessId);
00155   virtual int GatherVVoidArray(const void *sendBuffer, void *recvBuffer,
00156                                vtkIdType sendLength, vtkIdType *recvLengths,
00157                                vtkIdType *offsets, int type, int destProcessId);
00158   virtual int ScatterVoidArray(const void *sendBuffer, void *recvBuffer,
00159                                vtkIdType length, int type, int srcProcessId);
00160   virtual int ScatterVVoidArray(const void *sendBuffer, void *recvBuffer,
00161                                 vtkIdType *sendLengths, vtkIdType *offsets,
00162                                 vtkIdType recvLength, int type,
00163                                 int srcProcessId);
00164   virtual int AllGatherVoidArray(const void *sendBuffer, void *recvBuffer,
00165                                  vtkIdType length, int type);
00166   virtual int AllGatherVVoidArray(const void *sendBuffer, void *recvBuffer,
00167                                   vtkIdType sendLength, vtkIdType *recvLengths,
00168                                   vtkIdType *offsets, int type);
00169   virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00170                               vtkIdType length, int type,
00171                               int operation, int destProcessId);
00172   virtual int ReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00173                               vtkIdType length, int type,
00174                               Operation *operation, int destProcessId);
00175   virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00176                                  vtkIdType length, int type,
00177                                  int operation);
00178   virtual int AllReduceVoidArray(const void *sendBuffer, void *recvBuffer,
00179                                  vtkIdType length, int type,
00180                                  Operation *operation);
00182 
00184 
00191   int Iprobe(int source, int tag, int* flag, int* actualSource);
00192   int Iprobe(int source, int tag, int* flag, int* actualSource,
00193              int* type, int* size);
00194   int Iprobe(int source, int tag, int* flag, int* actualSource,
00195              unsigned long* type, int* size);
00196   int Iprobe(int source, int tag, int* flag, int* actualSource,
00197              const char* type, int* size);
00198   int Iprobe(int source, int tag, int* flag, int* actualSource,
00199              float* type, int* size);
00200   int Iprobe(int source, int tag, int* flag, int* actualSource,
00201              double* type, int* size);
00203 
00206   int WaitAll(const int count, Request requests[]);
00207 
00211   int WaitAny(const int count, Request requests[], int& idx);
00212 
00214 
00217   int WaitSome(
00218       const int count, Request requests[], int &NCompleted, int *completed );
00220 
00224   int TestAll( const int count, Request requests[], int& flag );
00225 
00227   int TestAny(const int count, Request requests[], int &idx, int &flag );
00228 
00230 
00234   int TestSome(const int count,Request requests[],
00235                int& NCompleted,int *completed);
00236 //BTX
00238 
00239   friend class vtkMPIController;
00240 
00241   vtkMPICommunicatorOpaqueComm *GetMPIComm()
00242     {
00243     return this->MPIComm;
00244     }
00245 
00246   int InitializeExternal(vtkMPICommunicatorOpaqueComm *comm);
00247 
00248 //ETX
00249 
00250   static char* Allocate(size_t size);
00251   static void Free(char* ptr);
00252 
00253 
00255 
00257   vtkSetClampMacro(UseSsend, int, 0, 1);
00258   vtkGetMacro(UseSsend, int);
00259   vtkBooleanMacro(UseSsend, int);
00261 
00263 
00267   void CopyFrom(vtkMPICommunicator* source);
00268 protected:
00269   vtkMPICommunicator();
00270   ~vtkMPICommunicator();
00272 
00273   // Obtain size and rank setting NumberOfProcesses and LocalProcessId Should
00274   // not be called if the current communicator does not include this process
00275   int InitializeNumberOfProcesses();
00276 
00278 
00285   vtkSetMacro(KeepHandle, int);
00286   vtkBooleanMacro(KeepHandle, int);
00288 
00289 
00290   static vtkMPICommunicator* WorldCommunicator;
00291 
00292   void InitializeCopy(vtkMPICommunicator* source);
00293 
00300   void Duplicate(vtkMPICommunicator* source);
00301 
00303 
00304   virtual int ReceiveDataInternal(
00305     char* data, int length, int sizeoftype,
00306     int remoteProcessId, int tag,
00307     vtkMPICommunicatorReceiveDataInfo* info,
00308     int useCopy, int& senderId);
00310 
00311   vtkMPICommunicatorOpaqueComm* MPIComm;
00312 
00313   int Initialized;
00314   int KeepHandle;
00315 
00316   int LastSenderId;
00317   int UseSsend;
00318   static int CheckForMPIError(int err);
00319 
00320 private:
00321   vtkMPICommunicator(const vtkMPICommunicator&);  // Not implemented.
00322   void operator=(const vtkMPICommunicator&);  // Not implemented.
00323 };
00324 
00325 #endif