Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

dtypes.h

Go to the documentation of this file.
00001 #ifndef __DTYPES_H_
00002 #define __DTYPES_H_
00003 
00004 #include <mpi.h>
00005 #include <complex>
00006 
00018 namespace par {
00019 
00028     template <typename T>
00029     class Mpi_datatype;
00030 
00031 #define HS_MPIDATATYPE(CTYPE, MPITYPE)  \
00032         template <>  \
00033                 class Mpi_datatype<CTYPE> \
00034                 {  \
00035                     public: \
00036                         static MPI_Datatype value() {\
00037                           return MPITYPE;\
00038                         } \
00039                 };
00040 
00041     HS_MPIDATATYPE(short,          MPI_SHORT)
00042     HS_MPIDATATYPE(int,            MPI_INT)
00043     HS_MPIDATATYPE(long,           MPI_LONG)
00044     HS_MPIDATATYPE(unsigned short, MPI_UNSIGNED_SHORT)
00045     HS_MPIDATATYPE(unsigned int,   MPI_UNSIGNED)
00046     HS_MPIDATATYPE(unsigned long,  MPI_UNSIGNED_LONG)
00047     HS_MPIDATATYPE(float,          MPI_FLOAT)
00048     HS_MPIDATATYPE(double,         MPI_DOUBLE)
00049     HS_MPIDATATYPE(long double,    MPI_LONG_DOUBLE)
00050     HS_MPIDATATYPE(long long,    MPI_LONG_LONG_INT)
00051     HS_MPIDATATYPE(char,    MPI_CHAR)
00052     HS_MPIDATATYPE(unsigned char,    MPI_UNSIGNED_CHAR)
00053 
00054     //PetscScalar is simply a typedef for double. Hence no need to explicitly
00055     //define an mpi_datatype for it.
00056 
00057 #undef HS_MPIDATATYPE
00058 
00059     template <typename T>
00060     class Mpi_datatype<std::complex<T> > {
00061     public:
00062         static MPI_Datatype value()
00063         {
00064             static bool         first = true;
00065             static MPI_Datatype datatype;
00066 
00067             if (first) {
00068                 first = false;
00069                 MPI_Type_contiguous(2, Mpi_datatype<T>::value(), &datatype);
00070                 MPI_Type_commit(&datatype);
00071             }
00072 
00073             return datatype;
00074         }
00075     };
00076 
00081     template <>
00082     class Mpi_datatype<bool> {
00083         static void bool_LOR(void *in, void *inout, int* len, MPI_Datatype * dptr) {
00084             for (int i = 0; i < (*len); i++) {
00085                 ((static_cast<bool*>(inout))[i]) =
00086                   ( ((static_cast<bool*>(in))[i]) || 
00087                     ((static_cast<bool*>(inout))[i]) );
00088             }//end for  
00089         }//end function
00090 
00091 
00092         static void bool_LAND(void *in, void *inout, int* len, MPI_Datatype * dptr) {
00093             for (int i = 0; i < (*len); i++) {
00094                 ((static_cast<bool*>(inout))[i]) =
00095                   ( ((static_cast<bool*>(in))[i]) && ((static_cast<bool*>(inout))[i]));
00096             }//end for  
00097         }//end function
00098 
00099     public: 
00104         static MPI_Op LAND() {
00105             static bool         first = true;
00106             static MPI_Op land;
00107             if (first) {
00108                 first = false;
00109                 MPI_Op_create(Mpi_datatype<bool>::bool_LAND ,true ,&land);
00110             }
00111 
00112             return land;
00113         }
00114 
00119         static MPI_Op LOR() {
00120             static bool         first = true;
00121             static MPI_Op lor;
00122             if (first) {
00123                 first = false;
00124                 MPI_Op_create(Mpi_datatype<bool>::bool_LOR ,true ,&lor);
00125             }
00126 
00127             return lor;
00128         }
00129 
00133         static MPI_Datatype value() {
00134             static bool         first = true;
00135             static MPI_Datatype datatype;
00136             if (first) {
00137                 first = false;
00138                 MPI_Type_contiguous(sizeof(bool), MPI_BYTE, &datatype);
00139                 MPI_Type_commit(&datatype);
00140             }
00141             return datatype;
00142         }
00143     };
00144 
00145 } //end namespace
00146 
00147 #endif
00148 

Generated on Tue Mar 24 16:14:03 2009 for DENDRO by  doxygen 1.3.9.1