vtf-logo

ELComm.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__elc_ELComm_h__)
00009 #define __elc_ELComm_h__
00010 
00011 // If we are debugging the whole elc package.
00012 #if defined(DEBUG_elc) && !defined(DEBUG_ELComm)
00013 #define DEBUG_ELComm
00014 #endif
00015 
00016 #include "defs.h"
00017 
00018 #include "../ads/array/Array.h"
00019 #include "../geom/kernel/BBox.h"
00020 
00021 #include <mpi.h>
00022 
00023 BEGIN_NAMESPACE_ELC
00024 
00026 enum VertexIdentifierStyle {LocalIndices, GlobalIdentifiers};
00027 
00029 
00035 template <int N, typename T>
00036 class ELComm {
00037   //
00038   // Protected types.
00039   //
00040 
00041 protected:
00042 
00044   typedef T Number;
00046   typedef ads::FixedArray<N,Number> Point;
00048   typedef geom::BBox<N,Number> BBox;
00049 #ifdef ELC_USE_CPP_INTERFACE
00051   typedef MPI::Request MpiRequest;
00053   typedef MPI::Status MpiStatus;
00054 #else
00056   typedef MPI_Request MpiRequest;
00058   typedef MPI_Status MpiStatus;
00059 #endif
00060 
00061   //
00062   // Enumerations.
00063   //
00064 
00065 protected:
00066 
00068   enum {TagIdentifiers,
00069         TagPositions,
00070         TagVelocities,
00071         TagPressures,
00072         TagFaceData};
00073 
00074   //
00075   // Member data.
00076   //
00077 
00078 protected:
00079 
00081 #ifdef ELC_USE_CPP_INTERFACE
00082   MPI::Intracomm _comm;
00083 #else
00084   MPI_Comm _comm;
00085 #endif
00086 
00087 #ifdef ELC_USE_CPP_INTERFACE
00089   MPI::Datatype _mpiNumber;
00090 #else
00092   MPI_Datatype _mpiNumber;
00093 #endif
00094 
00096   VertexIdentifierStyle _vertexIdentifierStyle;
00097   
00098   //
00099   // Not implemented.
00100   //
00101 
00102 private:
00103 
00104   // Default constructor not implemented.
00105   ELComm();
00106 
00107   // Copy constructor not implemented.
00108   ELComm(const ELComm&);
00109 
00110   // Assignment operator not implemented.
00111   ELComm&
00112   operator=(const ELComm&);
00113 
00114 public:
00115 
00116   //--------------------------------------------------------------------------
00118   // @{
00119 
00121 #ifdef ELC_USE_CPP_INTERFACE
00122   ELComm(const MPI::Intracomm& comm, 
00123          VertexIdentifierStyle vertexIdentifierStyle) :
00124     _comm(comm.Dup()),
00125     _vertexIdentifierStyle(vertexIdentifierStyle) {
00126     if (sizeof(Number) == sizeof(float)) {
00127       _mpiNumber = MPI::FLOAT;
00128     }
00129     else if (sizeof(Number) == sizeof(double)) {
00130       _mpiNumber = MPI::DOUBLE;
00131     }
00132     else if (sizeof(Number) == sizeof(long double)) {
00133       _mpiNumber = MPI::LONG_DOUBLE;
00134     }
00135     else {
00136       assert(false);
00137     }
00138   }
00139 #else
00140   ELComm(const MPI_Comm comm, 
00141          VertexIdentifierStyle vertexIdentifierStyle) :
00142     _comm(),
00143     _vertexIdentifierStyle(vertexIdentifierStyle) {
00144     MPI_Comm_dup(comm, &_comm);
00145 
00146     if (sizeof(Number) == sizeof(float)) {
00147       _mpiNumber = MPI_FLOAT;
00148     }
00149     else if (sizeof(Number) == sizeof(double)) {
00150       _mpiNumber = MPI_DOUBLE;
00151     }
00152     else if (sizeof(Number) == sizeof(long double)) {
00153       _mpiNumber = MPI_LONG_DOUBLE;
00154     }
00155     else {
00156       assert(false);
00157     }
00158   }
00159 #endif
00160 
00162   virtual
00163   ~ELComm() {
00164 #ifdef ELC_USE_CPP_INTERFACE
00165     _comm.Barrier();
00166     _comm.Free();
00167 #else
00168     MPI_Barrier(_comm);
00169     MPI_Comm_free(&_comm);
00170 #endif
00171   }
00172 
00173   // @}
00174 };
00175 
00176 END_NAMESPACE_ELC
00177 
00178 #endif

Generated on Fri Aug 24 12:55:45 2007 for Eulerian-Lagrangian Coupling by  doxygen 1.4.7