Commit 0276b894 authored by Steffen Christgau's avatar Steffen Christgau Committed by Matthias Ruester

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.
parent 2548d69f
......@@ -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,nod,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,nod,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,nod,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++ ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment