PlayaMPIOp.cpp

00001 // @HEADER
00002 // @HEADER
00003 
00004 #include "PlayaMPIOp.hpp"
00005 
00006 #ifdef HAVE_MPI
00007 // Provide an explicit template specialization for the opaque type MPI_Op
00008 // so that the instantiation of Teuchos::RCP<MPI_Op> objects compiles correctly in debug mode
00009 // without relying on the implementation details of the MPI library.
00010 #include "Teuchos_TypeNameTraits.hpp"
00011 namespace Teuchos
00012 {
00013   TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(MPI_Op);
00014 } // namespace Teuchos
00015 #endif
00016 
00017 namespace Playa
00018 {
00019 using Teuchos::RCP;
00020 using Teuchos::rcp;
00021 
00022 MPIOp::MPIOp(const std::string& name)
00023   : name_(name)
00024 #ifdef HAVE_MPI
00025   , mpiOp_()
00026 #endif
00027 {}
00028 
00029 #ifdef HAVE_MPI
00030 MPIOp::MPIOp(const std::string& name, 
00031   const RCP<MPI_Op>& mpiOp)
00032   : name_(name), mpiOp_(mpiOp){}
00033 
00034 
00035 MPI_Op* MPIOp::ptr() 
00036 {
00037   TEUCHOS_TEST_FOR_EXCEPT(mpiOp_.get()==0);
00038   return mpiOp_.get();
00039 }
00040 
00041 const MPI_Op& MPIOp::handle() const 
00042 {
00043   TEUCHOS_TEST_FOR_EXCEPT(mpiOp_.get()==0);
00044   return *(mpiOp_.get());
00045 }
00046 #endif
00047 
00048 
00049 
00050 std::stack<MPIOp>& MPIOp::opRegistry()
00051 {
00052   static std::stack<MPIOp> rtn;
00053 
00054   return rtn;
00055 }
00056 
00057 void MPIOp::clearOpRegistry()
00058 {
00059   while(!opRegistry().empty())
00060   {
00061 #ifdef HAVE_MPI
00062     MPIOp t = opRegistry().top();
00063 
00064     int ierr = MPI_Op_free(t.ptr());
00065 
00066     TEUCHOS_TEST_FOR_EXCEPTION(ierr != 0, std::runtime_error,
00067       "Error code=" << ierr << " detected in MPI_Type_free()");
00068 #endif
00069     opRegistry().pop();
00070   }
00071 }
00072 
00073 void MPIOp::registerOp(const MPIOp& opType)
00074 {
00075   opRegistry().push(opType);
00076 }
00077 
00078 
00079 MPIOp MPIOp::sumOp()
00080 {
00081 #ifdef HAVE_MPI
00082   static MPIOp rtn("MPI sum", rcp(new MPI_Op(MPI_SUM)));
00083 #else
00084   static MPIOp rtn("MPI sum");
00085 #endif
00086   return rtn;
00087 }
00088 
00089 
00090 MPIOp MPIOp::minOp()
00091 {
00092 #ifdef HAVE_MPI
00093   static MPIOp rtn("MPI min", rcp(new MPI_Op(MPI_MIN)));
00094 #else
00095   static MPIOp rtn("MPI min");
00096 #endif
00097   return rtn;
00098 }
00099 
00100 MPIOp MPIOp::maxOp()
00101 {
00102 #ifdef HAVE_MPI
00103   static MPIOp rtn("MPI max", rcp(new MPI_Op(MPI_MAX)));
00104 #else
00105   static MPIOp rtn("MPI max");
00106 #endif
00107   return rtn;
00108 }
00109 
00110 MPIOp MPIOp::minlocOp()
00111 {
00112 #ifdef HAVE_MPI
00113   static MPIOp rtn("MPI minloc", rcp(new MPI_Op(MPI_MINLOC)));
00114 #else
00115   static MPIOp rtn("MPI minloc");
00116 #endif
00117   return rtn;
00118 }
00119 
00120 MPIOp MPIOp::maxlocOp()
00121 {
00122 #ifdef HAVE_MPI
00123   static MPIOp rtn("MPI maxloc", rcp(new MPI_Op(MPI_MAXLOC)));
00124 #else
00125   static MPIOp rtn("MPI maxloc");
00126 #endif
00127   return rtn;
00128 }
00129 
00130 MPIOp MPIOp::productOp()
00131 {
00132 #ifdef HAVE_MPI
00133   static MPIOp rtn("MPI prod", rcp(new MPI_Op(MPI_PROD)));
00134 #else
00135   static MPIOp rtn("MPI prod");
00136 #endif
00137   return rtn;
00138 }
00139 
00140 
00141   
00142 } // namespace Playa
00143 

doxygen