wsmoses / Tapir-Meta

24 stars 7 forks source link

Bug while compiling c++ code with -O3 flag #11

Open vidsinghal opened 4 years ago

vidsinghal commented 4 years ago

Hi, Attached are two files one with no bug and one with a bug. The two files do the same thing the only difference is that the file with the bug is designed to perform a parallel version of the code compared to the file with no bug.

The file with the bug is designed such that the programmer can set the depth of parallelism in the main function. When this depth is set to 0 the runtime should be close to the file with no bug. The file with the bug is designed such that there are 2 functions: one parallel and one serial. When the desired depth is reached the program calls the serial version of the code rather than the parallel version. The only difference b/w the serial and parallel function is the name of the function and the addition of "spawn" and "sync" to enable parallelism.

The interesting thing is that when I compile the files with your clang++ compiler with the depth set to 0 in the file with the bug(parallel file) it is more than 10X slower than the file with no bug (compiled using -O3 flag) .

However if I compile the file with g++ the the run-times of both the files are much closer to each other as they should be with -O3 optimization.

It seems than your clang++ version cannot differentiate between a serial and parallel version of the functions in the file with the bug where the names of the functions are different but the only difference between the two functions is the addition of the spawn to make it parallel using the cilkplus runtime. So it is adding some parallel overhead in the file with the bug. This might be a bug you might want to solve as it might lead to other unidentified bugs in the compiler.

g++ on the other hand can differentiate between those functions and gives the desired run times.

I have attached the two files one with the bug and one without. Hope to see the new version of the compiler with the bug resolved. thanks! LLvm_bug.zip LLvm_no_bug.zip

I compiled the files as follows:

clang++ -std=c++11 -O3 -fcilkplus filename -o objectName