GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.48k stars 282 forks source link

problem compiling on nvcc when using openmp #286

Closed BillTavis closed 4 years ago

BillTavis commented 4 years ago

Hello, I have having a problem compiling on Linux using nvcc. Using a simple main file that does nothing but simply includes "CImg.h" I am able to compile with no problem using g++ main.cpp -fopenmp -o test but when I try compiling with nvcc I get errors. Using nvcc main.cu -Xcompiler -fopenmp -o test I get the following:

mand-git/CImg.h:31799:1: error: for statement expected before ‘default’ default : // Generic version ^ mand-git/CImg.h: In member function ‘cimg_library::CImg<t> cimg_library::CImg<T>::get_map(const cimg_library::CImg<t>&, unsigned int) const’: mand-git/CImg.h:31874:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h: In member function ‘cimg_library::CImg<T> cimg_library::CImg<T>::get_warp(const cimg_library::CImg<t>&, unsigned int, unsigned int, unsigned int) const’: mand-git/CImg.h:35442:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35476:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35543:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35577:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35680:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35716:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35789:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35825:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35952:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:35998:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:36089:1: error: for statement expected before ‘default’ default : // Dirichlet ^ mand-git/CImg.h:36134:1: error: for statement expected before ‘default’ default : // Dirichlet ^

If I try to compile without openmp it works fine, but I need that for my application. Any advice?

dtschump commented 4 years ago

Hello. Is it possible to try with the latest version of CImg.h ? The line numbers you show do not seem to correspond with the latest version. I never tried compiling CImg with nvcc to be honest.

BillTavis commented 4 years ago

Thanks for the fast response. I am using CImg-2.9.2 downloaded today (Standard Package). The line numbers seem to line up for me, seems to be happening wherever there is a default: in the switch statements.

dtschump commented 4 years ago

OK, so maybe some of the errors were discarded. Anyway, I've no ideas about what can be done. The OpenMP code in CImg seems to be valid (at least it validates with g++,clang++ and msvc) , so there is probably some weird stuffs going on with the nvcc compiler. Maybe people from NVIDIA could help better than I can.

dtschump commented 4 years ago

Also, not sure it could help, but you can always disable OpenMP support in CImg, by defining macro cimg_use_openmp to 0. So that you can enable OpenMP for other parts of your code, and ignore the OpenMP parts in CImg.

BillTavis commented 4 years ago

Yes, thank you that solved it! I placed the line #define cimg_use_openmp 0 before including CImg.h and it worked! My use of OpenMP is primarily in other parts of my code so this works for me. Thank you!

tlambert03 commented 3 years ago

fwiw, I'm running into this too (cimg 2.9.7, nvcc11.0). defining cimg_use_openmp 0 works for me. but would be curious if anyone else stumbling on this issue has found other solutions that allow openMP support in CImg.