Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Incorrect initialization of a shared object in an OpenMP parallel for - bug in the intel compiler?

$
0
0

I have the following code:

#include <iostream>
using std::cout;

struct Test {
int a[3];
};

void function (Test b) {
#pragma omp parallel for default(none) shared(cout,b)
for (int i=0; i<10; i++) {
cout << b.a[0] << ""<< b.a[1] << ""<< b.a[2] <<std::endl;
}
}


int main() {

Test a;
a.a[0]=1;
a.a[1]=2;
a.a[2]=3;

function(a);



}

When running it I would expect it to print 1 2 3 on each line. Indeed this happens when compiling in serial or with openmp using, e.g., g++. However when using the intel compiler (version 15.0.4 20150805 on Linux) with openmp I get 1 0 1 on each line. Is this a bug in the compiler, or am I doing something disallowed by the c++ or openmp standard? Note that if I pass the object by reference to the function everything is fine.


Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>