PlayaMPIDataType.cpp
00001
00002
00003
00004 #include "PlayaMPIDataType.hpp"
00005
00006 #ifdef HAVE_MPI
00007
00008
00009
00010 #include "Teuchos_TypeNameTraits.hpp"
00011 namespace Teuchos
00012 {
00013 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(MPI_Datatype);
00014 }
00015 #endif
00016
00017 namespace Playa
00018 {
00019 using Teuchos::RCP;
00020 using Teuchos::rcp;
00021
00022 MPIDataType::MPIDataType(const std::string& name)
00023 : name_(name)
00024 #ifdef HAVE_MPI
00025 , mpiType_()
00026 #endif
00027 {}
00028
00029 #ifdef HAVE_MPI
00030 MPIDataType::MPIDataType(const std::string& name,
00031 const RCP<MPI_Datatype>& mpiType)
00032 : name_(name), mpiType_(mpiType){}
00033
00034
00035 MPI_Datatype* MPIDataType::ptr()
00036 {
00037 TEUCHOS_TEST_FOR_EXCEPT(mpiType_.get()==0);
00038 return mpiType_.get();
00039 }
00040
00041 const MPI_Datatype& MPIDataType::handle() const
00042 {
00043 TEUCHOS_TEST_FOR_EXCEPT(mpiType_.get()==0);
00044 return *(mpiType_.get());
00045 }
00046 #endif
00047
00048
00049
00050 std::stack<MPIDataType>& MPIDataType::typeRegistry()
00051 {
00052 static std::stack<MPIDataType> rtn;
00053
00054 return rtn;
00055 }
00056
00057 void MPIDataType::clearTypeRegistry()
00058 {
00059 while(!typeRegistry().empty())
00060 {
00061 #ifdef HAVE_MPI
00062
00063
00064
00065 int ierr = MPI_Type_free(typeRegistry().top().ptr());
00066
00067 TEUCHOS_TEST_FOR_EXCEPTION(ierr != 0, std::runtime_error,
00068 "Error code=" << ierr << " detected in MPI_Type_free()");
00069 #endif
00070 typeRegistry().pop();
00071 }
00072 }
00073
00074 void MPIDataType::registerType(const MPIDataType& dataType)
00075 {
00076 typeRegistry().push(dataType);
00077 }
00078
00079 MPIDataType MPIDataType::intType()
00080 {
00081 #ifdef HAVE_MPI
00082 static MPIDataType rtn("MPI int", rcp(new MPI_Datatype(MPI_INT)));
00083 #else
00084 static MPIDataType rtn("MPI int");
00085 #endif
00086 return rtn;
00087 }
00088
00089
00090
00091 MPIDataType MPIDataType::floatType()
00092 {
00093 #ifdef HAVE_MPI
00094 static MPIDataType rtn("MPI float", rcp(new MPI_Datatype(MPI_FLOAT)));
00095 #else
00096 static MPIDataType rtn("MPI float");
00097 #endif
00098 return rtn;
00099 }
00100
00101
00102
00103 MPIDataType MPIDataType::doubleType()
00104 {
00105 #ifdef HAVE_MPI
00106 static MPIDataType rtn("MPI double", rcp(new MPI_Datatype(MPI_DOUBLE)));
00107 #else
00108 static MPIDataType rtn("MPI double");
00109 #endif
00110 return rtn;
00111 }
00112
00113
00114
00115 MPIDataType MPIDataType::doubleIntPairType()
00116 {
00117 #ifdef HAVE_MPI
00118 static MPIDataType rtn("MPI double/int pair", rcp(new MPI_Datatype(MPI_DOUBLE_INT)));
00119 #else
00120 static MPIDataType rtn("MPI double/int pair");
00121 #endif
00122 return rtn;
00123 }
00124
00125
00126
00127
00128 MPIDataType MPIDataType::charType()
00129 {
00130 #ifdef HAVE_MPI
00131 static MPIDataType rtn("MPI char", rcp(new MPI_Datatype(MPI_CHAR)));
00132 #else
00133 static MPIDataType rtn("MPI char");
00134 #endif
00135 return rtn;
00136 }
00137
00138
00139
00140
00141 }
00142