Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Morpheus_Scan.hpp
1
24#ifndef MORPHEUS_SCAN_HPP
25#define MORPHEUS_SCAN_HPP
26
27#include <impl/Morpheus_Scan_Impl.hpp>
28
29namespace Morpheus {
30
31/*
32 * Computes an inclusive prefix sum operation. The term 'inclusive'
33 * means that each result includes the corresponding input operand
34 * in the partial sum. When the input and output sequences are the
35 * same, the scan is performed in-place.
36 *
37 * \code
38 * #include <Morpheus_Core.hpp>
39 *
40 * using vec = Morpheus::DenseVector<int, int, Kokkos::HostSpace>;
41 * using serial = Kokkos::Serial;
42 *
43 * typename vec::index_type N = 10;
44 * vec in(N, 1), out(N, 0);
45 *
46 * Morpheus::inclusive_scan<serial>(in, out, N);
47 *
48 * // out is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
49 * \endcode
50 *
51 */
52template <typename ExecSpace, typename Vector>
53void inclusive_scan(const Vector& in, Vector& out,
54 typename Vector::index_type size,
55 typename Vector::index_type start = 0) {
56 Impl::inclusive_scan<ExecSpace>(in, out, size, start);
57}
58
59/*
60 * Computes an exclusive prefix sum operation. The term 'exclusive' means
61 * that each result does not include the corresponding input operand in the
62 * partial sum. More precisely, 0 is assigned to out[0] and the sum of
63 * 0 and in[0] is assigned to out[1], and so on. When the input and output
64 * sequences are the same, the scan is performed in-place.
65 *
66 * \code
67 * #include <Morpheus_Core.hpp>
68 *
69 * using vec = Morpheus::DenseVector<int, int, Kokkos::HostSpace>;
70 * using serial = Kokkos::Serial;
71 *
72 * typename vec::index_type N = 10;
73 * vec in(N, 1), out(N, 0);
74 *
75 * Morpheus::exclusive_scan<serial>(in, out, N);
76 *
77 * // out is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
78 * \endcode
79 *
80 */
81template <typename ExecSpace, typename Vector>
82void exclusive_scan(const Vector& in, Vector& out,
83 typename Vector::index_type size,
84 typename Vector::index_type start = 0) {
85 Impl::exclusive_scan<ExecSpace>(in, out, size, start);
86}
87
88/*
89 * Computes an inclusive key-value or 'segmented' prefix sum operation.
90 * The term 'inclusive' means that each result includes the corresponding
91 * input operand in the partial sum. The term 'segmented' means that the
92 * partial sums are broken into distinct segments. In other words, within
93 * each segment a separate inclusive scan operation is computed.
94 *
95 * \code
96 * #include <Morpheus_Core.hpp>
97 *
98 * using vec = Morpheus::DenseVector<int, int, Kokkos::HostSpace>;
99 * using serial = Kokkos::Serial;
100 *
101 * typename vec::index_type N = 10;
102 * vec in(N, 1), out(N, 0), keys(N);
103 *
104 * keys[0] = 0; keys[1] = 0; keys[2] = 0;
105 * keys[3] = 1; keys[4] = 1;
106 * keys[5] = 2;
107 * keys[6] = 3; keys[7] = 3; keys[8] = 3; keys[9] = 3;
108 *
109 * Morpheus::inclusive_scan_by_key<serial>(keys, in, out, N);
110 *
111 * // out is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4};
112 * \endcode
113 *
114 */
115template <typename ExecSpace, typename Vector1, typename Vector2>
116void inclusive_scan_by_key(const Vector1& keys, const Vector2& in, Vector2& out,
117 typename Vector2::index_type size,
118 typename Vector2::index_type start = 0) {
119 Impl::inclusive_scan_by_key<ExecSpace>(keys, in, out, size, start);
120}
121
122/*
123 * \p Computes an exclusive key-value or 'segmented' prefix sum operation. The
124 * term 'exclusive' means that each result does not include the corresponding
125 * input operand in the partial sum. The term 'segmented' means that the partial
126 * sums are broken into distinct segments. In other words, within each segment a
127 * separate exclusive scan operation is computed. The following code snippet
128 * demonstrates how to use \p exclusive_scan_by_key.
129 *
130 * \code
131 * #include <Morpheus_Core.hpp>
132 *
133 * using vec = Morpheus::DenseVector<int, int, Kokkos::HostSpace>;
134 * using serial = Kokkos::Serial;
135 *
136 * typename vec::index_type N = 10;
137 * vec in(N, 1), out(N, 0), keys(N);
138 *
139 * keys[0] = 0; keys[1] = 0; keys[2] = 0;
140 * keys[3] = 1; keys[4] = 1;
141 * keys[5] = 2;
142 * keys[6] = 3; keys[7] = 3; keys[8] = 3; keys[9] = 3;
143 *
144 * Morpheus::exclusive_scan_by_key<serial>(keys, in, out, N);
145 *
146 * // out is now {0, 1, 2, 0, 1, 0, 0, 1, 2, 3};
147 * \endcode
148 *
149 */
150template <typename ExecSpace, typename Vector1, typename Vector2>
151void exclusive_scan_by_key(const Vector1& keys, const Vector2& in, Vector2& out,
152 typename Vector2::index_type size,
153 typename Vector2::index_type start = 0) {
154 Impl::exclusive_scan_by_key<ExecSpace>(keys, in, out, size, start);
155}
156
157} // namespace Morpheus
158
159#endif // MORPHEUS_SCAN_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24