Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_MpiReductionOpSetter.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_MPI_REDUCTION_OP_SETTER_HPP
11 #define TEUCHOS_MPI_REDUCTION_OP_SETTER_HPP
12 
20 
21 #include <Teuchos_ConfigDefs.hpp>
22 
23 #ifdef HAVE_MPI
24 #include "Teuchos_ReductionOp.hpp"
25 #include <mpi.h>
26 
27 namespace Teuchos {
28 namespace Details {
29 
37 class TEUCHOSCOMM_LIB_DLL_EXPORT MpiReductionOpBase :
38  virtual public Describable {
39 public:
40  virtual void
41  reduce (void* invec, void* inoutvec,
42  int* len, MPI_Datatype* datatype) const = 0;
43 };
44 
51 template<typename OrdinalType>
52 class MpiReductionOp : public MpiReductionOpBase {
53 public:
54  MpiReductionOp (const ValueTypeReductionOp<OrdinalType,char>& reductOp)
55  : reductOp_ (reductOp)
56  {}
57 
58  void
59  reduce (void* invec, void* inoutvec, int* len, MPI_Datatype* datatype) const
60  {
61 #ifdef TEUCHOS_DEBUG
63  TEUCHOS_TEST_FOR_EXCEPT(!datatype);
64 #endif
65  // mfh 23 Nov 2014: Ross made the unfortunate decision initially
66  // to mash everything into MPI_CHAR. This means that we have to
67  // do a lot of type casting here. Of course, most implementations
68  // of ValueTypeReductionOp will immediately cast back from char*
69  // to the actual type of interest.
70  int sz;
71  MPI_Type_size (*datatype, &sz);
72  (void) datatype;
73  reductOp_.reduce ((*len) * sz, reinterpret_cast<char*> (invec),
74  reinterpret_cast<char*> (inoutvec));
75  }
76 
77 private:
78  const ValueTypeReductionOp<OrdinalType, char>& reductOp_;
79  // Not defined and not to be called
80  MpiReductionOp ();
81  MpiReductionOp (const MpiReductionOp&);
82  MpiReductionOp& operator= (const MpiReductionOp&);
83 };
84 
93 TEUCHOSCOMM_LIB_DLL_EXPORT MPI_Op setMpiReductionOp (const MpiReductionOpBase& reductOp);
94 
95 } // namespace Details
96 } // namespace Teuchos
97 
98 #endif // HAVE_MPI
99 
100 #endif // TEUCHOS_MPI_REDUCTION_OP_SETTER_HPP
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...