clang-omp / clang

clang with OpenMP 3.1 and some elements of OpenMP 4.0 support
clang-omp.github.com
Other
91 stars 15 forks source link

Simple hello world, different output Clang/GCC #73

Closed wargand closed 9 years ago

wargand commented 9 years ago

Hi, I just started with Clang/OpenMP, So I cloned and compiled the trunk version. Compilation worked fine. To test OpenMP with clang I downloaded the simple hello world program from here: https://computing.llnl.gov/tutorials/openMP/samples/C/omp_hello.c

When I compile and run it, I get: Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1

The same program compiled with gcc: Hello World from thread = 0 Number of threads = 8 Hello World from thread = 1 Hello World from thread = 4 Hello World from thread = 5 Hello World from thread = 3 Hello World from thread = 2 Hello World from thread = 6 Hello World from thread = 7

So, the gcc version looks more correct to me. Question is... my bug or clang bug? Something I overlooked?

andreybokhanko commented 9 years ago

Hi,

Have you tried to set OMP_NUM_THREADS variable as described here: http://clang-omp.github.io/#try-openmp-clang ?

Yours,

Andrey Bokhanko

Software Engineer Intel Compiler Team Intel

wargand commented 9 years ago

Hello,

yes, and in a way it works. When I set OMP_NUM_THREADS to 3 I get:

Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1 Hello World from thread = 0 Number of threads = 1

So I have different threads. I have as many threads as OMP_NUM_THREADS allows, but all threads are thread 0.

Guido

On Mon, 25 May 2015 08:12:51 -0700 Andrey Bokhanko notifications@github.com wrote:

Hi,

Have you tried to set OMP_NUM_THREADS variable as described here: http://clang-omp.github.io/#try-openmp-clang ?

Yours,

Andrey Bokhanko

Software Engineer Intel Compiler Team Intel


Reply to this email directly or view it on GitHub: https://github.com/clang-omp/clang/issues/73#issuecomment-105249670

andreybokhanko commented 9 years ago

Guido,

It seems your issue is related to how OpenMP runtime library works on your system. I suggest you to post your question on "openmp-dev" mailing list (http://lists.cs.uiuc.edu/mailman/listinfo/openmp-dev) -- as this is the forum library developers / users visit to communicate on library-related issues.

Yours,

Andrey Bokhanko

Software Engineer Intel Compiler Team Intel

wargand commented 9 years ago

As I said, I am not too experienced with OpenMP, but your explanation 'related how the runtime library works on my system' is not convincing. The problem seems to be that with clang omp_get_thread_num() always returns 0. This does not happen when I compile the same program with gcc.

Since the gcc compiles and runs the hello world correctly, I doubt the OpenMP devs will do more than shrug and tell me: Clang problem.

Guido

On Tue, 26 May 2015 14:23:16 -0700 Andrey Bokhanko notifications@github.com wrote:

Guido,

It seems your issue is related to how OpenMP runtime library works on your system. I suggest you to post your question on "openmp-dev" mailing list (http://lists.cs.uiuc.edu/mailman/listinfo/openmp-dev) -- as this is the forum library developers / users visit to communicate on library-related issues.

Yours,

Andrey Bokhanko

Software Engineer Intel Compiler Team Intel


Reply to this email directly or view it on GitHub: https://github.com/clang-omp/clang/issues/73#issuecomment-105668883

andreybokhanko commented 9 years ago

Guido,

Clang and gcc use different runtimes. Clang uses LLVM OpenMP runtime, while gcc uses libgomp. I'm not saying there is 100% probability that the problem is with runtime library, but based on your explanation ("I have different threads... but all threads are thread 0") it is very likely.

To answer your original question: the test program you use is fine, so the problem is definitely either with clang, OpenMP runtime, how they work on your system or how you configured the compiler / library. Sorry for not being more specific, but given the information you provided, someone has to invest significant amount of time to figure out what went wrong in your case.

Andrey Bokhanko

Software Engineer Intel Compiler Team Intel

wargand commented 9 years ago

Guido,

Clang and gcc use different runtimes. Clang uses LLVM OpenMP runtime, while gcc uses libgomp.

Ahh, ok. This could explain it. Actually the clang version seems to link against libgomp AND libiomp5. Which one is actually used? Don't know.

I'm not saying there is 100% probability that the problem is with runtime library, but based on your explanation ("I have different threads... but all threads are thread 0") it is very likely.

It's fine. I did not know about the difference libgomp/libiomp5 and therefore thought if everything is the same except the compiler, it has to be the compiler. sigh Not such a simple solution, it seems.

Sorry for not being more specific, but given the information you provided, someone has to invest significant amount of time to figure out what went wrong in your case.

Don't worry. Now that I know it is my system, I will figure it out.

Thanks, Guido

wargand commented 9 years ago

And problem solved. When Andrey told me: "Clang uses LLVM OpenMP runtime, while gcc uses libgomp" and I saw that clang programs linked against both libs, it was not too difficult to find the problem.

Since I tested gcc with OpenMP first I added -lgomp to the linker flags. Since I did not know the difference libgomp/LLVM OpenMP runtime I left this flag in, when I tried the same with clang. Without the -lgomp flag, the gcc and clang outputs are logical identical.

Sorry for the noise.

Guido

andreybokhanko commented 9 years ago

No problem. Glad the problem is resolved.

Andrey