From 6eb4798451ffdf9d69d7101f2f77a307e92e3e9c Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Tue, 19 Nov 2019 16:32:12 +0100 Subject: [PATCH] Writing documentation for StaticFor. --- src/TNL/Algorithms/StaticFor.h | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/TNL/Algorithms/StaticFor.h b/src/TNL/Algorithms/StaticFor.h index c740454584..e9bcb43e2c 100644 --- a/src/TNL/Algorithms/StaticFor.h +++ b/src/TNL/Algorithms/StaticFor.h @@ -15,10 +15,28 @@ namespace TNL { namespace Algorithms { -// Manual unrolling does not make sense for loops with a large iterations -// count. For a very large iterations count it would trigger the compiler's -// limit on recursive template instantiation. Also note that the compiler -// will (at least partially) unroll loops with static bounds anyway. +/*** + * \brief StaticFor is a wrapper for common for-loop with explicit unrolling. + * + * StaticFor can be used only for for-loops bounds of which are known at the + * compile time. StaticFor performs explicit loop unrolling for better performance. + * This, however, does not make sense for loops with a large iterations + * count. For a very large iterations count it could trigger the compiler's + * limit on recursive template instantiation. Also note that the compiler + * will (at least partially) unroll loops with static bounds anyway. For theses + * reasons, the explicit loop unrolling can be controlled by the third template + * parameter. + * + * \tparam Begin the loop will iterate over indexes [Begin,End) + * \tparam End the loop will iterate over indexes [Begin,End) + * \tparam unrolled controls the explicit loop unrolling. If it is true, the + * unrolling is performed. + * + * \par Example + * \include Algorithms/StaticForExample.cpp + * \par Output + * \include StaticForExample.out + */ template< int Begin, int End, bool unrolled = (End - Begin <= 8) > struct StaticFor; @@ -27,6 +45,12 @@ struct StaticFor< Begin, End, true > { static_assert( Begin < End, "Wrong index interval for StaticFor. Begin must be less than end." ); + /** + * \brief Static method for execution od the StaticFor. + * + * @param f is a (lambda) function to be performed in each iteration. + * @param args are auxiliary data to be passed to the function f. + */ template< typename Function, typename... Args > __cuda_callable__ static void exec( const Function& f, Args&&... args ) -- GitLab