Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
649bb7ac
Commit
649bb7ac
authored
Feb 28, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: parallel_for_(): update RNG state of the main thread
parent
ebdd7410
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
3 deletions
+22
-3
core.hpp
modules/core/include/opencv2/core.hpp
+2
-0
operations.hpp
modules/core/include/opencv2/core/operations.hpp
+2
-0
parallel.cpp
modules/core/src/parallel.cpp
+18
-3
No files found.
modules/core/include/opencv2/core.hpp
View file @
649bb7ac
...
...
@@ -2834,6 +2834,8 @@ public:
double
gaussian
(
double
sigma
);
uint64
state
;
bool
operator
==
(
const
RNG
&
other
)
const
;
};
/** @brief Mersenne Twister random number generator
...
...
modules/core/include/opencv2/core/operations.hpp
View file @
649bb7ac
...
...
@@ -349,6 +349,8 @@ inline int RNG::uniform(int a, int b) { return a == b ? a : (int)(next(
inline
float
RNG
::
uniform
(
float
a
,
float
b
)
{
return
((
float
)
*
this
)
*
(
b
-
a
)
+
a
;
}
inline
double
RNG
::
uniform
(
double
a
,
double
b
)
{
return
((
double
)
*
this
)
*
(
b
-
a
)
+
a
;
}
inline
bool
RNG
::
operator
==
(
const
RNG
&
other
)
const
{
return
state
==
other
.
state
;
}
inline
unsigned
RNG
::
next
()
{
state
=
(
uint64
)(
unsigned
)
state
*
/*CV_RNG_COEFF*/
4164903690U
+
(
unsigned
)(
state
>>
32
);
...
...
modules/core/src/parallel.cpp
View file @
649bb7ac
...
...
@@ -166,7 +166,8 @@ namespace
class
ParallelLoopBodyWrapper
:
public
cv
::
ParallelLoopBody
{
public
:
ParallelLoopBodyWrapper
(
const
cv
::
ParallelLoopBody
&
_body
,
const
cv
::
Range
&
_r
,
double
_nstripes
)
ParallelLoopBodyWrapper
(
const
cv
::
ParallelLoopBody
&
_body
,
const
cv
::
Range
&
_r
,
double
_nstripes
)
:
is_rng_used
(
false
)
{
body
=
&
_body
;
...
...
@@ -181,13 +182,23 @@ namespace
pThreadRoot
=
cv
::
instr
::
getInstrumentTLSStruct
().
pCurrentNode
;
#endif
}
#ifdef ENABLE_INSTRUMENTATION
~
ParallelLoopBodyWrapper
()
{
#ifdef ENABLE_INSTRUMENTATION
for
(
size_t
i
=
0
;
i
<
pThreadRoot
->
m_childs
.
size
();
i
++
)
SyncNodes
(
pThreadRoot
->
m_childs
[
i
]);
}
#endif
if
(
is_rng_used
)
{
// Some parallel backends execute nested jobs in the main thread,
// so we need to restore initial RNG state here.
cv
::
theRNG
()
=
rng
;
// We can't properly update RNG state based on RNG usage in worker threads,
// so lets just change main thread RNG state to the next value.
// Note: this behaviour is not equal to single-threaded mode.
cv
::
theRNG
().
next
();
}
}
void
operator
()(
const
cv
::
Range
&
sr
)
const
{
#ifdef ENABLE_INSTRUMENTATION
...
...
@@ -207,6 +218,9 @@ namespace
r
.
end
=
sr
.
end
>=
nstripes
?
wholeRange
.
end
:
(
int
)(
wholeRange
.
start
+
((
uint64
)
sr
.
end
*
(
wholeRange
.
end
-
wholeRange
.
start
)
+
nstripes
/
2
)
/
nstripes
);
(
*
body
)(
r
);
if
(
!
is_rng_used
&&
!
(
cv
::
theRNG
()
==
rng
))
is_rng_used
=
true
;
}
cv
::
Range
stripeRange
()
const
{
return
cv
::
Range
(
0
,
nstripes
);
}
...
...
@@ -215,6 +229,7 @@ namespace
cv
::
Range
wholeRange
;
int
nstripes
;
cv
::
RNG
rng
;
mutable
bool
is_rng_used
;
#ifdef ENABLE_INSTRUMENTATION
cv
::
instr
::
InstrNode
*
pThreadRoot
;
#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