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

fpm test fails to run an OpenMP "Hello, world!" program compiled with LLVM flang-new on macOS #1088

Open
rouson opened this issue Nov 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@rouson
Copy link
Contributor

rouson commented Nov 5, 2024

Description

On macOS 14.6.1 with an Apple M2 processor and LLVM Flang 20.0.0 (commit be64ca) built from source, fpm test --compiler flang-new --flag -fopenmp successfully builds a program in the test/ subdirectory. As demonstrated below, however, the program fails to launch even though I can execute multithreaded runs the samefpm-generated file as long as I launch the program myself at the command line rather than via fpm.

fpm new macos-openmp
cd macos-openmp 
vim test/check.f90
cat test/check.f90

program check
use omp_lib
implicit none

!$omp parallel 
print *, "Hello from thread ",omp_get_thread_num()
!$omp end parallel 

end program check

Running the above program with the command

fpm test --compiler flang-new --flag -fopenmp

yields the following trailing output:

[100%] Project compiled successfully.
dyld[59487]: Library not loaded: @rpath/libomp.dylib
  Referenced from: <6BBE5380-F853-3F07-B154-4337D2C20E5B> /Users/rouson/Repositories/macos-openmp/build/flang-new_1F0FD47CBB36F885/test/check
  Reason: no LC_RPATH's found
<ERROR> Execution for object " check " returned exit code  6
<ERROR> *cmd_run*:stopping due to failed executions
STOP 6

Expected Behaviour

I expected the above fpm command to produce the following output generated by launching the program directly at the command line:

export OMP_NUM_THREADS=2
./build/flang-new_1F0FD47CBB36F885/test/check
 Hello from thread  0
 Hello from thread  1

Version of fpm

0.10.1

Platform and Architecture

macOS

Additional Information

No response

@rouson rouson added the bug Something isn't working label Nov 5, 2024
@perazz
Copy link
Contributor

perazz commented Nov 7, 2024

Hi @rouson, my comments here are a wild guess as I don't have a flang installation.

The error you're seeing suggests that the executable cannot find the openmp library.

My understanding is that the executable contains the appropriate library dependency. The linker put it as @rpath/libomp.dylib, so, not with a special path, but just in any of the Mac's environment library folders.

However, that library is not present in the fpm run environment (the one created by call execute_command_line inside fpm), while it is present in your current terminal (everything works when you run from it).

Could it be related to the following open issue? llvm/llvm-project#90543
Or, does LLVM add to the environment variables that somehow are not defined in the new environment opened by fpm?

If special commands are needed, an optimal way to solve this would be to extend the openmp metapackage to work with LLVM flang imho.

@rouson
Copy link
Contributor Author

rouson commented Nov 12, 2024

@perazz great detective work. Thanks! I think your diagnosis is correct. I found the workaround below. FYI, I'm now also encountering the issue with linking to other libraries so it's not just related to OpenMP.

export FPM_LDFLAGS="-rpath $DYLD_LIBRARY_PATH"

Also, looking at the LLVM issue that you cited, I see that their cmake command includes something I didn't have:

-DCMAKE_CXX_LINK_FLAGS=“-Wl,-rpath,$LD_LIBRARY_PATH”

where the macOS equivalent involves replacing LD_LIBRARY_PATH with DYLD_LIBRARY_PATH, but I tried adding this to the cmake command that I use when building flang-new from source and that didn't help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants