Skip to content

Commit b28fd79

Browse files
committed
core: parallel_for_(): propagate RNG state from the main thread
1 parent 7878404 commit b28fd79

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

modules/core/src/parallel.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ namespace
174174
double len = wholeRange.end - wholeRange.start;
175175
nstripes = cvRound(_nstripes <= 0 ? len : MIN(MAX(_nstripes, 1.), len));
176176

177+
// propagate main thread state
178+
rng = cv::theRNG();
179+
177180
#ifdef ENABLE_INSTRUMENTATION
178181
pThreadRoot = cv::instr::getInstrumentTLSStruct().pCurrentNode;
179182
#endif
@@ -195,6 +198,9 @@ namespace
195198
#endif
196199
CV_INSTRUMENT_REGION()
197200

201+
// propagate main thread state
202+
cv::theRNG() = rng;
203+
198204
cv::Range r;
199205
r.start = (int)(wholeRange.start +
200206
((uint64)sr.start*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes);
@@ -208,6 +214,7 @@ namespace
208214
const cv::ParallelLoopBody* body;
209215
cv::Range wholeRange;
210216
int nstripes;
217+
cv::RNG rng;
211218
#ifdef ENABLE_INSTRUMENTATION
212219
cv::instr::InstrNode *pThreadRoot;
213220
#endif

0 commit comments

Comments
 (0)