Commit a4bddfff authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Added definition of ValueType to expression templates

parent d97cea88
Loading
Loading
Loading
Loading
+0 −45
Original line number Diff line number Diff line
#include <iostream>
#include <functional>
#include <TNL/Containers/Array.h>
#include <TNL/Containers/ArrayView.h>

using namespace TNL;

template< typename Device >
void reduceElementsExample()
{
   /****
    * Create new arrays
    */
   const int size = 10;
   Containers::Array< float, Device > a( size );
   auto a_view = a.getView();

   /****
    * Initiate the elements of array `a`
    */
   a_view.forAllElements( [] __cuda_callable__ ( int i, float& value ) { value = i; } );

   /****
    * Sum all elements of array `a`
    */
   auto fetch = [=] __cuda_callable__ ( int i, float& value ) { return value; };
   auto sum = a_view.reduceEachElement( fetch, std::plus<>{}, 0.0 );

   /****
    * Print the results
    */
   std::cout << " a = " << a << std::endl;
   std::cout << " sum = " << sum << std::endl;
}

int main( int argc, char* argv[] )
{
   std::cout << "Running example on the host system: " << std::endl;
   reduceElementsExample< Devices::Host >();

#ifdef HAVE_CUDA
   std::cout << "Running example on the CUDA device: " << std::endl;
   reduceElementsExample< Devices::Cuda >();
#endif
}
+0 −1
Original line number Diff line number Diff line
ArrayViewExample_reduceElements.cpp
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ template< typename T1,
struct DistributedBinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariable, VectorExpressionVariable >
{
   using RealType = decltype( Operation::evaluate( std::declval<T1>()[0], std::declval<T2>()[0] ) );
   using ValueType = RealType;
   using DeviceType = typename T1::DeviceType;
   using IndexType = typename T1::IndexType;
   using LocalRangeType = typename T1::LocalRangeType;
@@ -155,6 +156,7 @@ template< typename T1,
struct DistributedBinaryExpressionTemplate< T1, T2, Operation, VectorExpressionVariable, ArithmeticVariable >
{
   using RealType = decltype( Operation::evaluate( std::declval<T1>()[0], std::declval<T2>() ) );
   using ValueType = RealType;
   using DeviceType = typename T1::DeviceType;
   using IndexType = typename T1::IndexType;
   using LocalRangeType = typename T1::LocalRangeType;
@@ -236,6 +238,7 @@ template< typename T1,
struct DistributedBinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariable, VectorExpressionVariable >
{
   using RealType = decltype( Operation::evaluate( std::declval<T1>(), std::declval<T2>()[0] ) );
   using ValueType = RealType;
   using DeviceType = typename T2::DeviceType;
   using IndexType = typename T2::IndexType;
   using LocalRangeType = typename T2::LocalRangeType;
@@ -318,6 +321,7 @@ template< typename T1,
struct DistributedUnaryExpressionTemplate
{
   using RealType = decltype( Operation::evaluate( std::declval<T1>()[0] ) );
   using ValueType = RealType;
   using DeviceType = typename T1::DeviceType;
   using IndexType = typename T1::IndexType;
   using LocalRangeType = typename T1::LocalRangeType;
Loading