From 6514e4815f635e1dbc8b53fe2c8f9eda98f8e001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkovsky@mmg.fjfi.cvut.cz> Date: Sat, 16 Oct 2021 09:24:32 +0200 Subject: [PATCH] Simplified lambda function and local variables in ArrayView::forElements --- src/TNL/Containers/ArrayView.hpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/TNL/Containers/ArrayView.hpp b/src/TNL/Containers/ArrayView.hpp index 8ca4176050..cd0a4c537b 100644 --- a/src/TNL/Containers/ArrayView.hpp +++ b/src/TNL/Containers/ArrayView.hpp @@ -347,15 +347,11 @@ forElements( IndexType begin, IndexType end, Function&& f ) if( ! this->data ) return; - ValueType* data = this->getData(); - const IndexType size = this->getSize(); - auto g = [=] __cuda_callable__ ( IndexType i ) mutable + auto g = [] __cuda_callable__ ( IndexType i, Function f, ArrayView view ) { - TNL_ASSERT_GE( i, 0, "Element index must be non-negative." ); - TNL_ASSERT_LT( i, size, "Element index is out of bounds." ); - f( i, data[ i ] ); + f( i, view[ i ] ); }; - Algorithms::ParallelFor< DeviceType >::exec( begin, end, g ); + Algorithms::ParallelFor< DeviceType >::exec( begin, end, g, f, *this ); } template< typename Value, @@ -369,15 +365,11 @@ forElements( IndexType begin, IndexType end, Function&& f ) const if( ! this->data ) return; - const ValueType* data = this->getData(); - const IndexType size = this->getSize(); - auto g = [=] __cuda_callable__ ( IndexType i ) + auto g = [] __cuda_callable__ ( IndexType i, Function f, ArrayView view ) { - TNL_ASSERT_GE( i, 0, "Element index must be non-negative." ); - TNL_ASSERT_LT( i, size, "Element index is out of bounds." ); - f( i, data[ i ] ); + f( i, view[ i ] ); }; - Algorithms::ParallelFor< DeviceType >::exec( begin, end, g ); + Algorithms::ParallelFor< DeviceType >::exec( begin, end, g, f, *this ); } template< typename Value, -- GitLab