Closed welchr closed 3 years ago
Here is another take at the problem tricking Xcode into supportinh -fopenmp: https://mac.r-project.org/openmp/ Tests do test threading in built library, namely those setting _NUM_THREADS variables.
Not reproducible on Azure CI (though setting compiler via -DCMAKE_C_COMPILER
and not messing with CPPFLAGS or LDFLAGS at all)
Thanks for looking into this, really appreciate the help. Your test case clued me in to -DNOFORTRAN=1
, which seems to be related to the problem. If I include that, it will compile successfully, although it seems as though LAPACK is left out and only one test case is run when ctest is executed:
Test project /Users/welchr/scratch/OpenBLAS/build
Start 1: openblas_utest
1/1 Test #1: openblas_utest ................... Passed 0.18 sec
If I remove -DNOFORTRAN=1
, then the compile fails with:
/usr/local/bin/gfortran -L/usr/local/opt/libomp/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -fopenmp -Wall -frecursive -fno-optimize-sibling-calls -m64 -fdefault-integer-8 -fopenmp -fPIC -fno-tree-vectorize -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk CMakeFiles/zblat2.dir/zblat2.f.o -o zblat2 ../lib/libopenblas_64.a
Undefined symbols for architecture x86_64:
"___kmpc_for_static_fini", referenced from:
_.omp_outlined. in libopenblas_64.a(blas_server_omp.c.o)
"___kmpc_for_static_init_8", referenced from:
_.omp_outlined. in libopenblas_64.a(blas_server_omp.c.o)
"___kmpc_fork_call", referenced from:
_exec_blas in libopenblas_64.a(blas_server_omp.c.o)
"___kmpc_global_thread_num", referenced from:
_exec_blas in libopenblas_64.a(blas_server_omp.c.o)
"___kmpc_push_num_threads", referenced from:
_exec_blas in libopenblas_64.a(blas_server_omp.c.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [test/zblat1] Error 1
make[1]: *** [test/CMakeFiles/zblat1.dir/all] Error 2
Now if I add back in the modification to CMakeLists.txt (see my first post above) and recompile, it will succeed:
/usr/local/bin/gfortran -L/usr/local/opt/libomp/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -fopenmp -Wall -frecursive -fno-optimize-sibling-calls -m64 -fdefault-integer-8 -fopenmp -fPIC -fno-tree-vectorize -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk CMakeFiles/zblat2.dir/zblat2.f.o -o zblat2 ../lib/libopenblas_64.a /usr/local/opt/libomp/lib/libomp.dylib
[ 84%] Built target zblat2
And all the various test cases eventually pass as well:
Right at the end of the command there it seems to be including /usr/local/opt/libomp/lib/libomp.dylib
and that might be solving the issue.
I also saw this in the Makefile, where -lomp
gets tacked on if using clang and gfortran while using -DUSE_OPENMP=1
:
https://github.com/xianyi/OpenBLAS/blob/cbc583eb54647f4fcaa4f0bf3a131d76d8d9c5a3/Makefile#L277-L278
I wonder if my CMake change ends up achieving a similar result, where instead of -lomp
it is just adding /usr/local/opt/libomp/lib/libomp.dylib
directly to the command line.
Note that the llvm
formula includes libomp
at $(brew --prefix llvm)/lib/libomp.dylib
. It may not be the cause of your problems, but it's probably not great for the compiler to have to choose between two different versions of libomp
(and might be what necessitates your having to specify /usr/local/opt/libomp/lib/libomp.dylib
).
I believe the libomp
formula should also work with the Apple Clang -- that's what it's built and tested with.
All I had to do was:
export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib"
Mac M1 SDL2 was the culprit, installed via homebrew; which was not in my library path it seems
I did also ensure the LIBRARY_PATH
was not empty before running the above command.
[[ -z "${LIBRARY_PATH}" ]] && export LIBRARY_PATH=/usr/local/lib
This might be aesthetic (I'm not sure); but it does prevent unset LIBRARY_PATH materialising :/opt/homebrew/lib
vs /opt/homebrew/lib
I have a bit of an odd setup here probably, but I'm compiling on MacOS using Homebrew's clang rather than the system clang due to lack of OpenMP support:
I have OpenMP installed through Homebrew as well:
To compile, I run:
I would end up with compile errors, saying it could not find some symbols related to OpenMP, until I added the following to OpenBLAS's CMakeLists.txt:
Then it compiled successfully, and all test cases passed (though I do not know if the test cases include OpenMP tests...)
Any idea if this is the correct approach here, or might there be another solution that doesn't involve modifying CMakeLists.txt directly?