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