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

Cannot build with OpenBLAS due to missing -lpthread #63

Open
TiborGY opened this issue Apr 15, 2022 · 5 comments
Open

Cannot build with OpenBLAS due to missing -lpthread #63

TiborGY opened this issue Apr 15, 2022 · 5 comments

Comments

@TiborGY
Copy link

TiborGY commented Apr 15, 2022

Building Scalapack with OpenBLAS as the optimized BLAS/LAPACK library fails, because OpenBLAS builds demand that pthread is linked, unless OpenBLAS has been built without its default shared-memory threading enabled. See below for abridged build log.

This is probably something CMake could detect, based on the build information that OpenBLAS makes available about itself, or just detect OpenBLAS and always tack on -lpthread.

~/nfs_zpool/scalapack$ cmake . -D LAPACK_LIBRARIES=$OPENBLAS_LIB -D BLAS_LIBRARIES=$OPENBLAS_LIB
-- The C compiler identification is GNU 9.4.0
-- The Fortran compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/gfortran - skipped
-- Found MPI_C: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so (found version "3.1")
-- Found MPI_Fortran: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_usempif08.so (found version "3.1")
-- Found MPI: TRUE (found version "3.1")
-- Found MPI_LIBRARY : TRUE
-- --> MPI C Compiler : /usr/bin/mpicc
-- --> C Compiler : /usr/bin/cc
-- --> MPI Fortran Compiler : /usr/bin/mpif90
-- --> Fortran Compiler : /usr/bin/gfortran
-- Reducing RELEASE optimization level to O2
-- =========
-- Compiling and Building BLACS INSTALL Testing to set correct variables
-- Configure in the INSTALL directory successful
-- Build in the BLACS INSTALL directory successful
-- =========
-- Testing FORTRAN_MANGLING
-- CDEFS set to Add_
-- =========
-- CHECKING BLAS AND LAPACK LIBRARIES
-- --> LAPACK supplied by user is /mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a.
-- Looking for Fortran dgesv
-- Looking for Fortran dgesv - not found
-- --> LAPACK routine dgesv is found: .
-- --> Searching for optimized LAPACK and BLAS libraries on your machine.
-- Found BLAS: /mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a
-- Found LAPACK: /mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a
-- BLAS library: /mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a
-- LAPACK library: /mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a
-- =========
-- Configuring done
-- Generating done
-- Build files have been written to: /home/gytibor/nfs_zpool/scalapack
...
[ 68%] Built target scalapack
Scanning dependencies of target xslu
[ 68%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psludriver.f.o
[ 68%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psluinfo.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psgetrrv.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psmatgen.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/pmatgeninc.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/pslaschk.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/pslafchk.f.o
[ 69%] Linking Fortran executable ../xslu
/usr/bin/ld: /mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a(blas_server.o): undefined reference to symbol 'pthread_setaffinity_np@@GLIBC_2.3.4'
/usr/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [TESTING/LIN/CMakeFiles/xslu.dir/build.make:193: TESTING/xslu] Error 1
make[1]: *** [CMakeFiles/Makefile2:1260: TESTING/LIN/CMakeFiles/xslu.dir/all] Error 2
make: *** [Makefile:166: all] Error 2
@weslleyspereira
Copy link
Collaborator

Hi. What is the content of OPENBLAS_LIB ? Could you please try the following:

$ export BLAS_LIB="$OPENBLAS_LIB -lpthread"
$ export LAPACK_LIB="$OPENBLAS_LIB -lpthread"
$ cmake . -D LAPACK_LIBRARIES=$LAPACK_LIB -D BLAS_LIBRARIES=$BLAS_LIB

As far as I understand, BLAS_LIBRARIES and LAPACK_LIBRARIES should contain all libraries needed for the optimized BLAS and LAPACK libraries to work.

@TiborGY TiborGY closed this as completed Apr 15, 2022
@TiborGY TiborGY reopened this Apr 15, 2022
@TiborGY
Copy link
Author

TiborGY commented Apr 15, 2022

Hi. What is the content of OPENBLAS_LIB ?

~/nfs_zpool/scalapack$ echo $OPENBLAS_LIB
/mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a

Could you please try the following:

$ export BLAS_LIB="$OPENBLAS_LIB -lpthread"
$ export LAPACK_LIB="$OPENBLAS_LIB -lpthread"
$ cmake . -D LAPACK_LIBRARIES=$LAPACK_LIB -D BLAS_LIBRARIES=$BLAS_LIB

Does not work, cmake tries to interpret it instead of treating it as a string:

~/nfs_zpool/scalapack$ cmake . -D LAPACK_LIBRARIES=$LAPACK_LIB -D BLAS_LIBRARIES=$BLAS_LIB
CMake Error: Unknown argument -lpthread
CMake Error: Run 'cmake --help' for all supported options.

@weslleyspereira
Copy link
Collaborator

I'm sorry. We're missing the double quotes. So:

$ cmake . -D LAPACK_LIBRARIES="$LAPACK_LIB" -D BLAS_LIBRARIES="$BLAS_LIB"

If it still does not work, I would replace -lpthread by the complete path for the pthread library.

This is what I would do. If it does not work, I can install OpenBLAS to try to help you.

@TiborGY
Copy link
Author

TiborGY commented Apr 15, 2022

Defining the variables like this leads to other issues, CMake generates an invalid Makefile, where the name of the target includes the path to the BLAS lib.

[ 68%] Built target scalapack
Scanning dependencies of target xslu
[ 68%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psludriver.f.o
[ 68%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psluinfo.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psgetrrv.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/psmatgen.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/pmatgeninc.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/pslaschk.f.o
[ 69%] Building Fortran object TESTING/LIN/CMakeFiles/xslu.dir/pslafchk.f.o
make[2]: *** No rule to make target '/mnt/nfsroot/libs/OpenBLAS_latest_zen/lib/libopenblas.a -lpthread', needed by 'TESTING/xslu'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:1260: TESTING/LIN/CMakeFiles/xslu.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

@weslleyspereira
Copy link
Collaborator

Thanks for the attempts. I've come up with a simple solution:

cmake -D USE_OPTIMIZED_LAPACK_BLAS=ON -D BLA_VENDOR=OpenBLAS .. # configure step
cmake --build build # build step

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

No branches or pull requests

2 participants