Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

contrib/vtkMultiProcessController.h

Go to the documentation of this file.
00001 /*=========================================================================
00002   
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkMultiProcessController.h,v $
00005   Language:  C++
00006   
00007 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00008 All rights reserved.
00009 
00010 Redistribution and use in source and binary forms, with or without
00011 modification, are permitted provided that the following conditions are met:
00012 
00013  * Redistributions of source code must retain the above copyright notice,
00014    this list of conditions and the following disclaimer.
00015 
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019 
00020  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00021    of any contributors may be used to endorse or promote products derived
00022    from this software without specific prior written permission.
00023 
00024  * Modified source versions must be plainly marked as such, and must not be
00025    misrepresented as being the original software.
00026 
00027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00028 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00031 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00032 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00033 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00034 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00035 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 
00038 =========================================================================*/
00055 #ifndef __vtkMultiProcessController_h
00056 #define __vtkMultiProcessController_h
00057 
00058 #include "vtkObject.h"
00059 #include "vtkDataObject.h"
00060 class vtkDataSet;
00061 class vtkImageData;
00062 class vtkCollection;
00063 
00064 
00065 #define VTK_MP_CONTROLLER_MAX_PROCESSES 1024
00066 #define VTK_MP_CONTROLLER_ANY_SOURCE -1
00067 #define VTK_MP_CONTROLLER_INVALID_SOURCE -2
00068 
00069 // The special tag used for RMI communication.
00070 #define VTK_MP_CONTROLLER_RMI_TAG 315167
00071 #define VTK_MP_CONTROLLER_RMI_ARG_TAG 315168
00072 
00073 
00074 // Internally implemented RMI to break the process loop.
00075 #define VTK_BREAK_RMI_TAG           239954
00076 
00077 
00078 class vtkMultiProcessController;
00079 
00080 
00081 //BTX
00082 // The type of function that gets called when new processes are initiated.
00083 typedef void (*vtkProcessFunctionType)(vtkMultiProcessController *controller, 
00084                                        void *userData);
00085 
00086 // The type of function that gets called when an RMI is triggered.
00087 typedef void (*vtkRMIFunctionType)(void *localArg, 
00088                                    void *remoteArg, int remoteArgLength, 
00089                                    int remoteProcessId);
00090 //ETX
00091 
00092 
00093 class VTK_EXPORT vtkMultiProcessController : public vtkObject
00094 {
00095 public:
00096   static vtkMultiProcessController *New();
00097   vtkTypeMacro(vtkMultiProcessController,vtkObject);
00098   void PrintSelf(ostream& os, vtkIndent indent);
00099 
00103   virtual void Initialize(int vtkNotUsed(argc), char *arcv[]) {arcv=arcv;}
00104 
00108   virtual void SetNumberOfProcesses(int num);
00109   vtkGetMacro( NumberOfProcesses, int );
00110 
00111   //BTX
00115   void SetSingleMethod(vtkProcessFunctionType, void *data);
00116   //ETX
00117 
00121   virtual void SingleMethodExecute() = 0;
00122   
00123   //BTX
00128   void SetMultipleMethod(int index, vtkProcessFunctionType, void *data); 
00129   //ETX
00130 
00134   virtual void MultipleMethodExecute() = 0;
00135   
00137   virtual int GetLocalProcessId() { return this->LocalProcessId; }
00138 
00143   static vtkMultiProcessController *GetGlobalController();
00144   
00145   //------------------ Communication --------------------
00146   
00149   virtual int Send(vtkDataObject *data, int remoteProcessId, int tag);
00150   
00152   virtual int Send(int *data, int length, int remoteProcessId, int tag) = 0;
00153   virtual int Send(unsigned long *data, int length, 
00154          int remoteProcessId, int tag) = 0;
00155   virtual int Send(char *data, int length, 
00156          int remoteProcessId, int tag) = 0;
00157   virtual int Send(float *data, int length, 
00158          int remoteProcessId, int tag) = 0;
00159 
00162   virtual int Receive(vtkDataObject *data, int remoteProcessId, int tag);
00163 
00167   virtual int Receive(int *data, int length, int remoteProcessId, int tag) = 0;
00168   virtual int Receive(unsigned long *data, int length, 
00169             int remoteProcessId, int tag) = 0;
00170   virtual int Receive(char *data, int length, 
00171             int remoteProcessId, int tag) = 0;
00172   virtual int Receive(float *data, int length, 
00173             int remoteProcessId, int tag) = 0;
00174   
00180   vtkSetMacro(ForceDeepCopy, int);
00181   vtkGetMacro(ForceDeepCopy, int);
00182   vtkBooleanMacro(ForceDeepCopy, int);
00183   
00184   //------------------ RMIs --------------------
00185   //BTX
00191   void AddRMI(vtkRMIFunctionType, void *localArg, int tag);
00192   
00194   void RemoveRMI(vtkRMIFunctionType f, void *arg, int tag)
00195     {f = f; arg = arg; tag = tag; vtkErrorMacro("RemoveRMI Not Implemented Yet");};
00196   //ETX
00197   
00199   void TriggerRMI(int remoteProcessId, void *arg, int argLength, int tag);
00200 
00202   void TriggerRMI(int remoteProcessId, char *arg, int tag) 
00203     { this->TriggerRMI(remoteProcessId, (void*)arg, strlen(arg)+1, tag); }
00204 
00206   void TriggerRMI(int remoteProcessId, int tag)
00207     { this->TriggerRMI(remoteProcessId, NULL, 0, tag); }
00208 
00211   void ProcessRMIs();
00212 
00216   vtkSetMacro(BreakFlag, int);
00217   vtkGetMacro(BreakFlag, int);
00218   
00219   //------------------ Timing --------------------
00222   vtkGetMacro(WriteTime, float);
00223   vtkGetMacro(ReadTime, float);
00224   vtkGetMacro(SendWaitTime, float);
00225   vtkGetMacro(SendTime, float);
00226   vtkGetMacro(ReceiveWaitTime, float);
00227   vtkGetMacro(ReceiveTime, float);
00228 
00229 protected:
00230   vtkMultiProcessController();
00231   ~vtkMultiProcessController();
00232   vtkMultiProcessController(const vtkMultiProcessController&) {};
00233   void operator=(const vtkMultiProcessController&) {};
00234   
00235   int MaximumNumberOfProcesses;
00236   int NumberOfProcesses;
00237   // Since we cannot use this ivar in vtkThreadController subclass,
00238   // maybe we should eliminated it from this superclass.
00239   int LocalProcessId;
00240   
00241   vtkProcessFunctionType      SingleMethod;
00242   void                       *SingleData;
00243   vtkProcessFunctionType      MultipleMethod[VTK_MP_CONTROLLER_MAX_PROCESSES];
00244   void                       *MultipleData[VTK_MP_CONTROLLER_MAX_PROCESSES];  
00245   
00246   vtkCollection *RMIs;
00247   
00248   char *MarshalString;
00249   int MarshalStringLength;
00250   // The data may not take up all of the string.
00251   int MarshalDataLength;
00252   
00253   // This is a flag that can be used by the ports to break
00254   // their update loop. (same as ProcessRMIs)
00255   int BreakFlag;
00256 
00257   // convenience method
00258   void DeleteAndSetMarshalString(char *str, int strLength);
00259   
00260   // Write and read from marshal string
00261   // return 1 success, 0 fail
00262   int WriteObject(vtkDataObject *object);
00263   int ReadObject(vtkDataObject *object);
00264   
00265   int WriteDataSet(vtkDataSet *object);
00266   int ReadDataSet(vtkDataSet *object);
00267 
00268   int WriteImageData(vtkImageData *object);
00269   int ReadImageData(vtkImageData *object);
00270 
00271   void ProcessRMI(int remoteProcessId, void *arg, int argLength, int rmiTag);
00272 
00273   // This method implements "GetGlobalController".  
00274   // It needs to be virtual and static.
00275   virtual vtkMultiProcessController *GetLocalController();
00276   // It has to be set by the subclass (SingleMethodExecute ...), 
00277   // but I do not want to make the global variable visible in the header file.
00278   virtual void SetGlobalController(vtkMultiProcessController *controller);
00279   
00280   float ReadTime;
00281   float WriteTime;
00282 
00283   float SendWaitTime;
00284   float SendTime;
00285   float ReceiveWaitTime;
00286   float ReceiveTime;
00287 
00288   // This flag can force deep copies during send.
00289   int ForceDeepCopy;
00290 };
00291 
00292 
00293 #endif
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 

Generated on Wed Nov 21 12:26:55 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001