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
18ea784f
Commit
18ea784f
authored
Feb 23, 2013
by
Davis King
Browse files
Fixed a bug in parallel_for() and added unit tests for it.
parent
a31511c5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
1 deletion
+108
-1
dlib/test/CMakeLists.txt
dlib/test/CMakeLists.txt
+1
-0
dlib/test/makefile
dlib/test/makefile
+1
-0
dlib/test/parallel_for.cpp
dlib/test/parallel_for.cpp
+105
-0
dlib/threads/parallel_for_extension.h
dlib/threads/parallel_for_extension.h
+1
-1
No files found.
dlib/test/CMakeLists.txt
View file @
18ea784f
...
@@ -87,6 +87,7 @@ set (tests
...
@@ -87,6 +87,7 @@ set (tests
optimization.cpp
optimization.cpp
optimization_test_functions.cpp
optimization_test_functions.cpp
opt_qp_solver.cpp
opt_qp_solver.cpp
parallel_for.cpp
parse.cpp
parse.cpp
pipe.cpp
pipe.cpp
pixel.cpp
pixel.cpp
...
...
dlib/test/makefile
View file @
18ea784f
...
@@ -102,6 +102,7 @@ SRC += one_vs_one_trainer.cpp
...
@@ -102,6 +102,7 @@ SRC += one_vs_one_trainer.cpp
SRC
+=
optimization.cpp
SRC
+=
optimization.cpp
SRC
+=
optimization_test_functions.cpp
SRC
+=
optimization_test_functions.cpp
SRC
+=
opt_qp_solver.cpp
SRC
+=
opt_qp_solver.cpp
SRC
+=
parallel_for.cpp
SRC
+=
parse.cpp
SRC
+=
parse.cpp
SRC
+=
pipe.cpp
SRC
+=
pipe.cpp
SRC
+=
pixel.cpp
SRC
+=
pixel.cpp
...
...
dlib/test/parallel_for.cpp
0 → 100644
View file @
18ea784f
// Copyright (C) 2013 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include "tester.h"
#include <dlib/threads.h>
#include <vector>
#include <sstream>
namespace
{
using
namespace
test
;
using
namespace
dlib
;
using
namespace
std
;
dlib
::
logger
dlog
(
"test.parallel_for"
);
class
assign_element
{
public:
assign_element
(
std
::
vector
<
int
>&
vect_
)
:
vect
(
vect_
){}
std
::
vector
<
int
>&
vect
;
void
go
(
long
i
)
{
DLIB_TEST
(
0
<=
i
&&
i
<
vect
.
size
());
vect
[
i
]
=
i
;
}
void
operator
()
(
long
i
)
const
{
DLIB_TEST
(
0
<=
i
&&
i
<
vect
.
size
());
vect
[
i
]
=
i
;
}
};
void
test_parallel_for
(
long
start
)
{
std
::
vector
<
int
>
vect
(
200
,
0
);
parallel_for
(
4
,
start
,
vect
.
size
(),
assign_element
(
vect
));
for
(
unsigned
long
i
=
0
;
i
<
start
;
++
i
)
{
DLIB_TEST
(
vect
[
i
]
==
0
);
}
for
(
unsigned
long
i
=
start
;
i
<
vect
.
size
();
++
i
)
{
DLIB_TEST
(
vect
[
i
]
==
i
);
}
}
void
test_parallel_for2
(
long
start
)
{
std
::
vector
<
int
>
vect
(
200
,
0
);
assign_element
temp
(
vect
);
parallel_for
(
4
,
start
,
vect
.
size
(),
temp
,
&
assign_element
::
go
);
for
(
unsigned
long
i
=
0
;
i
<
start
;
++
i
)
{
DLIB_TEST
(
vect
[
i
]
==
0
);
}
for
(
unsigned
long
i
=
start
;
i
<
vect
.
size
();
++
i
)
{
DLIB_TEST
(
vect
[
i
]
==
i
);
}
}
class
test_parallel_for_routines
:
public
tester
{
public:
test_parallel_for_routines
(
)
:
tester
(
"test_parallel_for"
,
// the command line argument name for this test
"Run tests on the parallel_for routines."
,
// the command line argument description
0
// the number of command line arguments for this test
)
{
}
void
perform_test
(
)
{
test_parallel_for
(
0
);
test_parallel_for
(
30
);
test_parallel_for
(
50
);
test_parallel_for2
(
0
);
test_parallel_for2
(
30
);
test_parallel_for2
(
50
);
}
};
test_parallel_for_routines
a
;
}
dlib/threads/parallel_for_extension.h
View file @
18ea784f
...
@@ -100,7 +100,7 @@ namespace dlib
...
@@ -100,7 +100,7 @@ namespace dlib
const
long
block_size
=
std
::
max
(
1L
,
num
/
(
num_workers
*
chunks_per_thread
));
const
long
block_size
=
std
::
max
(
1L
,
num
/
(
num_workers
*
chunks_per_thread
));
for
(
long
i
=
0
;
i
<
num
;
i
+=
block_size
)
for
(
long
i
=
0
;
i
<
num
;
i
+=
block_size
)
{
{
tp
.
add_task
(
obj
,
funct
,
i
,
std
::
min
(
i
+
block_size
,
num
));
tp
.
add_task
(
obj
,
funct
,
begin
+
i
,
begin
+
std
::
min
(
i
+
block_size
,
num
));
}
}
tp
.
wait_for_all_tasks
();
tp
.
wait_for_all_tasks
();
}
}
...
...
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