mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added overloads of the parallel for functions that use default_thread_pool()
This commit is contained in:
parent
3de7ddf18a
commit
5b36194513
@ -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 <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
|
||||
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
|
||||
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>
|
||||
@ -597,6 +645,29 @@ namespace dlib
|
||||
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 @@
|
||||
#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 <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
|
||||
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
|
||||
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
|
||||
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()
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user