Commit 5b361945 authored by Davis King's avatar Davis King

Added overloads of the parallel for functions that use default_thread_pool()

parent 3de7ddf1
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "parallel_for_extension_abstract.h" #include "parallel_for_extension_abstract.h"
#include "thread_pool_extension.h" #include "thread_pool_extension.h"
#include "../console_progress_indicator.h" #include "../console_progress_indicator.h"
#include "async.h"
namespace dlib namespace dlib
{ {
...@@ -186,6 +187,17 @@ namespace dlib ...@@ -186,6 +187,17 @@ namespace dlib
parallel_for_blocked(tp, begin, end, funct, chunks_per_thread); parallel_for_blocked(tp, begin, end, funct, chunks_per_thread);
} }
template <typename T>
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 ...@@ -285,6 +297,19 @@ namespace dlib
parallel_for(tp, begin, end, funct, chunks_per_thread); parallel_for(tp, begin, end, funct, chunks_per_thread);
} }
// ----------------------------------------------------------------------------------------
template <typename T>
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 ...@@ -499,6 +524,29 @@ namespace dlib
parallel_for(num_threads, begin, end, helper, chunks_per_thread); parallel_for(num_threads, begin, end, helper, chunks_per_thread);
} }
// ----------------------------------------------------------------------------------------
template <typename T>
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<T> helper(funct, begin, end);
parallel_for(begin, end, helper, chunks_per_thread);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T> template <typename T>
...@@ -597,6 +645,29 @@ namespace dlib ...@@ -597,6 +645,29 @@ namespace dlib
parallel_for_blocked(num_threads, begin, end, helper, chunks_per_thread); parallel_for_blocked(num_threads, begin, end, helper, chunks_per_thread);
} }
// ----------------------------------------------------------------------------------------
template <typename T>
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<T> helper(funct, begin, end);
parallel_for_blocked(begin, end, helper, chunks_per_thread);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#ifdef DLIB_PARALLEL_FoR_ABSTRACT_Hh_ #ifdef DLIB_PARALLEL_FoR_ABSTRACT_Hh_
#include "thread_pool_extension_abstract.h" #include "thread_pool_extension_abstract.h"
#include "async_abstract.h"
namespace dlib namespace dlib
{ {
...@@ -123,6 +124,25 @@ namespace dlib ...@@ -123,6 +124,25 @@ namespace dlib
parallel_for_blocked(tp, begin, end, funct, chunks_per_thread); parallel_for_blocked(tp, begin, end, funct, chunks_per_thread);
!*/ !*/
// ----------------------------------------------------------------------------------------
template <typename T>
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 ...@@ -225,6 +245,25 @@ namespace dlib
parallel_for(tp, begin, end, funct, chunks_per_thread); parallel_for(tp, begin, end, funct, chunks_per_thread);
!*/ !*/
// ----------------------------------------------------------------------------------------
template <typename T>
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 ...@@ -312,6 +351,27 @@ namespace dlib
parallel for loop. parallel for loop.
!*/ !*/
// ----------------------------------------------------------------------------------------
template <typename T>
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 ...@@ -399,6 +459,27 @@ namespace dlib
executing the parallel for loop. executing the parallel for loop.
!*/ !*/
// ----------------------------------------------------------------------------------------
template <typename T>
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()
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment