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
67c7ebd5
Commit
67c7ebd5
authored
Mar 02, 2013
by
Davis King
Browse files
Added initial version of parallel for loop example
parent
d69a1c95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
examples/CMakeLists.txt
examples/CMakeLists.txt
+1
-0
examples/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