Compiling OpenMP Host Code Need assistance getting OpenMP code to compile

Hi,

So I’m trying to do some multi-gpu stuff and want to use OpenMP for the host code. (I’ve tried the multi-gpu examples using cutthread from the Linux SDK and am not too impressed). Anyway it turns out that the Windoze version of the SDK includes an OpenMP example… (why not Linux as well???)…

So I’m trying to build the Windoze example with the following Makefile:

[codebox]# Add source files here

EXECUTABLE := cudaOpenMP

CUDA source files (compiled with cudacc)

CUFILES := cudaOpenMP.cu

CUDACCFLAGS := -Xcompiler -openmp -lgomp -v

include …/…/common/common.mk[/codebox]

I used to get errors to the effect that “omp this or that” was unknown. Those have stopped now so I guess the necessary libraries are being found. Now I get a “cc1plus: error: output filename specified twice”. Here’s the full output:

[codebox]tim@stretch:~/cuda/active_projects/cudaOpenMP$ rm -r obj/; make

#$ SPACE=

#$ MODE=DEVICE

#$ HERE=/usr/local/cuda/bin

#$ THERE=/usr/local/cuda/bin

#$ TOP=/usr/local/cuda/bin/…

#$ LD_LIBRARY_PATH=/usr/local/cuda/bin/…/lib:/usr/local/cuda/bin/…/extools/lib:/usr/local/cuda/lib:/usr/lib/mpi/gcc/openmpi/lib

#$ PATH=/usr/local/cuda/bin/…/open64/bin:/usr/local/cuda/bin/…/bin:/usr/local/cuda/bin:/usr/lib/mpi/gcc/openmpi/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/lib/qt3/bin

#$ INCLUDES=“-I/usr/local/cuda/bin/…/include” “-I/usr/local/cuda/bin/…/include/cudart”

#$ LIBRARIES= “-L/usr/local/cuda/bin/…/lib” -lcudart

#$ CUDAFE_FLAGS=

#$ OPENCC_FLAGS=

#$ PTXAS_FLAGS=

#$ gcc -D__CUDA_ARCH__=100 -E -x c++ -DCUDA_NO_SM_13_DOUBLE_INTRINSICS -DCUDA_NO_SM_12_ATOMIC_INTRINSICS -DCUDA_NO_SM_11_ATOMIC_INTRINSICS -DCUDA_FLOAT_MATH_FUNCTIONS “-I/usr/local/cuda/bin/…/include” “-I/usr/local/cuda/bin/…/include/cudart” -I. -D__CUDACC__ -C -fno-strict-aliasing -openmp -O3 -I"." -I"/usr/local/cuda/include" -I"…/…/common/inc" -D"UNIX" -include “cuda_runtime.h” -m32 -malign-double -o “/tmp/tmpxft_00001bff_00000000-4_cudaOpenMP.cpp1.ii” “cudaOpenMP.cu”

cc1plus: error: output filename specified twice

–error 0x100 –

make: *** [obj/release/cudaOpenMP.cu.o] Error 255

tim@stretch:~/cuda/active_projects/cudaOpenMP$

[/codebox]

Some reasonably artful googling of that error has not turned anything useful up so far. Can somebody please tell me how to compile CUDA apps containing OpenMP calls in the host side code. I beleive the flags I’m using are about right, but something else isn’t…

Any ideas, advice or experience shared would be most appreciated…

The reason why there isn’t a linux OpenMP SDK example is most likely because OpenMP support in gcc was only officially added in version 4.3 (although several distributions like Redhat 5 and Ubuntu 8 contain a gcc 4.2 with back ported OMP support). It is a bit hard to ship an SDK version when the compiler support isn’t there…

Your makefile is pretty messed up, from the look of this:

gcc -D__CUDA_ARCH__=100 -E -x c++ ......

In gcc 4.3 (or a back ported 4.2), the correct command to enable compilation with OpenMP is

{gcc,g++,gfortran} -fopenmp

The linking stage should include -lgomp . It should work straight out of box without anything else special needed.

Thanks for the quick response! I’ve changed the second part of my (messed up) Makefile so now I have :

[codebox]CUDACCFLAGS := -Xcompiler -fopenmp

LIB := -Xlinker -lgomp[/codebox]

and all seems to be working now. Which is nice.

Fair comment about the compiler support. I didn’t think OpenMP support in gcc was all that new… lives and learns…

Just to clarify this for other people (it took me a while to figure out how to get this to work):

To compile in one line on linux gcc 4.3:

$ nvcc -Xcompiler -fopenmp -Xlinker -lgomp cudaOpenMP.cu

or

$ nvcc -Xcompiler -fopenmp -lgomp cudaOpenMP.cu

(which is the same thing).

Obviously this can be split out into a makefile as explained above.

-Jon

hi,

i am working on compiling an OpenMP code with CUDA as described in the earlier posts… I have made the Makefile also in the similar way…
But it gives the following errors :

[ddsop@deep par_bfs]$ make
obj/release/bfs.cu_o: In function main': tmpxft_00003f1a_00000000-11_bfs.ii:(.text+0x4a2): undefined reference to omp_set_num_threads’
tmpxft_00003f1a_00000000-11_bfs.ii:(.text+0x4be): undefined reference to GOMP_parallel_start' tmpxft_00003f1a_00000000-11_bfs.ii:(.text+0x4cf): undefined reference to GOMP_parallel_end’
obj/release/bfs.cu_o: In function main.omp_fn.0': tmpxft_00003f1a_00000000-11_bfs.ii:(.text+0x547): undefined reference to omp_get_thread_num’
tmpxft_00003f1a_00000000-11_bfs.ii:(.text+0x54c): undefined reference to `omp_get_num_procs’
collect2: ld returned 1 exit status
make: *** […/…/bin/linux/release/par_bfs] Error 1

This error comes in spite of including omp.h and cutil.h.
Please help…

Thanks

You probably are not linking the OpenMP runtime library. Add -lomp to the end of your linking phase and it should work.

i have added the linkers in the Makefile…

My Makefile looks like this :

Build script for project

############################################################
####################

Add source files here

EXECUTABLE := par_bfs

CUDA source files (compiled with cudacc)

CUFILES := bfs.cu

CUDACCFLAGS := -Xcompiler -fopenmp

LIB := -Xlinker -lgomp

############################################################
####################

Rules and targets

include …/…/common/common.mk