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 "PlayaMPIOp.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_Op);
00054 #endif
00055 }
00056 #endif
00057
00058 namespace Playa
00059 {
00060 using Teuchos::RCP;
00061 using Teuchos::rcp;
00062
00063 MPIOp::MPIOp(const std::string& name)
00064 : name_(name)
00065 #ifdef HAVE_MPI
00066 , mpiOp_()
00067 #endif
00068 {}
00069
00070 #ifdef HAVE_MPI
00071 MPIOp::MPIOp(const std::string& name,
00072 const RCP<MPI_Op>& mpiOp)
00073 : name_(name), mpiOp_(mpiOp){}
00074
00075
00076 MPI_Op* MPIOp::ptr()
00077 {
00078 TEUCHOS_TEST_FOR_EXCEPT(mpiOp_.get()==0);
00079 return mpiOp_.get();
00080 }
00081
00082 const MPI_Op& MPIOp::handle() const
00083 {
00084 TEUCHOS_TEST_FOR_EXCEPT(mpiOp_.get()==0);
00085 return *(mpiOp_.get());
00086 }
00087 #endif
00088
00089
00090
00091 std::stack<MPIOp>& MPIOp::opRegistry()
00092 {
00093 static std::stack<MPIOp> rtn;
00094
00095 return rtn;
00096 }
00097
00098 void MPIOp::clearOpRegistry()
00099 {
00100 while(!opRegistry().empty())
00101 {
00102 #ifdef HAVE_MPI
00103 MPIOp t = opRegistry().top();
00104
00105 int ierr = MPI_Op_free(t.ptr());
00106
00107 TEUCHOS_TEST_FOR_EXCEPTION(ierr != 0, std::runtime_error,
00108 "Error code=" << ierr << " detected in MPI_Type_free()");
00109 #endif
00110 opRegistry().pop();
00111 }
00112 }
00113
00114 void MPIOp::registerOp(const MPIOp& opType)
00115 {
00116 opRegistry().push(opType);
00117 }
00118
00119
00120 MPIOp MPIOp::sumOp()
00121 {
00122 #ifdef HAVE_MPI
00123 static MPIOp rtn("MPI sum", rcp(new MPI_Op(MPI_SUM)));
00124 #else
00125 static MPIOp rtn("MPI sum");
00126 #endif
00127 return rtn;
00128 }
00129
00130
00131 MPIOp MPIOp::minOp()
00132 {
00133 #ifdef HAVE_MPI
00134 static MPIOp rtn("MPI min", rcp(new MPI_Op(MPI_MIN)));
00135 #else
00136 static MPIOp rtn("MPI min");
00137 #endif
00138 return rtn;
00139 }
00140
00141 MPIOp MPIOp::maxOp()
00142 {
00143 #ifdef HAVE_MPI
00144 static MPIOp rtn("MPI max", rcp(new MPI_Op(MPI_MAX)));
00145 #else
00146 static MPIOp rtn("MPI max");
00147 #endif
00148 return rtn;
00149 }
00150
00151 MPIOp MPIOp::minlocOp()
00152 {
00153 #ifdef HAVE_MPI
00154 static MPIOp rtn("MPI minloc", rcp(new MPI_Op(MPI_MINLOC)));
00155 #else
00156 static MPIOp rtn("MPI minloc");
00157 #endif
00158 return rtn;
00159 }
00160
00161 MPIOp MPIOp::maxlocOp()
00162 {
00163 #ifdef HAVE_MPI
00164 static MPIOp rtn("MPI maxloc", rcp(new MPI_Op(MPI_MAXLOC)));
00165 #else
00166 static MPIOp rtn("MPI maxloc");
00167 #endif
00168 return rtn;
00169 }
00170
00171 MPIOp MPIOp::productOp()
00172 {
00173 #ifdef HAVE_MPI
00174 static MPIOp rtn("MPI prod", rcp(new MPI_Op(MPI_PROD)));
00175 #else
00176 static MPIOp rtn("MPI prod");
00177 #endif
00178 return rtn;
00179 }
00180
00181
00182
00183 }
00184