From 9cb1911fe8cac18630a7c41a31a66464e52c2f2b Mon Sep 17 00:00:00 2001 From: Steffen Christgau Date: Mon, 13 Jan 2020 17:04:00 +0100 Subject: [PATCH] Fix bug in OpenMP parallelization. m is declared outside the parallelized for-loops which makes it shared by default according the OpenMP standard as well as by the "default(shared)" statement. This implies a race condition and the actual value of m is undefined with in the loops. The patch fixes this issue. Note that the compiler might not allocate storage for m on the stack and use register instead, so the race condition may not manifest in wrong output when optimization is enabled, but the error is present anyway. --- code/src/ewStep.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/src/ewStep.cpp b/code/src/ewStep.cpp index 68251da..6b11e81 100644 --- a/code/src/ewStep.cpp +++ b/code/src/ewStep.cpp @@ -50,7 +50,7 @@ int ewStep( void ) CNode& Node = *gNode; // sea floor topography (mass conservation) - #pragma omp parallel for default(shared) private(i,j,absH) + #pragma omp parallel for default(shared) private(i,j,m,absH) for( i=Imin; i<=Imax; i++ ) { for( j=Jmin; j<=Jmax; j++ ) { @@ -118,7 +118,7 @@ int ewStep( void ) } // moment conservation - #pragma omp parallel for default(shared) private(i,j) + #pragma omp parallel for default(shared) private(i,j,m) for( i=Imin; i<=Imax; i++ ) { for( j=Jmin; j<=Jmax; j++ ) { @@ -210,7 +210,7 @@ int ewStepCor( void ) CNode& Node = *gNode; // sea floor topography (mass conservation) - #pragma omp parallel for default(shared) private(i,j,absH) + #pragma omp parallel for default(shared) private(i,j,m,absH) for( i=Imin; i<=Imax; i++ ) { for( j=Jmin; j<=Jmax; j++ ) { @@ -279,7 +279,7 @@ int ewStepCor( void ) // moment conservation // longitudial flux update - #pragma omp parallel for default(shared) private(i,j,v1,v2) + #pragma omp parallel for default(shared) private(i,j,m,v1,v2) for( i=Imin; i<=Imax; i++ ) { for( j=Jmin; j<=Jmax; j++ ) { @@ -313,7 +313,7 @@ int ewStepCor( void ) } // lattitudial flux update - #pragma omp parallel for default(shared) private(i,j,v1,v2) + #pragma omp parallel for default(shared) private(i,j,m,v1,v2) for( i=Imin; i<=Imax; i++ ) { for( j=Jmin; j<=Jmax; j++ ) { -- GitLab