casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PTransport.h
Go to the documentation of this file.
00001 //# PTransport.h: Base class for parallel data transport models
00002 //# Copyright (C) 1998,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id$
00028 
00029 #ifndef SYNTHESIS_PTRANSPORT_H
00030 #define SYNTHESIS_PTRANSPORT_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Arrays/Array.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class Algorithm;
00040 class Record;
00041 
00042 // <summary>
00043 // Base class for parallel data transport models
00044 // </summary>
00045 
00046 // <use visibility=local>   or   <use visibility=export>
00047 
00048 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //   <li> SomeClass
00053 //   <li> SomeOtherClass
00054 //   <li> some concept
00055 // </prerequisite>
00056 //
00057 // <etymology>
00058 // </etymology>
00059 //
00060 // <synopsis>
00061 // </synopsis>
00062 //
00063 // <example>
00064 // </example>
00065 //
00066 // <motivation>
00067 // </motivation>
00068 //
00069 //
00070 //# <todo asof="yyyy/mm/dd">
00071 //#   <li> add this feature
00072 //#   <li> fix this bug
00073 //#   <li> start discussion of this possible extension
00074 //# </todo>
00075 
00076 
00077 class PTransport {
00078  public:
00079   // Default constructor and destructor
00080   PTransport() : numprocs(0), myCpu(0), aWorker(0), aTag(0) {};
00081   virtual ~PTransport() {}
00082 
00083   // Return the number of processes
00084   Int numThreads() {return numprocs;};
00085 
00086   // Return the current process rank
00087   Int cpu() {return myCpu;}
00088 
00089   // Set the properties of the current connection including
00090   // source/destination and message tag.
00091   Int connect(Int i) {aWorker=i; return i;}
00092   void connectAnySource() {aWorker=anySource(); return;};
00093   void connectToController() {aWorker=controllerRank(); return;};
00094   void setTag(Int tag) {aTag=tag; return;};
00095   void setAnyTag() {aTag=anyTag(); return;};
00096   
00097   // Status functions for worker/controller designation
00098   Bool isController() {return (cpu()==controllerRank());};
00099   Bool isWorker() {return (cpu()!=controllerRank());};
00100   
00101   // Default source and message tag values
00102   virtual Int anyTag() = 0;
00103   virtual Int anySource() = 0;
00104   
00105   // Define the rank of the controller process
00106   virtual Int controllerRank() = 0;
00107   
00108   // Get and put functions on the parallel data transport layer
00109   virtual Int put(const Array<Float> &) = 0;
00110   virtual Int put(const Array<Double> &) = 0;
00111   virtual Int put(const Array<Complex> &) = 0;
00112   virtual Int put(const Array<DComplex> &) = 0;
00113   virtual Int put(const Array<Int> &) = 0;
00114   virtual Int put(const Float &) = 0;
00115   virtual Int put(const Double &) = 0;
00116   virtual Int put(const Complex &) = 0;
00117   virtual Int put(const DComplex &) = 0;
00118   virtual Int put(const Int &) = 0;
00119   virtual Int put(const String &) = 0;
00120   virtual Int put(const Bool &) = 0;
00121   virtual Int put(const Record &) = 0;
00122 
00123   virtual Int get(Array<Float> &) = 0;
00124   virtual Int get(Array<Double> &) = 0;
00125   virtual Int get(Array<Complex> &) = 0;
00126   virtual Int get(Array<DComplex> &) = 0;
00127   virtual Int get(Array<Int> &) = 0;
00128   virtual Int get(Float &) = 0;
00129   virtual Int get(Double &) = 0;
00130   virtual Int get(Complex &) = 0;
00131   virtual Int get(DComplex &) = 0;
00132   virtual Int get(Int &) = 0;
00133   virtual Int get(String &) = 0;
00134   virtual Int get(Bool &) = 0;
00135   virtual Int get(Record &) = 0;
00136   
00137  protected: 
00138   // Number of processes
00139   Int numprocs;
00140   
00141   // Rank of current process
00142   Int myCpu;
00143    
00144   // Current source or destination process
00145   Int aWorker;
00146 
00147   // Current message tag
00148   Int aTag;
00149 };
00150 
00151 // Putting in the MPI Transport stuff only makes sense if we have MPI
00152 
00153 #ifdef HasMPI
00154 // <summary>
00155 // MPI data transport models
00156 // </summary>
00157 
00158 // <use visibility=local>
00159 
00160 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00161 // </reviewed>
00162 
00163 // <prerequisite>
00164 //   <li> SomeClass
00165 //   <li> SomeOtherClass
00166 //   <li> some concept
00167 // </prerequisite>
00168 //
00169 // <etymology>
00170 // </etymology>
00171 //
00172 // <synopsis>
00173 // </synopsis>
00174 //
00175 // <example>
00176 // </example>
00177 //
00178 // <motivation>
00179 // </motivation>
00180 //
00181 //
00182 //# <todo asof="yyyy/mm/dd">
00183 //#   <li> add this feature
00184 //#   <li> fix this bug
00185 //#   <li> start discussion of this possible extension
00186 //# </todo>
00187 
00188 class MPITransport : public PTransport {
00189  public:
00190   // Default constructor and destructor
00191   MPITransport();
00192   virtual ~MPITransport();
00193 
00194   // Construct from argv
00195   MPITransport(Int, Char *argv[]);
00196 
00197   // Default source and message tag values
00198   virtual Int anyTag();
00199   virtual Int anySource();
00200   
00201   // Define the rank of the controller process
00202   virtual Int controllerRank() {return 0;};
00203   
00204   // Get and put functions on the parallel data transport layer
00205   virtual Int put(const Array<Float> &);
00206   virtual Int put(const Array<Double> &);
00207   virtual Int put(const Array<Complex> &);
00208   virtual Int put(const Array<DComplex> &);
00209   virtual Int put(const Array<Int> &);
00210   virtual Int put(const Float &);
00211   virtual Int put(const Double &);
00212   virtual Int put(const Complex &);
00213   virtual Int put(const DComplex &);
00214   virtual Int put(const Int &);
00215   virtual Int put(const String &);
00216   virtual Int put(const Bool &);
00217   virtual Int put(const Record &);
00218 
00219   virtual Int get(Array<Float> &);
00220   virtual Int get(Array<Double> &);
00221   virtual Int get(Array<Complex> &);
00222   virtual Int get(Array<DComplex> &);
00223   virtual Int get(Array<Int> &);
00224   virtual Int get(Float &);
00225   virtual Int get(Double &);
00226   virtual Int get(Complex &);
00227   virtual Int get(DComplex &);
00228   virtual Int get(Int &);
00229   virtual Int get(String &);
00230   virtual Int get(Bool &);
00231   virtual Int get(Record &);
00232 
00233  private:
00234   // Local work variables
00235   Int sendTo, myOp, getFrom;
00236 
00237   // Utility functions to set default source/destination and tag values
00238   void setSourceAndTag (Int &source, Int &tag);
00239   void setDestAndTag (Int &dest, Int &tag);
00240 };
00241 #endif
00242 
00243 // <summary>
00244 // Serial Data Transport Model
00245 // </summary>
00246 
00247 // <use visibility=local>
00248 
00249 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00250 // </reviewed>
00251 
00252 // <prerequisite>
00253 //   <li> SomeClass
00254 //   <li> SomeOtherClass
00255 //   <li> some concept
00256 // </prerequisite>
00257 //
00258 // <etymology>
00259 // </etymology>
00260 //
00261 // <synopsis>
00262 // </synopsis>
00263 //
00264 // <example>
00265 // </example>
00266 //
00267 // <motivation>
00268 // </motivation>
00269 //
00270 //
00271 //# <todo asof="yyyy/mm/dd">
00272 //#   <li> add this feature
00273 //#   <li> fix this bug
00274 //#   <li> start discussion of this possible extension
00275 //# </todo>
00276 
00277 // SerialTransport is your basic no-op.  We're just passing the pointers
00278 // to avoid unnecessary data copying.
00279 
00280 class SerialTransport : public PTransport {
00281  public:
00282   // Default constructor and destructor
00283   SerialTransport() : PTransport(), inQue(0), outQue(0), lastInQue(0)
00284     {_data.resize(20);}
00285   virtual ~SerialTransport(){}
00286 
00287   // Default source and message tag values
00288   virtual Int anyTag() {return -1;};
00289   virtual Int anySource() {return -1;};
00290   
00291   // Define the rank of the controller process
00292   virtual Int controllerRank() {return 0;};
00293 
00294   // Get and put functions on the data transport layer
00295   virtual Int put(const Array<Float> &);
00296   virtual Int put(const Array<Double> &);
00297   virtual Int put(const Array<Complex> &);
00298   virtual Int put(const Array<DComplex> &);
00299   virtual Int put(const Array<Int> &);
00300   virtual Int put(const Float &);
00301   virtual Int put(const Double &);
00302   virtual Int put(const Complex &);
00303   virtual Int put(const DComplex &);
00304   virtual Int put(const Int &);
00305   virtual Int put(const String &);
00306   virtual Int put(const Bool &);
00307   virtual Int put(const Record &);
00308 
00309   virtual Int get(Array<Float> &);
00310   virtual Int get(Array<Double> &);
00311   virtual Int get(Array<Complex> &);
00312   virtual Int get(Array<DComplex> &);
00313   virtual Int get(Array<Int> &);
00314   virtual Int get(Float &);
00315   virtual Int get(Double &);
00316   virtual Int get(Complex &);
00317   virtual Int get(DComplex &);
00318   virtual Int get(Int &);
00319   virtual Int get(String &);
00320   virtual Int get(Bool &);
00321   virtual Int get(Record &);
00322 
00323  private:
00324   uInt inQue;
00325   uInt outQue;
00326   uInt lastInQue;
00327   PtrBlock<void *> _data;
00328   
00329   Int add2Queue(void *);
00330   void *getFromQueue();
00331 };
00332 
00333 
00334 } //# NAMESPACE CASA - END
00335 
00336 #endif
00337 
00338