33 #ifndef _OPERATIONS_H_
34 #define _OPERATIONS_H_
45 struct myset:
public std::unary_function<T, T>
47 myset(T myvalue): value(myvalue) {};
49 const T& operator()(
const T& x)
const
57 struct identity :
public std::unary_function<T, T>
60 const T operator()(
const T& x)
const
72 const T operator()(
const T& x)
const
80 struct totality :
public std::unary_function<T, bool>
83 bool operator()(
const T& x)
const
93 const T operator()(
const T& x)
const
95 T inf = std::numeric_limits<T>::max();
96 return (x == 0) ? inf:(1/x);
101 template<
typename T1,
typename T2>
105 bool operator()(
const T1& x,
const T2 & y)
const
119 struct exponentiate :
public std::binary_function<double, double, double>
121 double operator()(
double x,
double y)
const {
return std::pow(x, y); }
133 struct maximum :
public std::binary_function<T, T, T>
136 const T operator()(
const T& x,
const T& y)
const
151 struct minimum :
public std::binary_function<T, T, T>
154 const T operator()(
const T& x,
const T& y)
const
171 T operator()(
const T& x,
const T& y)
const
189 T operator()(
const T& x,
const T& y)
const
206 T operator()(
const T& x,
const T& y)
const
208 return (x || y) && !(x && y);
224 T operator()(
const T& x,
const T& y)
const
236 template <
typename Op,
typename T>
241 template<
typename T>
struct MPIOp<
maximum<T>, T > {
static MPI_Op
op() {
return MPI_MAX; } };
242 template<
typename T>
struct MPIOp<
minimum<T>, T > {
static MPI_Op
op() {
return MPI_MIN; } };
243 template<
typename T>
struct MPIOp< std::plus<T>, T > {
static MPI_Op
op() {
return MPI_SUM; } };
244 template<
typename T>
struct MPIOp< std::multiplies<T>, T > {
static MPI_Op
op() {
return MPI_PROD; } };
245 template<
typename T>
struct MPIOp< std::logical_and<T>, T > {
static MPI_Op
op() {
return MPI_LAND; } };
246 template<
typename T>
struct MPIOp< std::logical_or<T>, T > {
static MPI_Op
op() {
return MPI_LOR; } };
249 template<
typename T>
struct MPIOp<
bitwise_or<T>, T > {
static MPI_Op
op() {
return MPI_BOR; } };