OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
GlobalComm.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef GLOBAL_COMM_H
12 #define GLOBAL_COMM_H
13 
14 /*
15  * GlobalComm.h - Global communication functions, such as reduce and scatter.
16  */
17 
18 
19 // forward declarations
20 class Communicate;
21 
22 
23 // Reduce equally-sized arrays across the machine, by sending to node
24 // 0 and broadcasting back the result. The arguments are two begin,end
25 // iterators for the source of the data, an iterator pointing to
26 // where the summed data should go, and an operation to perform in
27 // the reduction. Return success of operation.
28 // The final argument indicates whether the LOCAL NODE should have it's
29 // values included in the reduction (by default, this is true). If this
30 // pointer to the boolean array is null, all the values will be included.
31 // NOTE: The input iterators must iterate over simple data objects,
32 // which do not require their own special getMessage/putMessage. If you
33 // need to reduce a complex quantity, use the scalar version of reduce.
34 template <class InputIterator, class OutputIterator, class ReduceOp>
35 bool reduce(Communicate&, InputIterator, InputIterator, OutputIterator,
36  const ReduceOp&, bool *IncludeVal = 0);
37 
38 // same as above, but this uses the default Communicate object
39 template <class InputIterator, class OutputIterator, class ReduceOp>
40 bool reduce(InputIterator, InputIterator, OutputIterator,
41  const ReduceOp&, bool *IncludeVal = 0);
42 
43 // scalar versions of reduce ... instead of iterators, these versions
44 // expect a single quantity to reduce and a location to place the result.
45 template <class T, class ReduceOp>
46 bool reduce(Communicate& comm, T& input, T& output, const ReduceOp& op);
47 
48 // same as above, but this uses the default Communicate object
49 template <class T, class ReduceOp>
50 bool reduce(T& input, T& output, const ReduceOp& op);
51 
52 
53 // masked scalar versions of reduce ... instead of iterators, these versions
54 // expect a single quantity to reduce and a location to place the result.
55 // The final argument indicates whether the LOCAL NODE should have it's
56 // value included in the reduction (by default, this is true).
57 // Return success of operation.
58 template <class T, class ReduceOp>
59 bool reduce_masked(Communicate& comm, T& input, T& output, const ReduceOp& op,
60  bool IncludeVal);
61 
62 // same as above, but this uses the default Communicate object
63 template <class T, class ReduceOp>
64 bool reduce_masked(T& input, T& output, const ReduceOp& op,
65  bool IncludeVal);
66 
67 
68 // scalar versions of reduce ... instead of iterators, these versions
69 // expect a single quantity to reduce and a location to place the result.
70 template <class T, class ReduceOp>
71 bool reduce(Communicate& comm, T& input, T& output, const ReduceOp& op)
72 {
73  return reduce_masked(comm, input, output, op, true);
74 }
75 
76 // same as above, but this uses the default Communicate object
77 template <class T, class ReduceOp>
78 bool reduce(T& input, T& output, const ReduceOp& op)
79 {
80  return reduce_masked(input, output, op, true);
81 }
82 
83 
84 // Scatter the data in the given source container to all other nodes.
85 // The data is read using the first two begin,end iterators, and written
86 // to the location indicated by the third iterator. The next two
87 // arrays are for target nodes and target indices for the data in the
88 // source array; they should be of the same length as the source array.
89 // The final argument is an STL predicate which is used to combine data
90 // when two or more items are scattered into the same location on the
91 // same node.
92 // Return success of operation.
93 template <class InputIterator, class RandomIterator, class ScatterOp>
94 bool scatter(Communicate&, InputIterator, InputIterator, RandomIterator,
95  int *, int *, const ScatterOp&);
96 
97 // same as above, but this uses the default Communicate object
98 template <class InputIterator, class RandomIterator, class ScatterOp>
99 bool scatter(InputIterator, InputIterator, RandomIterator,
100  int *, int *, const ScatterOp&);
101 
102 
103 
104 /* Gather the data in the given source container from all other nodes to a
105  * specific node (default: 0).
106  */
107 template <typename T>
108 void gather(const T* input, T* output, int count, int root = 0);
109 
110 
111 /* Scatter the data from all other nodes to a
112  * specific node (default: 0).
113  */
114 template <typename T>
115 void scatter(const T* input, T* output, int count, int root = 0);
116 
117 /* Reduce data coming from all nodes to a specific node
118  * (default: 0). Apply certain operation
119  *
120  */
121 template <typename T, class Op>
122 void reduce(const T* input, T* output, int count, Op op, int root = 0);
123 
124 template <typename T, class Op>
125 void new_reduce(const T* input, T* output, int count, Op op, int root = 0);
126 
127 template <typename T, class Op>
128 void new_reduce(T* inout, int count, Op op, int root = 0);
129 
130 template <typename T, class Op>
131 void reduce(const T& input, T& output, int count, Op op, int root = 0);
132 
133 template <typename T, class Op>
134 void allreduce(const T* input, T* output, int count, Op op);
135 
136 template <typename T, class Op>
137 void allreduce(const T& input, T& output, int count, Op op);
138 
139 template <typename T, class Op>
140 void allreduce(T* inout, int count, Op op);
141 
142 template <typename T, class Op>
143 void allreduce(T& inout, int count, Op op);
144 
145 
146 #include "Message/GlobalComm.hpp"
147 
148 #endif // GLOBAL_COMM_H
void allreduce(const T *input, T *output, int count, Op op)
Definition: GlobalComm.hpp:510
bool reduce_masked(Communicate &comm, T &input, T &output, const ReduceOp &op, bool IncludeVal)
Definition: GlobalComm.hpp:208
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
Definition: GlobalComm.hpp:55
bool scatter(Communicate &, InputIterator, InputIterator, RandomIterator, int *, int *, const ScatterOp &)
Definition: GlobalComm.hpp:353
void new_reduce(const T *input, T *output, int count, Op op, int root=0)
Definition: GlobalComm.hpp:477
void gather(const T *input, T *output, int count, int root=0)
Definition: GlobalComm.hpp:449