sandbox/bugs/foreach_openmp.c
MWE showing unintended behaviour of the qcc compiler to identify race conditions when OpenMP is enabled.
Code should fail compilation.
Compilation using
qcc test.c -fopenmp -lm
succeeds.
#include "grid/quadtree.h"
#include "run.h"
scalar f1[], f2[];
scalar *l1 = {f1};
scalar *l2 = {f2};
Dummy case setup. Not necessary since we are not running anything.
int main ()
{
//domain size
( 1<<7 );
init_grid
run();
}
scalar
curVar, oldVar
are defined outside
the foreach loop. Code should fail to compile with -fopenmp because
there is a race condition. Same behaviour is seen when
scalar
is replaced by double
/int
.
See Google
Groups Discussion for more details.
event update(i< 2; i++)
{
scalar curVar, oldVar;
foreach()
{
for (curVar, oldVar in l1, l2)
{
[] = curVar[];
oldVar}
}
//fields_stats();
}
event updateDouble(i< 2; i++)
{
double var;
foreach()
{
= sq(f1[]);
var [] = var;
f1}
//fields_stats();
}
event updateInt(i< 2; i++)
{
int var;
foreach()
{
= sq(f1[]);
var [] = var;
f1}
//fields_stats();
}