From 6f82bdebdb652a30f6372aa8d476946d013601ba Mon Sep 17 00:00:00 2001 From: oparviai Date: Sun, 5 Mar 2017 13:56:03 +0000 Subject: [PATCH] Modify 'maxnorm' value insider critical section when using OpenMP with integer samples --- source/SoundTouch/TDStretch.cpp | 7 ++++++- source/SoundTouch/mmx_optimized.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/source/SoundTouch/TDStretch.cpp b/source/SoundTouch/TDStretch.cpp index f2c7297..8343f91 100644 --- a/source/SoundTouch/TDStretch.cpp +++ b/source/SoundTouch/TDStretch.cpp @@ -911,7 +911,12 @@ double TDStretch::calcCrossCorr(const short *mixingPos, const short *compare, do if (lnorm > maxnorm) { - maxnorm = lnorm; + // modify 'maxnorm' inside critical section to avoid multi-access conflict if in OpenMP mode + #pragma omp critical + if (lnorm > maxnorm) + { + maxnorm = lnorm; + } } // Normalize result by dividing by sqrt(norm) - this step is easiest // done using floating point operation diff --git a/source/SoundTouch/mmx_optimized.cpp b/source/SoundTouch/mmx_optimized.cpp index 17fe108..ba9ec25 100644 --- a/source/SoundTouch/mmx_optimized.cpp +++ b/source/SoundTouch/mmx_optimized.cpp @@ -125,7 +125,12 @@ double TDStretchMMX::calcCrossCorr(const short *pV1, const short *pV2, double &d if (norm > (long)maxnorm) { - maxnorm = norm; + // modify 'maxnorm' inside critical section to avoid multi-access conflict if in OpenMP mode + #pragma omp critical + if (norm > (long)maxnorm) + { + maxnorm = norm; + } } // Normalize result by dividing by sqrt(norm) - this step is easiest