|
Anasazi Version of the Day
|
00001 #ifndef __TSQR_MpiDatatype_hpp 00002 #define __TSQR_MpiDatatype_hpp 00003 00004 #include <mpi.h> 00005 #include <stdexcept> 00006 00009 00010 namespace TSQR { 00011 namespace MPI { 00012 00015 MPI_Datatype 00016 cloneRawDatatype (MPI_Datatype in, const bool needsFree); 00017 00026 template< class Datum > 00027 class MpiDatatype { 00028 public: 00031 MpiDatatype (); 00032 00035 MpiDatatype (const MpiDatatype& rhs) 00036 { 00037 clone (this->type_, this->needsFree_, rhs); 00038 } 00039 00042 MpiDatatype& operator= (const MpiDatatype& rhs) 00043 { 00044 if (this != &rhs) 00045 { 00046 if (needsFree_) 00047 { 00048 // Return value doesn't matter... 00049 (void) MPI_Type_free (&type_); 00050 needsFree_ = false; 00051 } 00052 clone (this->type_, this->needsFree_, rhs); 00053 } 00054 return *this; 00055 } 00056 00059 ~MpiDatatype () 00060 { 00061 if (needsFree_) 00062 { 00063 // Return value doesn't matter... 00064 (void) MPI_Type_free (&type_); 00065 needsFree_ = false; 00066 } 00067 } 00068 00069 MPI_Datatype get() const { return type_; } 00070 00071 private: 00072 static void 00073 clone (MPI_Datatype& newType, 00074 bool& needsFree, 00075 const MpiDatatype& rhs) 00076 { 00077 newType = cloneRawDatatype (rhs.get(), rhs.needsFree_); 00078 needsFree = rhs.needsFree_; 00079 } 00080 00083 MPI_Datatype type_; 00084 00087 bool needsFree_; 00088 }; 00089 00090 } // namespace MPI 00091 } // namespace TSQR 00092 00093 #endif // __TSQR_MpiDatatype_hpp
1.7.4