Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Tsqr_MpiDatatype.hpp
00001 #ifndef __TSQR_MpiDatatype_hpp
00002 #define __TSQR_MpiDatatype_hpp
00003 
00004 #include <Teuchos_ConfigDefs.hpp> // HAVE_MPI
00005 
00006 #ifdef HAVE_MPI
00007 #  include <mpi.h>
00008 #  include <stdexcept>
00009 
00012 
00013 namespace TSQR {
00014   namespace MPI {
00015 
00018     MPI_Datatype 
00019     cloneRawDatatype (MPI_Datatype in, const bool needsFree);
00020 
00029     template< class Datum >
00030     class MpiDatatype {
00031     public:
00034       MpiDatatype ();
00035 
00038       MpiDatatype (const MpiDatatype& rhs) 
00039       {
00040   clone (this->type_, this->needsFree_, rhs);
00041       }
00042 
00045       MpiDatatype& operator= (const MpiDatatype& rhs)
00046       {
00047   if (this != &rhs)
00048     {
00049       if (needsFree_)
00050         {
00051     // Return value doesn't matter...
00052     (void) MPI_Type_free (&type_);
00053     needsFree_ = false;
00054         }
00055       clone (this->type_, this->needsFree_, rhs);
00056     }
00057   return *this;
00058       }
00059 
00062       ~MpiDatatype () 
00063       { 
00064   if (needsFree_)
00065     {
00066       // Return value doesn't matter...
00067       (void) MPI_Type_free (&type_);
00068       needsFree_ = false;
00069     }
00070       }
00071 
00072       MPI_Datatype get() const { return type_; }
00073 
00074     private:
00075       static void 
00076       clone (MPI_Datatype& newType, 
00077        bool& needsFree,
00078        const MpiDatatype& rhs)
00079       {
00080   newType = cloneRawDatatype (rhs.get(), rhs.needsFree_);
00081   needsFree = rhs.needsFree_;
00082       }
00083 
00086       MPI_Datatype type_;
00087 
00090       bool needsFree_;
00091     };
00092 
00093   } // namespace MPI
00094 } // namespace TSQR
00095 
00096 
00097 #endif // HAVE_MPI
00098 #endif // __TSQR_MpiDatatype_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends