The question about using OpenMP taskloop feature in gcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

Greetings from me!

I try to test OpenMP taskloop feature, so write a simple program:

#include <omp.h>
#include <stdio.h>

int main(void) {
    #pragma omp parallel for
    for (auto i = 0; i < 10; i++) {
          int sum = 0;
          #pragma omp taskloop shared(sum)
          for (auto j = 0; j < 1000000; j++) {
                 sum += j;
           }
           printf("%d\n", sum);
     }
     return 0;
}

Build with g++:

$ g++ -fopenmp -std=c++11 hello.cpp

Run it:

$ ./a.out
1306095808
-282666465
-1041115334
1291875106
1458947340
-1324830858
1186345979
-505484990
1660339799
93719282

We can see it generates the gibberish. But build using clang++:

$ clang++ -fopenmp -std=c++11 hello.cpp

Every time it will generate the same result:

$ ./a.out
1783293664
1783293664
1783293664
1783293664
1783293664
1783293664
1783293664
1783293664
1783293664
1783293664

Since I am not an expert of OpenMP, I am not sure whether it's the
coincidence of
clang version, or it should be a bug of gcc.

Could anyone give some comments? Thanks very much in advance!


Best Regards
Nan Xiao



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux