Skip to content

Commit

Permalink
Add support for BLAS/LAPACK ILP64 libraries (grimme-lab#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmejiar authored Jun 15, 2022
1 parent 98a11ac commit 4281891
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 151 deletions.
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ if(NOT TARGET "OpenMP::OpenMP_Fortran" AND WITH_OpenMP)
find_package("OpenMP" REQUIRED)
endif()

if(WITH_ILP64)
message(STATUS "Using LAPACK/BLAS ILP64 interface")
endif()

if(NOT TARGET "LAPACK::LAPACK")
find_package("custom-lapack" REQUIRED)
endif()
Expand All @@ -42,7 +46,7 @@ if(NOT TARGET "mctc-lib::mctc-lib")
find_package("mctc-lib" REQUIRED)
endif()

if(NOT TARGET "mstore::mstore")
if(NOT TARGET "mstore::mstore" AND WITH_TESTS)
find_package("mstore")
endif()

Expand Down Expand Up @@ -83,6 +87,17 @@ if(WITH_OpenMP)
"OpenMP::OpenMP_Fortran"
)
endif()
if(WITH_ILP64)
target_compile_definitions(
"${PROJECT_NAME}-lib"
PUBLIC -DIK=i8
)
else()
target_compile_definitions(
"${PROJECT_NAME}-lib"
PUBLIC -DIK=i4
)
endif()
target_include_directories(
"${PROJECT_NAME}-lib"
PUBLIC
Expand Down Expand Up @@ -126,5 +141,7 @@ install(
)

# add the testsuite
enable_testing()
add_subdirectory("test")
if(WITH_TESTS)
enable_testing()
add_subdirectory("test")
endif()
7 changes: 5 additions & 2 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
# limitations under the License.

option(BUILD_SHARED_LIBS "Whether the libraries built should be shared" FALSE)

option(WITH_OpenMP "Enable support for shared memory parallelisation with OpenMP" TRUE)
if(NOT DEFINED "${PROJECT_NAME}-dependeny-method")
option(WITH_ILP64 "Enable support for ILP64 BLAS/LAPACK calls" FALSE)
option(WITH_TESTS "Enable compilation of unit tests" TRUE)


if(NOT DEFINED "${PROJECT_NAME}-dependency-method")
set(
"${PROJECT_NAME}-dependency-method"
"subproject" "cmake" "pkgconf" "fetch"
Expand Down
8 changes: 8 additions & 0 deletions config/cmake/Findcustom-blas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if ((BLA_VENDOR MATCHES ^Intel) OR (DEFINED ENV{MKLROOT}))
enable_language("C")
endif()

if(WITH_ILP64)
set(BLA_SIZEOF_INTEGER 8)
endif()

if(NOT BLAS_FOUND)
find_package("BLAS")
if(NOT TARGET "BLAS::BLAS")
Expand Down
8 changes: 8 additions & 0 deletions config/cmake/Findcustom-lapack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if ((BLA_VENDOR MATCHES ^Intel) OR (DEFINED ENV{MKLROOT}))
enable_language("C")
endif()

if(WITH_ILP64)
set(BLA_SIZEOF_INTEGER 8)
endif()

if(NOT LAPACK_FOUND)
find_package("LAPACK")

Expand Down
51 changes: 38 additions & 13 deletions config/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,27 @@ if lapack_vendor == 'auto'
endif
endif

if get_option('ilp64')
ilp64 = true
add_project_arguments('-DIK=i8', language:'fortran')
else
add_project_arguments('-DIK=i4', language:'fortran')
ilp64 = false
endif

if lapack_vendor == 'mkl'
mkl_dep = []
cc = fc
if add_languages('c', required: false, native: false)
cc = meson.get_compiler('c')
endif
if fc_id == 'intel'
mkl_dep += cc.find_library('mkl_intel_lp64')
mkl_dep += cc.find_library(ilp64 ? 'mkl_intel_ilp64' : 'mkl_intel_lp64')
if get_option('openmp')
mkl_dep += cc.find_library('mkl_intel_thread')
endif
elif fc_id == 'gcc'
mkl_dep += cc.find_library('mkl_gf_lp64')
mkl_dep += cc.find_library(ilp64 ? 'mkl_gf_ilp64' : 'mkl_gf_lp64')
if get_option('openmp')
mkl_dep += cc.find_library('mkl_gnu_thread')
endif
Expand All @@ -79,33 +87,50 @@ elif lapack_vendor == 'mkl-rt'
lib_deps += mkl_dep

elif lapack_vendor == 'openblas'
openblas_dep = dependency('openblas', required: false)
openblas_dep = dependency(ilp64 ? 'openblas64' : 'openblas', required: false)
if not openblas_dep.found()
openblas_dep = fc.find_library('openblas')
openblas_dep = fc.find_library(ilp64 ? 'openblas64' : 'openblas')
endif
lib_deps += openblas_dep
if not fc.links('external dsytrs; call dsytrs(); end', dependencies: openblas_dep)
lapack_dep = dependency('lapack', required: false)
lapack_dep = dependency(ilp64 ? 'lapack64' : 'lapack', required: false)
if not lapack_dep.found()
lapack_dep = fc.find_library('lapack')
lapack_dep = fc.find_library(ilp64 ? 'lapack64' : 'lapack')
endif
lib_deps += lapack_dep
endif

elif lapack_vendor == 'custom'
foreach lib: get_option('custom_libraries')
lib_deps += fc.find_library(lib)
endforeach
custom_deps = []
libs = get_option('custom_libraries')
if libs[0].startswith('-L')
foreach lib: libs
if lib != libs[0]
custom_deps += fc.find_library(lib, dirs: libs[0].substring(2))
endif
endforeach
else
foreach lib: libs
custom_deps += fc.find_library(lib)
endforeach
endif
if (not fc.links('external dsytrs; call dsytrs(); end', dependencies: [custom_deps,omp_dep]))
error('Custom LAPACK libraries do not link')
elif (not fc.links('external dsytrs; call dgemm(); end', dependencies: [custom_deps,omp_dep]))
error('Custom BLAS libraries do not link')
endif
lib_deps += custom_deps


else
lapack_dep = dependency('lapack', required: false)
lapack_dep = dependency(ilp64 ? 'lapack64' : 'lapack', required: false)
if not lapack_dep.found()
lapack_dep = fc.find_library('lapack')
lapack_dep = fc.find_library(ilp64 ? 'lapack64' : 'lapack')
endif
lib_deps += lapack_dep
blas_dep = dependency('blas', required: false)
blas_dep = dependency(ilp64 ? 'blas64' : 'blas', required: false)
if not blas_dep.found()
blas_dep = fc.find_library('blas')
blas_dep = fc.find_library(ilp64 ? 'blas64' : 'blas')
endif
lib_deps += blas_dep
endif
Expand Down
8 changes: 8 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ option(
yield: true,
description: 'use OpenMP parallelisation',
)

option(
'ilp64',
type: 'boolean',
value: false,
yield: true,
description: 'enable ILP64 LAPACK/BLAS',
)
6 changes: 3 additions & 3 deletions src/multicharge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ set(dir "${CMAKE_CURRENT_SOURCE_DIR}")

list(
APPEND srcs
"${dir}/blas.f90"
"${dir}/blas.F90"
"${dir}/cutoff.f90"
"${dir}/data.f90"
"${dir}/ewald.f90"
"${dir}/lapack.f90"
"${dir}/model.f90"
"${dir}/lapack.F90"
"${dir}/model.F90"
"${dir}/ncoord.f90"
"${dir}/output.f90"
"${dir}/param.f90"
Expand Down
Loading

0 comments on commit 4281891

Please sign in to comment.