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
67c7ebd5
Commit
67c7ebd5
authored
Mar 03, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added initial version of parallel for loop example
parent
d69a1c95
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
CMakeLists.txt
examples/CMakeLists.txt
+1
-0
parallel_for_ex.cpp
examples/parallel_for_ex.cpp
+71
-0
No files found.
examples/CMakeLists.txt
View file @
67c7ebd5
...
@@ -57,6 +57,7 @@ add_example(multithreaded_object_ex)
...
@@ -57,6 +57,7 @@ add_example(multithreaded_object_ex)
add_example
(
object_detector_advanced_ex
)
add_example
(
object_detector_advanced_ex
)
add_example
(
object_detector_ex
)
add_example
(
object_detector_ex
)
add_example
(
optimization_ex
)
add_example
(
optimization_ex
)
add_example
(
parallel_for_ex
)
add_example
(
pipe_ex
)
add_example
(
pipe_ex
)
add_example
(
pipe_ex_2
)
add_example
(
pipe_ex_2
)
add_example
(
quantum_computing_ex
)
add_example
(
quantum_computing_ex
)
...
...
examples/parallel_for_ex.cpp
0 → 100644
View file @
67c7ebd5
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This is an example illustrating the use of the parallel for loop
tools from the dlib C++ Library.
*/
#include <dlib/threads.h>
#include <dlib/misc_api.h> // for dlib::sleep
#include <vector>
#include <iostream>
using
namespace
dlib
;
using
namespace
std
;
struct
function_object
{
function_object
(
std
::
vector
<
int
>&
vect
)
:
vect1
(
vect
)
{}
std
::
vector
<
int
>&
vect1
;
void
operator
()
(
long
i
)
const
{
vect1
[
i
]
=
i
;
dlib
::
sleep
(
100
);
}
};
int
main
()
{
const
unsigned
long
num_threads
=
4
;
std
::
vector
<
int
>
vect1
(
10
);
parallel_for
(
num_threads
,
0
,
vect1
.
size
(),
function_object
(
vect1
));
for
(
unsigned
long
i
=
0
;
i
<
vect1
.
size
();
++
i
)
cout
<<
vect1
[
i
]
<<
endl
;
cout
<<
"
\n
**************************************
\n
"
;
vect1
.
assign
(
10
,
-
1
);
parallel_for
(
num_threads
,
1
,
5
,
function_object
(
vect1
));
for
(
unsigned
long
i
=
0
;
i
<
vect1
.
size
();
++
i
)
cout
<<
vect1
[
i
]
<<
endl
;
cout
<<
"
\n
**************************************
\n
"
;
// uncomment this line if your compiler supports the new C++0x lambda functions
#define COMPILER_SUPPORTS_CPP0X_LAMBDA_FUNCTIONS
#ifdef COMPILER_SUPPORTS_CPP0X_LAMBDA_FUNCTIONS
std
::
vector
<
int
>
vect2
(
10
);
parallel_for
(
num_threads
,
0
,
vect2
.
size
(),
[
&
](
long
i
){
vect2
[
i
]
=
i
;
dlib
::
sleep
(
100
);
});
for
(
unsigned
long
i
=
0
;
i
<
vect2
.
size
();
++
i
)
cout
<<
vect2
[
i
]
<<
endl
;
#endif
}
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