40 #include <ginkgo/ginkgo.hpp> 42 #include <collective_common.hpp> 47 template <
typename ValueType,
typename IndexType>
48 extern void gather_add_values(
const IndexType num_elems,
49 const IndexType *indices,
50 const ValueType *from_array,
51 ValueType *into_array);
53 template <
typename ValueType,
typename IndexType>
54 extern void gather_diff_values(
const IndexType num_elems,
55 const IndexType *indices,
56 const ValueType *from_array,
57 ValueType *into_array);
59 template <
typename ValueType,
typename IndexType>
60 extern void gather_avg_values(
const IndexType num_elems,
61 const IndexType *indices,
62 const ValueType *from_array,
63 ValueType *into_array);
65 template <
typename ValueType,
typename IndexType>
66 extern void gather_values(
const IndexType num_elems,
const IndexType *indices,
67 const ValueType *from_array, ValueType *into_array);
70 template <
typename ValueType,
typename IndexType>
71 struct Gather :
public gko::Operation {
72 Gather(
const IndexType num_elems,
const IndexType *indices,
73 const ValueType *from_array, ValueType *into_array,
75 : num_elems{num_elems},
77 from_array{from_array},
78 into_array{into_array},
82 void run(std::shared_ptr<const gko::OmpExecutor>)
const override 86 #pragma omp parallel for 87 for (
auto i = 0; i < num_elems; ++i) {
88 into_array[i] = from_array[indices[i]];
92 #pragma omp parallel for 93 for (
auto i = 0; i < num_elems; ++i) {
94 into_array[i] = from_array[indices[i]] + into_array[i];
98 #pragma omp parallel for 99 for (
auto i = 0; i < num_elems; ++i) {
100 into_array[i] = from_array[indices[i]] - into_array[i];
104 #pragma omp parallel for 105 for (
auto i = 0; i < num_elems; ++i) {
106 into_array[i] = (from_array[indices[i]] + into_array[i]) / 2;
110 std::cout <<
"Undefined gather operation" << std::endl;
116 void run(std::shared_ptr<const gko::CudaExecutor>)
const override 120 gather_values(num_elems, indices, from_array, into_array);
123 gather_add_values(num_elems, indices, from_array, into_array);
126 gather_diff_values(num_elems, indices, from_array, into_array);
129 gather_avg_values(num_elems, indices, from_array, into_array);
132 std::cout <<
"Undefined gather operation" << std::endl;
137 const IndexType num_elems;
138 const IndexType *indices;
139 const ValueType *from_array;
140 ValueType *into_array;
141 OperationType optype;
145 #define INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \ 146 template _macro(float, gko::int32); \ 147 template _macro(double, gko::int32); \ 148 template _macro(float, gko::int64); \ 149 template _macro(double, gko::int64); 151 #define DECLARE_GATHER(ValueType, IndexType) struct Gather<ValueType, IndexType> 152 INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(DECLARE_GATHER);
153 #undef DECLARE_GATHER Definition: gather.hpp:71
The Schwarz wrappers namespace.
Definition: comm_helpers.hpp:49