How to enable OpenMP on cmake gcc? (covid-sim)

Hello,

I am trying to build covid-sim.
It need OpenMP to be useful.
https://build.opensuse.org/package/show/home:andythe_great/covid-sim
https://github.com/mrc-ide/covid-sim/issues/349

OpenMP is a feature in gcc is not it?
It seems like I have not enable OpenMP properly.

I add

BuildRequires:  libgomp1

and build flags

%cmake -DUSE_OPENMP:BOOL=ON \
       -DOpenMP_CXX_FLAGS:STRING=libomp \
       -DOpenMP_C_FLAGS:STRING=libomp \
       -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} 

But still encounter warning which I believe cause the build to fail.

/home/abuild/rpmbuild/BUILD/covid-sim-0.13.0/src/CovidSim.cpp:2711: warning: ignoring #pragma omp parallel -Wunknown-pragmas]
2711 | #pragma omp parallel for schedule(static,1) default(none) \

Thanks you.

Hi
That’s a runtime library for running programs that have been compiled with openmp?


This is the OpenMP runtime library needed by OpenMP enabled programs 
that were built with the -fopenmp compiler option and by programs that 
were auto-parallelized via the -ftree-parallelize-loops compiler 
option. 

Hello,
Did you mean the libgomp1 dependency I included? I am not sure if it is needed, I just found some random recommendation.
I have change the flags as my old one seems to be wrong.

I think I use it correctly now. Still, I am uncertain what went wrong from the build log.


%cmake -DUSE_OPENMP:BOOL=ON \
       -DOpenMP_CXX_FLAGS:STRING="%{optflags} -fopenmp" \
       -DOpenMP_C_FLAGS:STRING="%{optflags} -fopenmp" \
       -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} 

I believe that this is the error isn’t it? But it is specific to covid-sim rather than cmake?

#pragma omp parallel for schedule(static,500) default(none) \

Hi
The flags are already set and USE_OPENMP is already on?
https://github.com/mrc-ide/covid-sim/blob/master/CMakeLists.txt

I would suggest a first step is to build as per instructions, no using the macros…


mkdir build
cd build
cmake ..
make


git clone https://github.com/mrc-ide/covid-sim.git

Cloning into 'covid-sim'...
remote: Enumerating objects: 46, done.
remote: Counting objects: 100% (46/46), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 6871 (delta 23), reused 25 (delta 12), pack-reused 6825
Receiving objects: 100% (6871/6871), 101.93 MiB | 5.86 MiB/s, done.
Resolving deltas: 100% (5715/5715), done.

cd covid-sim
mkdir build
cd build

cmake ..

-- The C compiler identification is GNU 9.3.1
-- The CXX compiler identification is GNU 9.3.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'RelWithDebInfo' as none was specified.
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Found Python3: /usr/bin/python3.8 (found version "3.8.3") found components: Interpreter 
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Configuring done
-- Generating done
-- Build files have been written to: /data/repositories/covid-sim/build

/data/repositories/covid-sim/build> make

Scanning dependencies of target CovidSim
  6%] Building CXX object src/CMakeFiles/CovidSim.dir/CovidSim.cpp.o
 13%] Building CXX object src/CMakeFiles/CovidSim.dir/BinIO.cpp.o
 20%] Building CXX object src/CMakeFiles/CovidSim.dir/Rand.cpp.o
 26%] Building CXX object src/CMakeFiles/CovidSim.dir/Error.cpp.o
 33%] Building CXX object src/CMakeFiles/CovidSim.dir/Dist.cpp.o
 40%] Building CXX object src/CMakeFiles/CovidSim.dir/Kernels.cpp.o
 46%] Building CXX object src/CMakeFiles/CovidSim.dir/Bitmap.cpp.o
 53%] Building CXX object src/CMakeFiles/CovidSim.dir/SetupModel.cpp.o
 60%] Building CXX object src/CMakeFiles/CovidSim.dir/CalcInfSusc.cpp.o
 66%] Building CXX object src/CMakeFiles/CovidSim.dir/Sweep.cpp.o
 73%] Building CXX object src/CMakeFiles/CovidSim.dir/Update.cpp.o
 80%] Building CXX object src/CMakeFiles/CovidSim.dir/Param.cpp.o
 86%] Building CXX object src/CMakeFiles/CovidSim.dir/MicroCellPosition.cpp.o
 93%] Building CXX object src/CMakeFiles/CovidSim.dir/Direction.cpp.o
[100%] Linking CXX executable CovidSim
[100%] Built target CovidSim

