Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
a31511c5
Commit
a31511c5
authored
Feb 23, 2013
by
Davis King
Browse files
Added parallel_for_verbose()
parent
2c330080
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
238 additions
and
0 deletions
+238
-0
dlib/threads/parallel_for_extension.h
dlib/threads/parallel_for_extension.h
+155
-0
dlib/threads/parallel_for_extension_abstract.h
dlib/threads/parallel_for_extension_abstract.h
+83
-0
No files found.
dlib/threads/parallel_for_extension.h
View file @
a31511c5
...
...
@@ -5,6 +5,7 @@
#include "parallel_for_extension_abstract.h"
#include "thread_pool_extension.h"
#include "../console_progress_indicator.h"
namespace
dlib
{
...
...
@@ -284,6 +285,160 @@ namespace dlib
parallel_for
(
tp
,
begin
,
end
,
funct
,
chunks_per_thread
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
namespace
impl
{
template
<
typename
T
>
class
parfor_verbose_helper
{
public:
parfor_verbose_helper
(
T
&
obj_
,
void
(
T
::*
funct_
)(
long
),
long
begin
,
long
end
)
:
obj
(
obj_
),
funct
(
funct_
),
pbar
(
end
-
begin
)
{
count
=
0
;
pbar
.
print_status
(
-
1
);
}
long
count
;
T
&
obj
;
void
(
T
::*
funct
)(
long
);
console_progress_indicator
pbar
;
mutex
m
;
void
operator
()(
long
i
)
{
(
obj
.
*
funct
)(
i
);
{
auto_mutex
lock
(
m
);
pbar
.
print_status
(
count
++
);
}
}
};
template
<
typename
T
>
class
parfor_verbose_helper2
{
public:
parfor_verbose_helper2
(
const
T
&
obj_
,
long
begin
,
long
end
)
:
obj
(
obj_
),
pbar
(
end
-
begin
)
{
count
=
0
;
pbar
.
print_status
(
-
1
);
}
mutable
long
count
;
const
T
&
obj
;
mutable
console_progress_indicator
pbar
;
mutex
m
;
void
operator
()(
long
i
)
const
{
obj
(
i
);
{
auto_mutex
lock
(
m
);
pbar
.
print_status
(
count
++
);
}
}
};
}
template
<
typename
T
>
void
parallel_for_verbose
(
thread_pool
&
tp
,
long
begin
,
long
end
,
T
&
obj
,
void
(
T
::*
funct
)(
long
),
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_helper
<
T
>
helper
(
obj
,
funct
,
begin
,
end
);
parallel_for
(
tp
,
begin
,
end
,
helper
,
chunks_per_thread
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
parallel_for_verbose
(
unsigned
long
num_threads
,
long
begin
,
long
end
,
T
&
obj
,
void
(
T
::*
funct
)(
long
),
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_helper
<
T
>
helper
(
obj
,
funct
,
begin
,
end
);
parallel_for
(
num_threads
,
begin
,
end
,
helper
,
chunks_per_thread
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
parallel_for_verbose
(
thread_pool
&
tp
,
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
(
tp
,
begin
,
end
,
helper
,
chunks_per_thread
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
parallel_for_verbose
(
unsigned
long
num_threads
,
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
(
num_threads
,
begin
,
end
,
helper
,
chunks_per_thread
);
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/threads/parallel_for_extension_abstract.h
View file @
a31511c5
...
...
@@ -216,6 +216,89 @@ namespace dlib
parallel_for(tp, begin, end, funct, chunks_per_thread);
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
parallel_for_verbose
(
thread_pool
&
tp
,
long
begin
,
long
end
,
T
&
obj
,
void
(
T
::*
funct
)(
long
),
long
chunks_per_thread
=
8
);
/*!
requires
- begin <= end
- chunks_per_thread > 0
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.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
parallel_for_verbose
(
unsigned
long
num_threads
,
long
begin
,
long
end
,
T
&
obj
,
void
(
T
::*
funct
)(
long
),
long
chunks_per_thread
=
8
);
/*!
requires
- begin <= end
- chunks_per_thread > 0
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.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
parallel_for_verbose
(
thread_pool
&
tp
,
long
begin
,
long
end
,
const
T
&
funct
,
long
chunks_per_thread
=
8
);
/*!
requires
- begin <= end
- chunks_per_thread > 0
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.
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
parallel_for_verbose
(
unsigned
long
num_threads
,
long
begin
,
long
end
,
const
T
&
funct
,
long
chunks_per_thread
=
8
);
/*!
requires
- begin <= end
- chunks_per_thread > 0
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.
!*/
// ----------------------------------------------------------------------------------------
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment