diff --git a/dlib/threads/parallel_for_extension.h b/dlib/threads/parallel_for_extension.h index 311267029..60b64b1b4 100644 --- a/dlib/threads/parallel_for_extension.h +++ b/dlib/threads/parallel_for_extension.h @@ -6,6 +6,7 @@ #include "parallel_for_extension_abstract.h" #include "thread_pool_extension.h" #include "../console_progress_indicator.h" +#include "async.h" namespace dlib { @@ -186,6 +187,17 @@ namespace dlib parallel_for_blocked(tp, begin, end, funct, chunks_per_thread); } + template + void parallel_for_blocked ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ) + { + parallel_for_blocked(default_thread_pool(), begin, end, funct, chunks_per_thread); + } + // ---------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- @@ -285,6 +297,19 @@ namespace dlib parallel_for(tp, begin, end, funct, chunks_per_thread); } +// ---------------------------------------------------------------------------------------- + + template + void parallel_for ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ) + { + parallel_for(default_thread_pool(), begin, end, funct, chunks_per_thread); + } + // ---------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- @@ -499,6 +524,29 @@ namespace dlib parallel_for(num_threads, begin, end, helper, chunks_per_thread); } +// ---------------------------------------------------------------------------------------- + + template + void parallel_for_verbose ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ) + { + // make sure requires clause is not broken + DLIB_ASSERT(begin <= end && chunks_per_thread > 0, + "\t void parallel_for_verbose()" + << "\n\t Invalid inputs were given to this function" + << "\n\t begin: " << begin + << "\n\t end: " << end + << "\n\t chunks_per_thread: " << chunks_per_thread + ); + + impl::parfor_verbose_helper2 helper(funct, begin, end); + parallel_for(begin, end, helper, chunks_per_thread); + } + // ---------------------------------------------------------------------------------------- template @@ -597,6 +645,29 @@ namespace dlib parallel_for_blocked(num_threads, begin, end, helper, chunks_per_thread); } +// ---------------------------------------------------------------------------------------- + + template + void parallel_for_blocked_verbose ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ) + { + // make sure requires clause is not broken + DLIB_ASSERT(begin <= end && chunks_per_thread > 0, + "\t void parallel_for_blocked_verbose()" + << "\n\t Invalid inputs were given to this function" + << "\n\t begin: " << begin + << "\n\t end: " << end + << "\n\t chunks_per_thread: " << chunks_per_thread + ); + + impl::parfor_verbose_helper2 helper(funct, begin, end); + parallel_for_blocked(begin, end, helper, chunks_per_thread); + } + // ---------------------------------------------------------------------------------------- } diff --git a/dlib/threads/parallel_for_extension_abstract.h b/dlib/threads/parallel_for_extension_abstract.h index 9c3959081..fd6f4645f 100644 --- a/dlib/threads/parallel_for_extension_abstract.h +++ b/dlib/threads/parallel_for_extension_abstract.h @@ -4,6 +4,7 @@ #ifdef DLIB_PARALLEL_FoR_ABSTRACT_Hh_ #include "thread_pool_extension_abstract.h" +#include "async_abstract.h" namespace dlib { @@ -123,6 +124,25 @@ namespace dlib parallel_for_blocked(tp, begin, end, funct, chunks_per_thread); !*/ +// ---------------------------------------------------------------------------------------- + + template + void parallel_for_blocked ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ); + /*! + requires + - begin <= end + - chunks_per_thread > 0 + - funct does not throw any exceptions + ensures + - This function is equivalent to the following block of code: + parallel_for_blocked(default_thread_pool(), begin, end, funct, chunks_per_thread); + !*/ + // ---------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- @@ -225,6 +245,25 @@ namespace dlib parallel_for(tp, begin, end, funct, chunks_per_thread); !*/ +// ---------------------------------------------------------------------------------------- + + template + void parallel_for ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ); + /*! + requires + - begin <= end + - chunks_per_thread > 0 + - funct does not throw any exceptions + ensures + - This function is equivalent to the following block of code: + parallel_for(default_thread_pool(), begin, end, funct, chunks_per_thread); + !*/ + // ---------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- @@ -312,6 +351,27 @@ namespace dlib parallel for loop. !*/ +// ---------------------------------------------------------------------------------------- + + template + void parallel_for_verbose ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ); + /*! + requires + - begin <= end + - chunks_per_thread > 0 + - funct does not throw any exceptions + ensures + - This function is identical to the parallel_for() routine defined above except + that it will print messages to cout showing the progress in executing the + parallel for loop. + - It will also use the default_thread_pool(). + !*/ + // ---------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------- @@ -399,6 +459,27 @@ namespace dlib executing the parallel for loop. !*/ +// ---------------------------------------------------------------------------------------- + + template + void parallel_for_blocked_verbose ( + long begin, + long end, + const T& funct, + long chunks_per_thread = 8 + ); + /*! + requires + - begin <= end + - chunks_per_thread > 0 + - funct does not throw any exceptions + ensures + - This function is identical to the parallel_for_blocked() routine defined + above except that it will print messages to cout showing the progress in + executing the parallel for loop. + - It will also use the default_thread_pool() + !*/ + // ---------------------------------------------------------------------------------------- }