Note gcc 9 :wink:

Additional note: add cmake -DCMAKE_VERBOSE_MAKEFILE=ON … for verbose make output…

Hello,
I should have tried building on my local machine first as you said.
But covid-sim would still not found openMP on my TW machine.
So OpenMP is a feature in gcc. From what I understand C compiler and CXX compiler mustbe the same version for OpenMP to detect properly.

andy@linux:~/Desktop/Software/OBS Projects/home:andythe_great/covid-sim/covid-sim-0.13.0/build> cmake ..
-- The C compiler identification is GNU 9.3.1
-- The CXX compiler identification is GNU 9.3.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'RelWithDebInfo' as none was specified.
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindOpenMP.cmake:529 (find_package_handle_standard_args)
  CMakeLists.txt:35 (find_package)


-- Configuring incomplete, errors occurred!

The C compiler identification is GNU and CXX compiler identification is 9.3.1.

I look inside CMakeError.log, don’t look like anything useful.


Detecting C OpenMP failed with the following output:
Change Dir: /home/kev-test/Desktop/Software/OBS Projects/home:andythe_great/covid-sim/covid-sim-0.13.0/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake cmTC_052e2/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_052e2.dir/build.make CMakeFiles/cmTC_052e2.dir/build
gmake[1]: Entering directory '/home/kev-test/Desktop/Software/OBS Projects/home:andythe_great/covid-sim/covid-sim-0.13.0/build/CMakeFiles/CMakeTmp'
CMakeFiles/cmTC_052e2.dir/build.make:84: *** target pattern contains no '%'.  Stop.
gmake[1]: Leaving directory '/home/kev-test/Desktop/Software/OBS Projects/home:andythe_great/covid-sim/covid-sim-0.13.0/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:141: cmTC_052e2/fast] Error 2



Detecting CXX OpenMP failed with the following output:
Change Dir: /home/kev-test/Desktop/Software/OBS Projects/home:andythe_great/covid-sim/covid-sim-0.13.0/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake cmTC_4a0e5/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_4a0e5.dir/build.make CMakeFiles/cmTC_4a0e5.dir/build
gmake[1]: Entering directory '/home/kev-test/Desktop/Software/OBS Projects/home:andythe_great/covid-sim/covid-sim-0.13.0/build/CMakeFiles/CMakeTmp'
CMakeFiles/cmTC_4a0e5.dir/build.make:84: *** target pattern contains no '%'.  Stop.
gmake[1]: Leaving directory '/home/kev-test/Desktop/Software/OBS Projects/home:andythe_great/covid-sim/covid-sim-0.13.0/build/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:141: cmTC_4a0e5/fast] Error 2

I’m a bit lost.

Thanks.

Edit: Trying to use “cmake … -DOpenMP_C_FLAGS=-fopenmp” yields the same error.

Hi
Is glibc-devel installed?

Yes, both glibc and glibc-devel.

Hi
There is something wrong with your local build environment… I tested here on Leap 15.1 and SLED 15 SP2 beta, both ran cmake fine and detected OpenMP present…

Hi
Here you go… https://build.opensuse.org/request/show/810630

You are right, I tried running openSUSE TW live ISO and it can compile locally.

Hi
Here you go… https://build.opensuse.org/request/show/810630

I see you use install -Dm0755 instead of %cmake_install.
Looking at File cmake.macros of Package cmake - openSUSE Build Service


%cmake_install \
    DESTDIR=%{buildroot} %__builder install -C %__builddir

The difference is just the “-C”? How does that make a difference?

Thank so much for help.

ps. Veyon package was submit for review, it now build on TW.

Hi
The -C option is change to the directory, in this case ‘build’ I imagine a patch is needed to get it correct for using the macro, since it’s just a binary easier to just install, then look at the cmake/make/Makefile install issue…

Alright I will keep that in mind. This seems like an edge case when the macro fail.

Hi
I would suggest talking with upstream :wink:

Did you enable the test, not sure how long it takes…

Test still running…

Is this the right place to ask them? GitHub - openSUSE/osc: The Command Line Interface to work with an Open Build Service

Hi
No, covid-sim :wink: They should be able to figure it out, or not fix etc…

test all pass
now I have to build doc

Hi
No, docs are all built… or split out?

oh right, you add the flag. I think it is ok to keep it in 1 package.

Do I also need to use %ctest macro?

Hi
Yup, my thoughts too :wink:

Hello,
I see you add graphviz as Buildrequires, but it can build without it, can it be Requires instead?