From 2b44995c07226199292c26f23313605ad56f5735 Mon Sep 17 00:00:00 2001 From: Victoriya Fedotova Date: Thu, 19 Sep 2024 04:28:35 -0700 Subject: [PATCH] 'Lambda function' term was changed to more generic and appropriate 'Callable object' term --- cpp/daal/src/threading/threading.h | 212 ++++++++++++++--------------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/cpp/daal/src/threading/threading.h b/cpp/daal/src/threading/threading.h index b83564f25c1..832b1ef8c13 100644 --- a/cpp/daal/src/threading/threading.h +++ b/cpp/daal/src/threading/threading.h @@ -198,29 +198,29 @@ inline size_t setNumberOfThreads(const size_t numThreads, void ** globalControl) template inline void threader_func(int i, const void * a) { - const F & lambda = *static_cast(a); - lambda(i); + const F & func = *static_cast(a); + func(i); } template inline void static_threader_func(size_t i, size_t tid, const void * a) { - const F & lambda = *static_cast(a); - lambda(i, tid); + const F & func = *static_cast(a); + func(i, tid); } template inline void threader_func_b(int i0, int in, const void * a) { - const F & lambda = *static_cast(a); - lambda(i0, in); + const F & func = *static_cast(a); + func(i0, in); } template inline void threader_func_break(int i, bool & needBreak, const void * a) { - const F & lambda = *static_cast(a); - lambda(i, needBreak); + const F & func = *static_cast(a); + func(i, needBreak); } /// Pass a function to be executed in a for loop to the threading layer. @@ -230,16 +230,16 @@ inline void threader_func_break(int i, bool & needBreak, const void * a) /// Data dependencies between the iterations are allowed, but may requre the use /// of synchronization primitives. /// -/// @tparam F Lambda function of type `[/* captures */](int i) -> void`, +/// @tparam F Callable object of type `[/* captures */](int i) -> void`, /// where `i` is the loop's iteration index, `0 <= i < n`. /// /// @param[in] n Number of iterations in the for loop. /// @param[in] reserved Parameter reserved for the future. Currently unused. -/// @param[in] lambda Lambda function that defines the loop body. +/// @param[in] func Callable object that defines the loop body. template -inline void threader_for(int n, int reserved, const F & lambda) +inline void threader_for(int n, int reserved, const F & callable) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&callable); _daal_threader_for(n, reserved, a, threader_func); } @@ -252,15 +252,15 @@ inline void threader_for(int n, int reserved, const F & lambda) /// Data dependencies between the iterations are allowed, but may requre the use /// of synchronization primitives. /// -/// @tparam F Lambda function of type `[/* captures */](int64_t i) -> void`, +/// @tparam F Callable object of type `[/* captures */](int64_t i) -> void`, /// where `i` is the loop's iteration index, `0 <= i < n`. /// /// @param[in] n Number of iterations in the for loop. -/// @param[in] lambda Lambda function that defines the loop body. +/// @param[in] func Callable object that defines the loop body. template -inline void threader_for_int64(int64_t n, const F & lambda) +inline void threader_for_int64(int64_t n, const F & func) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&func); _daal_threader_for_int64(n, a, threader_func); } @@ -279,24 +279,24 @@ inline void threader_for_int64(int64_t n, const F & lambda) /// Data dependencies between the iterations are allowed, but may requre the use /// of synchronization primitives. /// -/// @tparam F Lambda function of type `[/* captures */](int i) -> void`, +/// @tparam F Callable object of type `[/* captures */](int i) -> void`, /// where `i` is the loop's iteration index, `0 <= i < n`. /// /// @param[in] n Number of iterations in the for loop. /// @param[in] reserved Parameter reserved for the future. Currently unused. -/// @param[in] lambda Lambda function that defines iteration's body. +/// @param[in] func Callable object that defines iteration's body. template -inline void threader_for_simple(int n, int reserved, const F & lambda) +inline void threader_for_simple(int n, int reserved, const F & func) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&func); _daal_threader_for_simple(n, reserved, a, threader_func); } template -inline void threader_for_int32ptr(const int * begin, const int * end, const F & lambda) +inline void threader_for_int32ptr(const int * begin, const int * end, const F & func) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&func); _daal_threader_for_int32ptr(begin, end, a, threader_func); } @@ -321,17 +321,17 @@ inline void threader_for_int32ptr(const int * begin, const int * end, const F & /// ... /// the `t`-th thread executes iterations `(t - 1) * nI, ..., n - 1`. /// -/// @tparam F Lambda function of type `[/* captures */](size_t i, size_t tid) -> void`, +/// @tparam F Callable object of type `[/* captures */](size_t i, size_t tid) -> void`, /// where /// `i` is the loop's iteration index, `0 <= i < n`; /// `tid` is the index of the thread, `0 <= tid < t`. /// /// @param[in] n Number of iterations in the for loop. -/// @param[in] lambda Lambda function that defines iteration's body. +/// @param[in] func Callable object that defines iteration's body. template -inline void static_threader_for(size_t n, const F & lambda) +inline void static_threader_for(size_t n, const F & func) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&func); _daal_static_threader_for(n, a, static_threader_func); } @@ -341,7 +341,7 @@ inline void static_threader_for(size_t n, const F & lambda) /// The default scheduling of the threading layer is used to assign /// the iterations of the loop to threads. /// -/// @tparam F Lambda function of type `[/* captures */](int beginRange, int endRange) -> void` +/// @tparam F Callable object of type `[/* captures */](int beginRange, int endRange) -> void` /// where /// `beginRange` is the starting index of the loop iterations block to be /// processed by a thread, `0 <= beginRange < n`; @@ -350,44 +350,44 @@ inline void static_threader_for(size_t n, const F & lambda) /// /// @param[in] n Number of iterations in the for loop. /// @param[in] reserved Parameter reserved for the future. Currently unused. -/// @param[in] lambda Lambda function that processes the block of loop's iterations +/// @param[in] func Callable object that processes the block of loop's iterations /// `[beginRange, endRange)`. template -inline void threader_for_blocked(int n, int reserved, const F & lambda) +inline void threader_for_blocked(int n, int reserved, const F & func) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&func); _daal_threader_for_blocked(n, reserved, a, threader_func_b); } template -inline void threader_for_optional(int n, int threads_request, const F & lambda) +inline void threader_for_optional(int n, int threads_request, const F & func) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&func); _daal_threader_for_optional(n, threads_request, a, threader_func); } template -inline void threader_for_break(int n, int threads_request, const F & lambda) +inline void threader_for_break(int n, int threads_request, const F & func) { - const void * a = static_cast(&lambda); + const void * a = static_cast(&func); _daal_threader_for_break(n, threads_request, a, threader_func_break); } -template +template inline void * tls_func(const void * a) { - const lambdaType & lambda = *static_cast(a); - return lambda(); + const callableType & func = *static_cast(a); + return func(); } -template +template inline void tls_reduce_func(void * v, const void * a) { - const lambdaType & lambda = *static_cast(a); - lambda((F)v); + const callableType & func = *static_cast(a); + func((F)v); } struct tlsBase @@ -402,12 +402,12 @@ class tls_deleter : public tlsBase virtual void del(void * a) = 0; }; -template +template class tls_deleter_ : public tls_deleter { public: virtual ~tls_deleter_() {} - virtual void del(void * a) { delete static_cast(a); } + virtual void del(void * a) { delete static_cast(a); } }; /// Thread-local storage (TLS). @@ -423,26 +423,26 @@ class tls : public tlsBase public: /// Initialize thread-local storage /// - /// @tparam lambdaType Lambda function of type `[/* captures */]() -> F` + /// @tparam callableType Callable object of type `[/* captures */]() -> F` /// - /// @param lambda Lambda function that initializes a thread-local storage - template - explicit tls(const lambdaType & lambda) + /// @param func Callable object that initializes a thread-local storage + template + explicit tls(const callableType & func) { - lambdaType * locall = new lambdaType(lambda); - d = new tls_deleter_(); + callableType * localfunc = new callableType(func); + d = new tls_deleter_(); - //const void* ac = static_cast(&lambda); - const void * ac = static_cast(locall); + //const void* ac = static_cast(&func); + const void * ac = static_cast(localfunc); void * a = const_cast(ac); voidLambda = a; - tlsPtr = _daal_get_tls_ptr(a, tls_func); + tlsPtr = _daal_get_tls_ptr(a, tls_func); } /// Destroys the memory associated with a thread-local storage /// - /// @note TLS does not release the memory allocated by a lambda-function + /// @note TLS does not release the memory allocated by a callable object /// provided to the constructor. /// Developers are responsible for deletion of that memory. virtual ~tls() @@ -454,7 +454,7 @@ class tls : public tlsBase /// Access a local data of a thread by value /// - /// @return When first invoked by a thread, a lambda provided to the constructor is + /// @return When first invoked by a thread, a callable object provided to the constructor is /// called to initialize the local data of the thread and return it. /// All the following invocations just return the same thread-local data. F local() @@ -465,30 +465,30 @@ class tls : public tlsBase /// Sequential reduction. /// - /// @tparam lambdaType Lambda function of type `[/* captures */](F) -> void` + /// @tparam callableType Callable object of type `[/* captures */](F) -> void` /// - /// @param lambda Lambda function that is applied to each element of thread-local - /// storage sequentially. - template - void reduce(const lambdaType & lambda) + /// @param func Callable object that is applied to each element of thread-local + /// storage sequentially. + template + void reduce(const callableType & func) { - const void * ac = static_cast(&lambda); + const void * ac = static_cast(&func); void * a = const_cast(ac); - _daal_reduce_tls(tlsPtr, a, tls_reduce_func); + _daal_reduce_tls(tlsPtr, a, tls_reduce_func); } /// Parallel reduction. /// - /// @tparam lambdaType Lambda function of type `[/* captures */](F) -> void` + /// @tparam callableType Callable object of type `[/* captures */](F) -> void` /// - /// @param lambda Lambda function that is applied to each element of thread-local - /// storage in parallel. - template - void parallel_reduce(const lambdaType & lambda) + /// @param func Callable object that is applied to each element of thread-local + /// storage in parallel. + template + void parallel_reduce(const callableType & func) { - const void * ac = static_cast(&lambda); + const void * ac = static_cast(&func); void * a = const_cast(ac); - _daal_parallel_reduce_tls(tlsPtr, a, tls_reduce_func); + _daal_parallel_reduce_tls(tlsPtr, a, tls_reduce_func); } private: @@ -497,11 +497,11 @@ class tls : public tlsBase tls_deleter * d; }; -template +template inline void * creater_func(const void * a) { - const lambdaType & lambda = *static_cast(a); - return lambda(); + const callableType & func = *static_cast(a); + return func(); } class static_tls_deleter @@ -511,12 +511,12 @@ class static_tls_deleter virtual void del(void * a) = 0; }; -template +template class static_tls_deleter_ : public static_tls_deleter { public: virtual ~static_tls_deleter_() {} - virtual void del(void * a) { delete static_cast(a); } + virtual void del(void * a) { delete static_cast(a); } }; /// Thread-local storage (TLS) for the case of static parallel work scheduling. @@ -528,11 +528,11 @@ class static_tls public: /// Initialize thread-local storage. /// - /// @tparam lambdaType Lambda function of type `[/* captures */]() -> F` + /// @tparam callableType Callable object of type `[/* captures */]() -> F` /// - /// @param lambda Lambda function that initializes a thread-local storage - template - explicit static_tls(const lambdaType & lambda) + /// @param func Callable object that initializes a thread-local storage + template + explicit static_tls(const callableType & func) { _nThreads = threader_get_max_threads_number(); @@ -548,8 +548,8 @@ class static_tls _storage[i] = nullptr; } - lambdaType * locall = new lambdaType(lambda); - _deleter = new static_tls_deleter_(); + callableType * locall = new callableType(func); + _deleter = new static_tls_deleter_(); if (!locall || !_deleter) { return; @@ -559,12 +559,12 @@ class static_tls void * a = const_cast(ac); _creater = a; - _creater_func = creater_func; + _creater_func = creater_func; } /// Destroys the memory associated with a thread-local storage. /// - /// @note Static TLS does not release the memory allocated by a lambda-function + /// @note Static TLS does not release the memory allocated by a callable object /// provided to the constructor. /// Developers are responsible for deletion of that memory. virtual ~static_tls() @@ -581,7 +581,7 @@ class static_tls /// /// @param tid Index of the thread. /// - /// @return When first invoked by a thread, a lambda provided to the constructor is + /// @return When first invoked by a thread, a callable object provided to the constructor is /// called to initialize the local data of the thread and return it. /// All the following invocations just return the same thread-local data. F local(size_t tid) @@ -603,18 +603,18 @@ class static_tls /// Sequential reduction. /// - /// @tparam lambdaType Lambda function of type `[/* captures */](F) -> void` + /// @tparam callableType Callable object of type `[/* captures */](F) -> void` /// - /// @param lambda Lambda function that is applied to each element of thread-local - /// storage sequentially. - template - void reduce(const lambdaType & lambda) + /// @param func Callable object that is applied to each element of thread-local + /// storage sequentially. + template + void reduce(const callableType & func) { if (_storage) { for (size_t i = 0; i < _nThreads; ++i) { - if (_storage[i]) lambda(_storage[i]); + if (_storage[i]) func(_storage[i]); } } } @@ -644,29 +644,29 @@ class ls : public tlsBase public: /// Initialize local storage. /// - /// @tparam lambdaType Lambda function of type `[/* captures */]() -> F` + /// @tparam callableType Callable object of type `[/* captures */]() -> F` /// - /// @param lambda Lambda function that initializes local storage + /// @param func Callable object that initializes local storage /// @param isTls if `true`, then local storage is a thread-local storage (`daal::tls`) /// and might have problems in case of nested parallel regions. - template - explicit ls(const lambdaType & lambda, const bool isTls = false) + template + explicit ls(const callableType & func, const bool isTls = false) { - _isTls = isTls; - lambdaType * locall = new lambdaType(lambda); - d = new tls_deleter_(); + _isTls = isTls; + callableType * localfunc = new callableType(func); + d = new tls_deleter_(); - //const void* ac = static_cast(&lambda); - const void * ac = static_cast(locall); + //const void* ac = static_cast(&func); + const void * ac = static_cast(localfunc); void * a = const_cast(ac); voidLambda = a; - lsPtr = _isTls ? _daal_get_tls_ptr(a, tls_func) : _daal_get_ls_ptr(a, tls_func); + lsPtr = _isTls ? _daal_get_tls_ptr(a, tls_func) : _daal_get_ls_ptr(a, tls_func); } /// Destroys the memory associated with local storage. /// - /// @note `ls` does not release the memory allocated by a lambda-function + /// @note `ls` does not release the memory allocated by a callable object /// provided to the constructor. /// Developers are responsible for deletion of that memory. virtual ~ls() @@ -678,7 +678,7 @@ class ls : public tlsBase /// Access the local data of a thread by value. /// - /// @return When first invoked by a thread, a lambda provided to the constructor is + /// @return When first invoked by a thread, a callable object provided to the constructor is /// called to initialize the local data of the thread and return it. /// All the following invocations just return the same thread-local data. F local() @@ -694,16 +694,16 @@ class ls : public tlsBase /// Sequential reduction. /// - /// @tparam lambdaType Lambda function of type `[/* captures */](F) -> void` + /// @tparam callableType Callable object of type `[/* captures */](F) -> void` /// - /// @param lambda Lambda function that is applied to each element of thread-local - /// storage sequentially. - template - void reduce(const lambdaType & lambda) + /// @param func Callable object that is applied to each element of thread-local + /// storage sequentially. + template + void reduce(const callableType & func) { - const void * ac = static_cast(&lambda); + const void * ac = static_cast(&func); void * a = const_cast(ac); - _isTls ? _daal_reduce_tls(lsPtr, a, tls_reduce_func) : _daal_reduce_ls(lsPtr, a, tls_reduce_func); + _isTls ? _daal_reduce_tls(lsPtr, a, tls_reduce_func) : _daal_reduce_ls(lsPtr, a, tls_reduce_func); } private: