nvcc compiler, pthreads, Linux


I am writing a program that needs 2 cpu threads, and was wondering if I can use the flag -pthread with nvcc compiler. My initial testing tells me otherwise.

I ended up breaking the code into a .c file and a .cu file, compiling the .c file with “g++ -pthread …”, and the .cu file with “nvcc …” commands to obtain object files, then linking them with nvcc. This works ok, but I would like to know if there is an easier way.

I finally figured it out. Basically nvcc can compile .cu files that have #include and other code related to POSIX threads without the need to use -pthread flag. In other words, instead of “g++ -pthread … file.c”, one can use “nvcc … file.cu”. In hindsight, the solution was very simple!