Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with LLVM Clang and OpenMP fails on Ubuntu 24.04 #486

Closed
mmuetzel opened this issue Jul 13, 2024 · 9 comments
Closed

Building with LLVM Clang and OpenMP fails on Ubuntu 24.04 #486

mmuetzel opened this issue Jul 13, 2024 · 9 comments

Comments

@mmuetzel
Copy link
Contributor

mmuetzel commented Jul 13, 2024

When trying to build with LLVM Clang 18.1.3 on Ubuntu 24.04, linking ViewFactors fails with the following error when EulerFEM is configured to build with OpenMP (CC=clang CXX=clang++ cmake -DWITH_OpenMP=ON ..:

/usr/bin/ld: view3d/libview3d.a(ViewFactors.c.o): undefined reference to symbol '__kmpc_dispatch_next_4@@VERSION'
/usr/bin/ld: /lib/x86_64-linux-gnu/libomp.so.5: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

I don't know what causes that error or how to resolve it.

Building works after having configured with -DWITH_OpenMP=OFF (the default if WITH_OpenMP isn't set manually).

Is that a known issue?

mmuetzel added a commit to mmuetzel/elmerfem that referenced this issue Jul 13, 2024
Building with LLVM Clang and libomp currently fails (see ElmerCSC#486).

Add configurations to the build matrix that build with LLVM Clang without
OpenMP. Also add a runner that builds with GCC without OpenMP.
@mmuetzel mmuetzel changed the title Building with LLVM Clang and OpenMP fails Building with LLVM Clang and OpenMP fails on Ubuntu 24.04 Jul 14, 2024
@tzwinger
Copy link
Contributor

tzwinger commented Jul 15, 2024

Did I get it wrong, but are you still using gfortran for the Fortran part of Elmer? Simply, it works for me using clang and clang++, but as soon as I replace gfortran with flang, I get into all sorts of troubles. For CSC it would be very interesting to get it working with the complete LLVM compiler suite, as LLVM is important for our supercomputer LUMI, which has AMD hardware.

@mmuetzel
Copy link
Contributor Author

Yes, this is still with gfortran. I only used clang and clang++ instead of gcc and g++.
The reason for that error might be that some dependencies (OpenBLAS?) were built with libgomp on Ubuntu. And linking different OpenMP implementations into the same application causes errors.

When it comes to using LLVM Flang: MSYS2 (Windows MinGW) has the CLANG64 environment that is based on a LLVM toolchain (clang, clang++, flang, lld, libomp, ...):
https://www.msys2.org/docs/environments/

I'd like to add some CI runners for MSYS2 (incl. a runner using their CLANG64 environment) once the CMake build rules are ready for Windows. That would hopefully cover at least parts of the build configuration on your supercomputer.

@ghostforest
Copy link

ghostforest commented Jul 24, 2024

I got a similar error. The linker cant find openMP or something. I suggest you check here: #503 (comment)
I'm on mac but the issue might be the same. I did get it to compile after all. Linking openMP with clang is explicitly difficult it seems. I posted my cmake command and my shell configuration. You might need to change the links to the libraries to match the locations on your system.
I think it should be a lot easier to compile this. As of now I spent probably 2 weeks to get different configurations on mac compiled simply of lack of documentations or a decent cmake.

@mmuetzel
Copy link
Contributor Author

mmuetzel commented Jul 24, 2024

I can't find the issue (i.e, the error message) that you saw in #503.
Maybe you are confusing openMPI with OpenMP? The symbol that is reported as an undefined reference in the error message here belongs to the LLVM implementation of OpenMP afaict. It's not related to MPI.
https://llvm.org/doxygen/classllvm_1_1OpenMPIRBuilder.html#a49dbf0af8f3e1314b3b60222651b6fc2

@ghostforest
Copy link

ghostforest commented Jul 24, 2024

I had the same issue as you. I had to explicitly link the dylib. That is what chat gpt told me. Adding

export PATH="/opt/homebrew/opt/open-mpi/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/open-mpi/lib $LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/open-mpi/include $CPPFLAGS"
export OMPI_CC=/opt/homebrew/opt/llvm/bin/clang
export OMPI_CXX=/opt/homebrew/opt/llvm/bin/clang++
export OMPI_FC=/usr/local/bin/gfortran

to my shell configuration file,
and adding:

      -DMPI_C_COMPILER=/opt/homebrew/opt/open-mpi/bin/mpicc \
      -DMPI_CXX_COMPILER=/opt/homebrew/opt/open-mpi/bin/mpicxx \
      -DMPI_Fortran_COMPILER=/opt/homebrew/opt/open-mpi/bin/mpifort \
      -DCMAKE_C_FLAGS="-fopenmp" \
      -DCMAKE_CXX_FLAGS="-fopenmp" \
      -DCMAKE_EXE_LINKER_FLAGS="-L/opt/homebrew/opt/libomp/lib -lomp" \

to the cmake command solved the issue for me. I cant tell you more.

ChatGPT:
The error you're encountering is a linker error, indicating that the linker (ld) cannot find a required symbol (__kmpc_dispatch_next_4@@VERSION) which is part of the OpenMP library (libomp). This usually happens because the linker hasn't been provided with the necessary library to resolve the OpenMP symbols.

@mmuetzel
Copy link
Contributor Author

Do you mean to explicitly link with -lomp? I haven't tried that. But maybe that's needed additionally to -fopenmp in that specific configuration...

@ghostforest
Copy link

ghostforest commented Jul 24, 2024

I mean that I had the same problem as you and that I asked chatgpt and it told me:
The error you're encountering is a linker error, indicating that the linker (ld) cannot find a required symbol (__kmpc_dispatch_next_4@@VERSION) which is part of the OpenMP library (libomp). This usually happens because the linker hasn't been provided with the necessary library to resolve the OpenMP symbols.

Id simply compare your cmake command to mine and add what is missing regarding OpenMP.
Id compare your shell configuration to the part of mine that I posted and Id add what is missing....
Shell config seems to be important on Mac at least. Even stating all the directories in the cmake command will make the compiler not find things if its not defined in your shell profile.
Ofc you have to change the links so they point to the corresponding directories on your system.
See the last post in #503. Its all there.

If you tried that and it still fails we can look further. But for now apply the information that has been given to you.

Short answer:
YES

@mmuetzel
Copy link
Contributor Author

Mixing different OpenMP implementations is probably a bad idea. I took the opposite approach and linked to the GNU implementation of OpenMP instead of linking explicitly with -lomp.
Let's see how that will fare: #487

@mmuetzel
Copy link
Contributor Author

mmuetzel commented Jul 25, 2024

It looks like configuring with CC=clang CXX=clang++ cmake -DWITH_OpenMP=ON -DOpenMP_C_FLAGS=-fopenmp=libgomp -DOpenMP_CXX_FLAGS=-fopenmp=libgomp .. resolves the issue at link time.

So, this was a user error on configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants