Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
a31511c5
Commit
a31511c5
authored
Feb 23, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added parallel_for_verbose()
parent
2c330080
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
238 additions
and
0 deletions
+238
-0
parallel_for_extension.h
dlib/threads/parallel_for_extension.h
+155
-0
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 @@
...
@@ -5,6 +5,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"
namespace
dlib
namespace
dlib
{
{
...
@@ -284,6 +285,160 @@ namespace dlib
...
@@ -284,6 +285,160 @@ namespace dlib
parallel_for
(
tp
,
begin
,
end
,
funct
,
chunks_per_thread
);
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
...
@@ -216,6 +216,89 @@ 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_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