Teuchos_MpiReductionOpSetter.cpp
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 #include "Teuchos_MpiReductionOpSetter.hpp"
00030 #include "Teuchos_OpaqueWrapper.hpp"
00031 #include "Teuchos_GlobalMPISession.hpp"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 extern "C" {
00044
00045 void Teuchos_MPI_reduction_op(
00046 void *invec
00047 ,void *inoutvec
00048 ,int *len
00049 ,MPI_Datatype *datatype
00050 );
00051
00052 void Teuchos_MPI_Op_free( MPI_Op *op )
00053 {
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 }
00069
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 namespace {
00079
00080 Teuchos::RCP<const Teuchos::MpiReductionOpBase> the_reduct_op = Teuchos::null;
00081
00082 Teuchos::RCP<const Teuchos::OpaqueWrapper<MPI_Op> > the_mpi_op = Teuchos::null;
00083
00084 Teuchos::RCP<const Teuchos::MpiReductionOpBase> get_reduct_op()
00085 {
00086 return the_reduct_op;
00087 }
00088
00089 void set_reduct_op( const Teuchos::RCP<const Teuchos::MpiReductionOpBase>& reduct_op )
00090 {
00091 using Teuchos::null;
00092 #ifdef TEUCHOS_DEBUG
00093 TEST_FOR_EXCEPT( get_reduct_op() != null && reduct_op != null );
00094 #endif
00095 if(!the_mpi_op.get()) {
00096 MPI_Op mpi_op = MPI_OP_NULL;
00097 TEST_FOR_EXCEPT(
00098 0!=MPI_Op_create( &Teuchos_MPI_reduction_op ,1 ,&mpi_op )
00099 );
00100 the_mpi_op = Teuchos::opaqueWrapper(mpi_op,Teuchos_MPI_Op_free);
00101 }
00102 the_reduct_op = reduct_op;
00103 }
00104
00105 }
00106
00107 extern "C" {
00108
00109 void Teuchos_MPI_reduction_op(
00110 void *invec
00111 ,void *inoutvec
00112 ,int *len
00113 ,MPI_Datatype *datatype
00114 )
00115 {
00116 get_reduct_op()->reduce(invec,inoutvec,len,datatype);
00117 }
00118
00119 }
00120
00121 namespace Teuchos {
00122
00123 MpiReductionOpSetter::MpiReductionOpSetter(
00124 const Teuchos::RCP<const MpiReductionOpBase>& reduct_op
00125 )
00126 {
00127 #ifdef TEUCHOS_DEBUG
00128 TEST_FOR_EXCEPT(!reduct_op.get())
00129 #endif
00130 set_reduct_op(reduct_op);
00131 }
00132
00133 MpiReductionOpSetter::~MpiReductionOpSetter()
00134 {
00135 set_reduct_op( null );
00136 }
00137
00138 MPI_Op MpiReductionOpSetter::mpi_op() const
00139 {
00140 return (*the_mpi_op)();
00141 }
00142
00143 }