Computes segmented scan (prefix sum) sequentially.
The reduction lambda function takes two variables which are supposed to be reduced:
#include <iostream>
#include <TNL/Containers/Array.h>
#include <TNL/Algorithms/SegmentedScan.h>
template< typename Device >
void
{
{
return a + b;
};
}
int
main( int argc, char* argv[] )
{
Array< bool, Devices::Host > host_flags{ 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0 };
Array< double, Devices::Host > host_v{ 1, 3, 5, 2, 4, 6, 9, 3, 5, 3, 6, 9, 12, 15 };
segmentedScan( host_v, host_flags );
std::cout <<
"The segmented prefix sum of the host array is " << host_v <<
"." <<
std::endl;
#ifdef __CUDACC__
#endif
return EXIT_SUCCESS;
}
Array is responsible for memory management, access to array elements, and general array operations.
Definition Array.h:64
__cuda_callable__ IndexType getSize() const
Returns the current array size.
Definition Array.hpp:245
Namespace for fundamental TNL algorithms.
Definition AtomicOperations.h:9
Result reduce(Index begin, Index end, Fetch &&fetch, Reduction &&reduction, const Result &identity)
reduce implements (parallel) reduction for vectors and arrays.
Definition reduce.h:65
Namespace for TNL containers.
Definition Array.h:17
The main TNL namespace.
Definition AtomicOperations.h:9
Computes segmented scan (or prefix sum) on a vector.
Definition SegmentedScan.h:56
host_flags = [ 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0 ]
host_v = [ 1, 3, 5, 2, 4, 6, 9, 3, 5, 3, 6, 9, 12, 15 ]
The segmented prefix sum of the host array is [ 1, 4, 9, 2, 6, 12, 21, 3, 8, 3, 9, 18, 30, 45 ].