I just want to cooperate CPU & GPU to do something.
My problem is that when I compile the above code these omp pragmas do not have any effect !
My system is SuSE10.1,
the C/C++ compiler is icpc&icc 10.0.023, and nvcc1.0,
and the option ’ -Xcompiler -openmp’ has added to ‘NVCCFLAG’ in ‘common.mk’.
I just ported the Windows CUDA SDK project/cudaOpenMP/cudaOpenMP.cu from Windows to Linux RHEL 5.1 with gcc 4.1. My understanding is that although OpenMP isn’t generally available until gcc 4.2, some Linux ports, like RHEL 5.1 with gcc 4.1, do support OpenMP to some extent (a good share of the OpenMP Validation Suite passes, but not everything). cudaOpenMP reports “Test PASSED” on RHEL 5.1 (I don’t have OpenMP support on my Windows machine so I can’t compare outputs).
To enable:
add the following line below the line containing “NVCCFLAGS :=” around line 90
NVCCFLAGS += -Xcompiler -fopenmp
search for “# Libs” and add the following line below the initial definition of LIB
LIB += -lgomp
in cudaOpenMP.cu place curly-brackets ({}) around the #pragma omp parallel clause (after doing so the { will be at line 120 and the } at line 149
The extra set of {}'s shouldn’t have been necessary, but it seems to have been necessary for me.
The extra {}'s are needed when the #pragma encapsulates more than one statement, thus forming a block. At least that’s what I read elsewhere…
Anyway, using laffer’s advice above I got the cudaOpenMP example from the Windoze SDK working. I also wrote another little test program and all seemed to be going well so I went ahead and integrated OpenMP into my main project. Now, when I compile the project I get a “warning: ignoring #pragma omp parallel”.
The difference between my project and the cudaOpenMP example is that I’m using OpenMP in .cpp file, as opposed to .cu. The curious thing is that all the other OpenMP calls I use compile and work correctly. For instance omp_get_num_procs() compiles and gives the right result if queried, but when the #pragma omp parallel block is entered there’s only one CPU thread etc etc…
As I mentioned, I made the changes suggested by laffer in the common.mk file which means I can now compile and run CUDA app’s with OpenMP pragmas in .cu files but not in .cpp files. I’ve tried all sorts of different combinations of the following general form:
but in each case I get the same “warning: ignoring #pragma omp parallel” and otherwise everything compiles, and runs… The OpenMP library is being found, linked and OpenMP calls work but the #pragma is ignored! Why!!!
Can anybody help me out with this? I’m sure it’s something small. If someone does I promise I’ll write a little how-to and post it here so if this question is ever asked again, it won’t need to be answered again…
Hi, I know this is nearly 2 years late, but I’ve come across this problem, too, and figured out that “what” and the “why.”
The problem is that nvcc assumes a Gnu C compiler, regardless of whether you are using ifc or pgcc as your regular compiler. It sounds like you use ifc/ifcpc, which would normally accept “-openmp”. Use the gcc syntax “-fopenmp” in your nvcc command line instead.
Now, this bring about a whole new series of problems—how to link in the OpenMP libraries when some of your code is compiled with “ifc -openmp” and the Cuda stuff with “nvcc --compiler-options -fopenmp”. Any ideas?