G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsBinaryFunctions.h
Go to the documentation of this file.
1
18#pragma once
19
20// #include <functional>
21// #include <algorithm>
22
23namespace gismo
24{
25template<typename Type>
26struct Min
27 : std::binary_function<Type,Type,Type>
28{
29 Type operator()(const Type& t1, const Type& t2) const
30 {
31 return std::min(t1,t2);
32 }
33};
34
35template<typename Type>
36struct Max
37 : std::binary_function<Type,Type,Type>
38{
39 Type operator()(const Type& t1, const Type& t2) const
40 {
41 return std::max(t1,t2);
42 }
43};
44
45
46
47template<typename Type, typename BinaryFunction>
48class Generic_MPI_Op
49{
50
51public:
52 static MPI_Op get ()
53 {
54 if (!op) // if op is null then create new op
55 {
56 op = memory::shared_ptr<MPI_Op>(new MPI_Op);
57 MPI_Op_create((void (*)(void*, void*, int*, MPI_Datatype*))&operation,true,op.get());
58 }
59 return *op;
60 }
61private:
62 static void operation (Type *in, Type *inout, int *len, MPI_Datatype*)
63 {
64 BinaryFunction func;
65
66 for (int i=0; i< *len; ++i, ++in, ++inout) {
67 Type temp;
68 temp = func(*in, *inout);
69 *inout = temp;
70 }
71 }
72 Generic_MPI_Op () {}
73 Generic_MPI_Op (const Generic_MPI_Op& ) {}
74 static memory::shared_ptr<MPI_Op> op; // to check: can do with static MPI_Op ?
75};
76
77
78template<typename Type, typename BinaryFunction>
79memory::shared_ptr<MPI_Op> Generic_MPI_Op<Type,BinaryFunction>::op = memory::shared_ptr<MPI_Op>(static_cast<MPI_Op*>(0));
80
81#define ComposeMPIOp(type,func,op) \
82 template<> \
83 class Generic_MPI_Op<type, func<type> >{ \
84 public: \
85 static MPI_Op get(){ \
86 return op; \
87 } \
88 private: \
89 Generic_MPI_Op () {} \
90 Generic_MPI_Op (const Generic_MPI_Op & ) {} \
91 }
92
93
94ComposeMPIOp(char, std::plus, MPI_SUM);
95ComposeMPIOp(unsigned char, std::plus, MPI_SUM);
96ComposeMPIOp(short, std::plus, MPI_SUM);
97ComposeMPIOp(unsigned short, std::plus, MPI_SUM);
98ComposeMPIOp(int, std::plus, MPI_SUM);
99ComposeMPIOp(unsigned int, std::plus, MPI_SUM);
100ComposeMPIOp(long, std::plus, MPI_SUM);
101ComposeMPIOp(unsigned long, std::plus, MPI_SUM);
102ComposeMPIOp(float, std::plus, MPI_SUM);
103ComposeMPIOp(double, std::plus, MPI_SUM);
104ComposeMPIOp(long double, std::plus, MPI_SUM);
105
106ComposeMPIOp(char, std::multiplies, MPI_PROD);
107ComposeMPIOp(unsigned char, std::multiplies, MPI_PROD);
108ComposeMPIOp(short, std::multiplies, MPI_PROD);
109ComposeMPIOp(unsigned short, std::multiplies, MPI_PROD);
110ComposeMPIOp(int, std::multiplies, MPI_PROD);
111ComposeMPIOp(unsigned int, std::multiplies, MPI_PROD);
112ComposeMPIOp(long, std::multiplies, MPI_PROD);
113ComposeMPIOp(unsigned long, std::multiplies, MPI_PROD);
114ComposeMPIOp(float, std::multiplies, MPI_PROD);
115ComposeMPIOp(double, std::multiplies, MPI_PROD);
116ComposeMPIOp(long double, std::multiplies, MPI_PROD);
117
118ComposeMPIOp(char, Min, MPI_MIN);
119ComposeMPIOp(unsigned char, Min, MPI_MIN);
120ComposeMPIOp(short, Min, MPI_MIN);
121ComposeMPIOp(unsigned short, Min, MPI_MIN);
122ComposeMPIOp(int, Min, MPI_MIN);
123ComposeMPIOp(unsigned int, Min, MPI_MIN);
124ComposeMPIOp(long, Min, MPI_MIN);
125ComposeMPIOp(unsigned long, Min, MPI_MIN);
126ComposeMPIOp(float, Min, MPI_MIN);
127ComposeMPIOp(double, Min, MPI_MIN);
128ComposeMPIOp(long double, Min, MPI_MIN);
129
130ComposeMPIOp(char, Max, MPI_MAX);
131ComposeMPIOp(unsigned char, Max, MPI_MAX);
132ComposeMPIOp(short, Max, MPI_MAX);
133ComposeMPIOp(unsigned short, Max, MPI_MAX);
134ComposeMPIOp(int, Max, MPI_MAX);
135ComposeMPIOp(unsigned int, Max, MPI_MAX);
136ComposeMPIOp(long, Max, MPI_MAX);
137ComposeMPIOp(unsigned long, Max, MPI_MAX);
138ComposeMPIOp(float, Max, MPI_MAX);
139ComposeMPIOp(double, Max, MPI_MAX);
140ComposeMPIOp(long double, Max, MPI_MAX);
141
142#undef ComposeMPIOp
143
144
145}
The G+Smo namespace, containing all definitions for the library.