From 36d0ec4aad150e807c53b940aa05ac28f256ab06 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Wed, 21 Feb 2024 14:27:31 +0100 Subject: [PATCH 1/8] CMake implementation Signed-off-by: Cristian Le --- .gitignore | 42 ++-- CMakeLists.txt | 172 +++++++++++++++ CMakePresets.json | 7 + cmake/CMakePresets-CI.json | 197 ++++++++++++++++++ cmake/CMakePresets-defaults.json | 107 ++++++++++ cmake/Wannier90Config.cmake.in | 8 + cmake/wannier90.pc.in | 9 + src/CMakeLists.txt | 63 ++++++ src/postw90/CMakeLists.txt | 32 +++ test-suite/CMakeLists.txt | 132 ++++++++++++ test-suite/libv2-demo/CMakeLists.txt | 20 ++ .../lib-gas-opt-pllel/CMakeLists.txt | 7 + .../libc-gas-mix-serial-clash/CMakeLists.txt | 7 + .../libc-gas-mix-serial/CMakeLists.txt | 7 + .../libc-gas-opt-pllel-random/CMakeLists.txt | 7 + test-suite/tests/CMakeLists.txt | 97 +++++++++ 16 files changed, 902 insertions(+), 12 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 CMakePresets.json create mode 100644 cmake/CMakePresets-CI.json create mode 100644 cmake/CMakePresets-defaults.json create mode 100644 cmake/Wannier90Config.cmake.in create mode 100644 cmake/wannier90.pc.in create mode 100644 src/CMakeLists.txt create mode 100644 src/postw90/CMakeLists.txt create mode 100644 test-suite/CMakeLists.txt create mode 100644 test-suite/libv2-demo/CMakeLists.txt create mode 100644 test-suite/libv2-demo/lib-gas-opt-pllel/CMakeLists.txt create mode 100644 test-suite/libv2-demo/libc-gas-mix-serial-clash/CMakeLists.txt create mode 100644 test-suite/libv2-demo/libc-gas-mix-serial/CMakeLists.txt create mode 100644 test-suite/libv2-demo/libc-gas-opt-pllel-random/CMakeLists.txt create mode 100644 test-suite/tests/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 4e7318d5a..f3d70e966 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,31 @@ -wannier90.x -postw90.x -.DS_Store -make.inc -w90chk2chk.x -w90spn2spn.x -libwannier.a -libwan2.a -libwannier.so -libwannier.dylib -*~ -*.x.dSYM +### Build system +cmake-build-*/ +build/ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + + +### Other +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +### IDE files .vscode +/.idea + +### Project files +/CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..1bf38ff6a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,172 @@ +cmake_minimum_required(VERSION 3.25...3.29) + +#[=============================================================================[ +# Basic project definition # +]=============================================================================] + +list(APPEND CMAKE_MESSAGE_CONTEXT Wannier90) +project(Wannier90 + VERSION 4.0.0 + DESCRIPTION "Compute maximally-localised Wannier functions." + HOMEPAGE_URL https://www.wannier90.org + LANGUAGES Fortran C + ) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif () + +#[=============================================================================[ +# Options # +]=============================================================================] + +option(WANNIER90_MPI "Wannier90: Build with MPI support" OFF) +option(WANNIER90_SHARED_LIBS "Wannier90: Build library as a shared library" ${PROJECT_IS_TOP_LEVEL}) +option(WANNIER90_INSTALL "Wannier90: Install files" ${PROJECT_IS_TOP_LEVEL}) +option(WANNIER90_TEST "Wannier90: Build test-suite" ${PROJECT_IS_TOP_LEVEL}) + +#[=============================================================================[ +# Project configuration # +]=============================================================================] + +if (NOT CMAKE_Fortran_MODULE_DIRECTORY) + set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fortran_mods) +endif () +set(BUILD_SHARED_LIBS ${WANNIER90_SHARED_LIBS}) + +if (WANNIER90_INSTALL) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + + # CMake does not properly support fortran module installation paths. + # Adapting the standard from fortran-stdlib + # https://gitlab.kitware.com/cmake/cmake/-/issues/19608 + # https://discourse.cmake.org/t/api-design-c-modules-source-listings-and-interface-properties/5389/14 + cmake_path(APPEND CMAKE_INSTALL_INCLUDEDIR ${PROJECT_NAME} "${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" + OUTPUT_VARIABLE _DEFAULT_CMAKE_INSTALL_MODULEDIR + ) + set(CMAKE_INSTALL_MODULEDIR ${_DEFAULT_CMAKE_INSTALL_MODULEDIR} + CACHE STRING + "Fortran module installation path (Not a cmake native variable)" + ) + cmake_path(IS_ABSOLUTE CMAKE_INSTALL_MODULEDIR _is_absolute) + if (_is_absolute) + set(CMAKE_INSTALL_FULL_MODULEDIR ${CMAKE_INSTALL_MODULEDIR}) + else () + cmake_path(APPEND CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_MODULEDIR} + OUTPUT_VARIABLE CMAKE_INSTALL_FULL_MODULEDIR + ) + endif () +endif () + +## Populate variables for FetchContent and sub-projects +# All variables have to be consistent with CMakeExtraUtilsConfig.cmake +set(Wannier90_MPI ${WANNIER90_WITH_MPI}) + +#[=============================================================================[ +# External packages # +]=============================================================================] + +## Third-party libraries +find_package(BLAS REQUIRED) +find_package(LAPACK REQUIRED) +if (WANNIER90_MPI) + find_package(MPI REQUIRED) +endif () + +#[=============================================================================[ +# Main definition # +]=============================================================================] + +## Main targets +add_executable(Wannier90_exe) +set_target_properties(Wannier90_exe PROPERTIES + OUTPUT_NAME wannier90.x + EXPORT_NAME exe +) +add_executable(Wannier90::exe ALIAS Wannier90_exe) +add_executable(Wannier90_post) +set_target_properties(Wannier90_post PROPERTIES + OUTPUT_NAME postw90.x + EXPORT_NAME post +) +add_executable(Wannier90::post ALIAS Wannier90_post) +add_library(Wannier90_lib) +set_target_properties(Wannier90_lib PROPERTIES + OUTPUT_NAME wannier90 + EXPORT_NAME wannier90 + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR} +) +add_library(Wannier90::wannier90 ALIAS Wannier90_lib) + +## Main implementations +add_subdirectory(src) + +## Testing +if (WANNIER90_TEST) + enable_testing() + ## Define compiled support programs + # TODO: These should be moved outside of src and hard coded path? + add_executable(w90chk2chk.x src/w90chk2chk.F90) + add_executable(w90spn2spn.x src/w90spn2spn.F90) + target_link_libraries(w90chk2chk.x PRIVATE Wannier90_lib) + target_link_libraries(w90spn2spn.x PRIVATE Wannier90_lib) + + add_subdirectory(test-suite) +endif () + +#[=============================================================================[ +# Install or Export # +]=============================================================================] + +## Installs +if (WANNIER90_INSTALL) + configure_file(cmake/wannier90.pc.in wannier90.pc) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/wannier90.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + COMPONENT Wannier90_Development + ) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/Wannier90ConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion + ) + configure_package_config_file( + cmake/Wannier90Config.cmake.in + Wannier90Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Wannier90 + ) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Wannier90ConfigVersion.cmake + ${CMAKE_CURRENT_BINARY_DIR}/Wannier90Config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Wannier90 + COMPONENT Spglib_Development + ) + install(EXPORT Wannier90Targets + FILE Wannier90Targets.cmake + NAMESPACE Wannier90:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Wannier90 + COMPONENT Wannier90_Development + ) + export(EXPORT Wannier90Targets + FILE Wannier90Targets.cmake + NAMESPACE Wannier90:: + ) +endif () + +## Make project available to FetchContent +if (NOT PROJECT_IS_TOP_LEVEL) + # Propagate variables for FetchContent + return(PROPAGATE + Wannier90_VERSION + Wannier90_VERSION_MAJOR + Wannier90_VERSION_MINOR + Wannier90_VERSION_PATCH + Wannier90_VERSION_TWEAK + Wannier90_MPI + ) +endif () diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..51696d4ed --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,7 @@ +{ + "version": 6, + "include": [ + "cmake/CMakePresets-defaults.json", + "cmake/CMakePresets-CI.json" + ] +} diff --git a/cmake/CMakePresets-CI.json b/cmake/CMakePresets-CI.json new file mode 100644 index 000000000..e13a93677 --- /dev/null +++ b/cmake/CMakePresets-CI.json @@ -0,0 +1,197 @@ +{ + "version": 6, + "include": [ + "CMakePresets-defaults.json" + ], + "configurePresets": [ + { + "name": "ci-base", + "hidden": true, + "generator": "Ninja", + "inherits": [ + "default" + ], + "cacheVariables": { + "WANNIER90_TEST": { + "type": "BOOL", + "value": true + }, + "WANNIER90_MPI": { + "type": "BOOL", + "value": "$env{WITH_MPI}" + } + }, + "errors": { + "deprecated": true + } + }, + { + "name": "gcc-ci", + "displayName": "CI - GCC toolchain", + "inherits": [ + "ci-base" + ], + "binaryDir": "cmake-build-ci-gcc", + "cacheVariables": { + "CMAKE_Fortran_COMPILER": { + "type": "FILEPATH", + "value": "gfortran" + } + } + }, + { + "name": "llvm-ci", + "displayName": "CI - LLVM toolchain", + "inherits": [ + "ci-base" + ], + "binaryDir": "cmake-build-ci-llvm", + "cacheVariables": { + "CMAKE_Fortran_COMPILER": { + "type": "FILEPATH", + "value": "flang-new" + } + } + }, + { + "name": "intel-ci", + "displayName": "CI - Intel toolchain", + "inherits": [ + "ci-base" + ], + "binaryDir": "cmake-build-ci-intel", + "cacheVariables": { + "CMAKE_Fortran_COMPILER": { + "type": "FILEPATH", + "value": "ifx" + } + } + } + ], + "buildPresets": [ + { + "name": "ci-base", + "hidden": true, + "inherits": [ + "default" + ], + "cleanFirst": true + }, + { + "name": "gcc-ci", + "displayName": "CI - GCC toolchain", + "inherits": [ + "ci-base" + ], + "configurePreset": "gcc-ci" + }, + { + "name": "llvm-ci", + "displayName": "CI - LLVM toolchain", + "inherits": [ + "ci-base" + ], + "configurePreset": "llvm-ci" + }, + { + "name": "intel-ci", + "displayName": "CI - Intel toolchain", + "inherits": [ + "ci-base" + ], + "configurePreset": "intel-ci" + } + ], + "testPresets": [ + { + "name": "ci-base", + "hidden": true, + "inherits": [ + "default" + ], + "output": { + "outputOnFailure": true + } + }, + { + "name": "gcc-ci", + "displayName": "CI - GCC toolchain", + "inherits": [ + "ci-base" + ], + "configurePreset": "gcc-ci" + }, + { + "name": "llvm-ci", + "displayName": "CI - LLVM toolchain", + "inherits": [ + "ci-base" + ], + "configurePreset": "llvm-ci" + }, + { + "name": "intel-ci", + "displayName": "CI - Intel toolchain", + "inherits": [ + "ci-base" + ], + "configurePreset": "intel-ci" + } + ], + "workflowPresets": [ + { + "name": "gcc-ci", + "displayName": "CI - GCC toolchain", + "steps": [ + { + "type": "configure", + "name": "gcc-ci" + }, + { + "type": "build", + "name": "gcc-ci" + }, + { + "type": "test", + "name": "gcc-ci" + } + ] + }, + { + "name": "llvm-ci", + "displayName": "CI - LLVM toolchain", + "steps": [ + { + "type": "configure", + "name": "llvm-ci" + }, + { + "type": "build", + "name": "llvm-ci" + }, + { + "type": "test", + "name": "llvm-ci" + } + ] + }, + { + "name": "intel-ci", + "displayName": "CI - Intel toolchain", + "steps": [ + { + "type": "configure", + "name": "intel-ci" + }, + { + "type": "build", + "name": "intel-ci" + }, + { + "type": "test", + "name": "intel-ci" + } + ] + } + ] +} diff --git a/cmake/CMakePresets-defaults.json b/cmake/CMakePresets-defaults.json new file mode 100644 index 000000000..49391e26b --- /dev/null +++ b/cmake/CMakePresets-defaults.json @@ -0,0 +1,107 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "default", + "displayName": "Default preset", + "binaryDir": "cmake-build-release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": { + "type": "STRING", + "value": "Release" + }, + "CMAKE_MESSAGE_CONTEXT_SHOW": { + "type": "BOOL", + "value": true + } + } + }, + { + "name": "_mpi", + "hidden": true, + "cacheVariables": { + "WANNIER90_MPI": { + "type": "BOOL", + "value": true + } + } + }, + { + "name": "mpi", + "displayName": "MPI preset", + "binaryDir": "cmake-build-mpi", + "inherits": [ + "_mpi", + "default" + ] + } + ], + "buildPresets": [ + { + "name": "default", + "displayName": "Default preset", + "configurePreset": "default" + }, + { + "name": "mpi", + "displayName": "MPI preset", + "configurePreset": "mpi", + "inherits": [ + "default" + ] + } + ], + "testPresets": [ + { + "name": "default", + "displayName": "Default preset", + "configurePreset": "default" + }, + { + "name": "mpi", + "displayName": "MPI preset", + "configurePreset": "mpi", + "inherits": [ + "default" + ] + } + ], + "workflowPresets": [ + { + "name": "default", + "displayName": "Default workflow", + "steps": [ + { + "type": "configure", + "name": "default" + }, + { + "type": "build", + "name": "default" + }, + { + "type": "test", + "name": "default" + } + ] + }, + { + "name": "mpi", + "displayName": "MPI workflow", + "steps": [ + { + "type": "configure", + "name": "mpi" + }, + { + "type": "build", + "name": "mpi" + }, + { + "type": "test", + "name": "mpi" + } + ] + } + ] +} diff --git a/cmake/Wannier90Config.cmake.in b/cmake/Wannier90Config.cmake.in new file mode 100644 index 000000000..af6ec851c --- /dev/null +++ b/cmake/Wannier90Config.cmake.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ + + +## Define basic variables +set(Wannier90_MPI @WANNIER90_MPI@) + +## Parse find_package request +include(${CMAKE_CURRENT_LIST_DIR}/Wannier90Targets.cmake) diff --git a/cmake/wannier90.pc.in b/cmake/wannier90.pc.in new file mode 100644 index 000000000..e1fdf3e8b --- /dev/null +++ b/cmake/wannier90.pc.in @@ -0,0 +1,9 @@ +prefix: @CMAKE_INSTALL_PREFIX@ + +Name: wannier +Version: @PROJECT_VERSION@ +Description: @PROJECT_DESCRIPTION@ +URL: @PROJECT_HOMEPAGE_URL@ + +Cflags: -I@CMAKE_INSTALL_FULL_MODULEDIR@ -I@CMAKE_INSTALL_FULL_INCLUDEDIR@ +Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lwannier90 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..e586473e1 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,63 @@ +## Source files definitions +target_sources(Wannier90_lib PRIVATE + comms.F90 + constants.F90 + disentangle.F90 + error.F90 + error_base.F90 + hamiltonian.F90 + io.F90 + kmesh.F90 + library_interface.F90 + overlap.F90 + plot.F90 + readwrite.F90 + sitesym.F90 + transport.F90 + types.F90 + utility.F90 + wannier90_readwrite.F90 + wannier90_types.F90 + wannierise.F90 + ws_distance.F90 + ) +target_sources(Wannier90_exe PRIVATE + wannier_prog.F90 + ) + +## Linking targets +target_link_libraries(Wannier90_exe PRIVATE + Wannier90_lib +) +target_link_libraries(Wannier90_lib PRIVATE + BLAS::BLAS LAPACK::LAPACK +) +target_include_directories(Wannier90_lib PUBLIC + "$" + "$" + "$" +) +target_sources(Wannier90_lib INTERFACE + FILE_SET wannier90_C_Headers TYPE HEADERS FILES wannier90.hh +) +if (WANNIER90_MPI) + target_link_libraries(Wannier90_lib PRIVATE MPI::MPI_Fortran) +endif () + +add_subdirectory(postw90) + +## Installs +if (WANNIER90_INSTALL) + install(TARGETS Wannier90_lib Wannier90_exe + EXPORT Wannier90Targets + LIBRARY COMPONENT Wannier90_Runtime NAMELINK_COMPONENT Wannier90_Development + ARCHIVE COMPONENT Wannier90_Development + PUBLIC_HEADER COMPONENT Wannier90_Development + RUNTIME COMPONENT Wannier90_Runtime + FILE_SET wannier90_C_Headers COMPONENT Wannier90_Development + ) + install(FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/w90_library.mod + DESTINATION ${CMAKE_INSTALL_MODULEDIR} + COMPONENT Wannier90_Development + ) +endif () diff --git a/src/postw90/CMakeLists.txt b/src/postw90/CMakeLists.txt new file mode 100644 index 000000000..e2a4facab --- /dev/null +++ b/src/postw90/CMakeLists.txt @@ -0,0 +1,32 @@ +target_sources(Wannier90_post PRIVATE + postw90.F90 + ) +target_sources(Wannier90_lib PRIVATE + berry.F90 + boltzwann.F90 + dos.F90 + geninterp.F90 + get_oper.F90 + gyrotropic.F90 + kpath.F90 + kslice.F90 + postw90.F90 + postw90_common.F90 + postw90_readwrite.F90 + postw90_types.F90 + spin.F90 + wan_ham.F90 + ) +target_link_libraries(Wannier90_post PRIVATE + Wannier90_lib BLAS::BLAS LAPACK::LAPACK) + +## Installs +if (WANNIER90_INSTALL) + install(TARGETS Wannier90_post + EXPORT Wannier90Targets + LIBRARY COMPONENT Wannier90_Runtime NAMELINK_COMPONENT Wannier90_Development + ARCHIVE COMPONENT Wannier90_Development + PUBLIC_HEADER COMPONENT Wannier90_Development + RUNTIME COMPONENT Wannier90_Runtime + ) +endif () diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt new file mode 100644 index 000000000..2e0a2addf --- /dev/null +++ b/test-suite/CMakeLists.txt @@ -0,0 +1,132 @@ +cmake_minimum_required(VERSION 3.25...3.29) + +#[=============================================================================[ +# Basic project definition # +]=============================================================================] + +list(APPEND CMAKE_MESSAGE_CONTEXT Test) +project(Wannier90_test + LANGUAGES CXX Fortran +) + +enable_testing() + +#[=============================================================================[ +# Options # +]=============================================================================] + +#[=============================================================================[ +# Project configuration # +]=============================================================================] + +#[=============================================================================[ +# External packages # +]=============================================================================] + +find_package(Python 3.8 REQUIRED) + +#[=============================================================================[ +# Main definition # +]=============================================================================] + +function(Wannier90_add_test test) + #[===[.md + # Wannier90_add_test + + Internal helper for adding functional tests specific for Wannier90 + + ## Synopsis + ```cmake + Wannier90_add_test( + [TEST_NAME ] + [LABELS ] + [TEST_COMMAND ] + ) + ``` + + ## Options + + : `` + Path to the CMake project to be executed relative to `${CMAKE_CURRENT_SOURCE_DIR}` + + : `TEST_NAME` [Default: ``] + Name for the test to be used as the ctest name + + : `LABELS` + Additional labels to be added + + : `TEST_COMMAND` [Default: ctest] + Test command to use instead of ctest + + ]===] + + list(APPEND CMAKE_MESSAGE_CONTEXT "Wannier90_add_test") + + set(ARGS_Options) + set(ARGS_OneValue + TEST_NAME + ) + set(ARGS_MultiValue + LABELS + TEST_COMMAND + ) + cmake_parse_arguments(PARSE_ARGV 1 ARGS "${ARGS_Options}" "${ARGS_OneValue}" "${ARGS_MultiValue}") + # Check required/optional arguments + if (ARGC LESS 1) + message(FATAL_ERROR "Missing test name") + endif () + if (NOT DEFINED ARGS_TEST_NAME) + set(ARGS_TEST_NAME ${test}) + endif () + if (NOT DEFINED ARGS_TEST_COMMAND) + set(ARGS_TEST_COMMAND + ${CMAKE_CTEST_COMMAND} --test-dir ${CMAKE_CURRENT_BINARY_DIR}/${test} --output-on-failure + ) + endif () + + set(extra_args) + if (Wannier90_IS_TOP_LEVEL) + list(APPEND extra_args + -DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS + # Generated Config file point to binary targets until it is installed + -DWannier90_ROOT=${Wannier90_BINARY_DIR} + -DFETCHCONTENT_SOURCE_DIR_WANNIER90=${Wannier90_SOURCE_DIR} + ) + endif () + set(compiler_args) + foreach (lang IN ITEMS CXX Fortran) + if (DEFINED CMAKE_${lang}_COMPILER) + list(APPEND compiler_args -DCMAKE_${lang}_COMPILER=${CMAKE_${lang}_COMPILER}) + endif () + endforeach () + + add_test(NAME ${ARGS_TEST_NAME} + COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/${test} + ${CMAKE_CURRENT_BINARY_DIR}/${test} + # Use the same build environment as the current runner + --build-generator "${CMAKE_GENERATOR}" + --build-options + ${compiler_args} ${extra_args} + --test-command ${ARGS_TEST_COMMAND} + ) + set_tests_properties(${ARGS_TEST_NAME} PROPERTIES + LABELS "${ARGS_LABELS}" + ) +endfunction() + +## Prepare test environment +foreach (extra_file IN ITEMS + checkpoints + run_tests + testcode + tests + tools +) + # TODO: Use `PYTHONPATH` to avoid needing to copy and setting workdir + file(COPY ${extra_file} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endforeach () + +## Add unit tests +add_subdirectory(tests) +## Add functional tests +add_subdirectory(libv2-demo) diff --git a/test-suite/libv2-demo/CMakeLists.txt b/test-suite/libv2-demo/CMakeLists.txt new file mode 100644 index 000000000..dfdc9654b --- /dev/null +++ b/test-suite/libv2-demo/CMakeLists.txt @@ -0,0 +1,20 @@ +set_property(DIRECTORY APPEND + PROPERTY LABELS functional library +) + +set(test_names + lib-gas-opt-pllel + libc-gas-mix-serial + libc-gas-mix-serial-clash +) +if (Wannier90_MPI) + list(APPEND test_names + libc-gas-opt-pllel-random + ) +endif () + +foreach (test IN LISTS test_names) + Wannier90_add_test(${test} + TEST_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test}/demo + ) +endforeach () diff --git a/test-suite/libv2-demo/lib-gas-opt-pllel/CMakeLists.txt b/test-suite/libv2-demo/lib-gas-opt-pllel/CMakeLists.txt new file mode 100644 index 000000000..c29fffba1 --- /dev/null +++ b/test-suite/libv2-demo/lib-gas-opt-pllel/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(demo_Wannier90 LANGUAGES Fortran) + +find_package(Wannier90 REQUIRED) + +add_executable(demo demo.f90) +target_link_libraries(demo PRIVATE Wannier90::wannier90) diff --git a/test-suite/libv2-demo/libc-gas-mix-serial-clash/CMakeLists.txt b/test-suite/libv2-demo/libc-gas-mix-serial-clash/CMakeLists.txt new file mode 100644 index 000000000..7cf325790 --- /dev/null +++ b/test-suite/libv2-demo/libc-gas-mix-serial-clash/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(demo_Wannier90 LANGUAGES CXX) + +find_package(Wannier90 REQUIRED) + +add_executable(demo demo.cc wannier.cc) +target_link_libraries(demo PRIVATE Wannier90::wannier90) diff --git a/test-suite/libv2-demo/libc-gas-mix-serial/CMakeLists.txt b/test-suite/libv2-demo/libc-gas-mix-serial/CMakeLists.txt new file mode 100644 index 000000000..7cf325790 --- /dev/null +++ b/test-suite/libv2-demo/libc-gas-mix-serial/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(demo_Wannier90 LANGUAGES CXX) + +find_package(Wannier90 REQUIRED) + +add_executable(demo demo.cc wannier.cc) +target_link_libraries(demo PRIVATE Wannier90::wannier90) diff --git a/test-suite/libv2-demo/libc-gas-opt-pllel-random/CMakeLists.txt b/test-suite/libv2-demo/libc-gas-opt-pllel-random/CMakeLists.txt new file mode 100644 index 000000000..7cf325790 --- /dev/null +++ b/test-suite/libv2-demo/libc-gas-opt-pllel-random/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(demo_Wannier90 LANGUAGES CXX) + +find_package(Wannier90 REQUIRED) + +add_executable(demo demo.cc wannier.cc) +target_link_libraries(demo PRIVATE Wannier90::wannier90) diff --git a/test-suite/tests/CMakeLists.txt b/test-suite/tests/CMakeLists.txt new file mode 100644 index 000000000..aeb606ac7 --- /dev/null +++ b/test-suite/tests/CMakeLists.txt @@ -0,0 +1,97 @@ +## List tests +set(test_names + testpostw90_boltzwann + testpostw90_example04_dos + testpostw90_example04_pdos + testpostw90_fe_ahc + testpostw90_fe_ahc_adaptandfermi + testpostw90_fe_dos_spin + testpostw90_fe_kpathcurv + testpostw90_fe_kpathmorbcurv + testpostw90_fe_kpathmorbcurv_ws + testpostw90_fe_kslicecurv + testpostw90_fe_kslicemorb + testpostw90_fe_kubo_Axy + testpostw90_fe_kubo_jdos + testpostw90_fe_kubo_Szz + testpostw90_fe_morb + testpostw90_fe_morbandahc + testpostw90_fe_spin + testpostw90_gaas_kdotp + testpostw90_gaas_sc_eta_corr + testpostw90_gaas_sc_xyz + testpostw90_gaas_sc_xyz_scphase2 + testpostw90_gaas_sc_xyz_scphase2_ws + testpostw90_gaas_sc_xyz_ws + testpostw90_gaas_shc + testpostw90_pt_kpathbandsshc + testpostw90_pt_kpathshc + testpostw90_pt_ksliceshc + testpostw90_pt_shc + testpostw90_pt_shc_ryoo + testpostw90_si_geninterp + testpostw90_si_geninterp_wsdistance + testpostw90_te_gyrotropic + testpostw90_te_gyrotropic_C + testpostw90_te_gyrotropic_D0 + testpostw90_te_gyrotropic_dos + testpostw90_te_gyrotropic_Dw + testpostw90_te_gyrotropic_K + testpostw90_te_gyrotropic_NOA + testw90_basic1 + testw90_basic2 + testw90_benzene_gamma_val + testw90_benzene_gamma_val_hexcell + testw90_benzene_gamma_valcond + testw90_bvec + testw90_cube_format + testw90_disentanglement_sawfs + testw90_example01 + testw90_example02 + testw90_example02_restart + testw90_example03 + testw90_example03_labelinfo + testw90_example03_optmem + testw90_example04 + testw90_example05 + testw90_example07 + testw90_example11_1 + testw90_example11_2 + testw90_example21_As_sp + testw90_example26 + testw90_gaas_disentanglement_issue192 + testw90_lavo3_dissphere + testw90_na_chain_gamma + testw90_nnkpt1 + testw90_nnkpt2 + testw90_nnkpt3 + testw90_nnkpt4 + testw90_nnkpt5 + testw90_precond_1 + testw90_precond_2 + testw90_write_u_matrices + testw90_write_u_matrices_disent +) +if (Wannier90_MPI) + list(APPEND test_names + partestw90_mpierr + ) +endif () + +## Define tests +foreach (test IN LISTS test_names) + set(extra_args) + if (Wannier90_MPI) + list(APPEND extra_args -n 2) + set(num_procs 2) + else () + set(num_procs 1) + endif () + add_test(NAME ${test} + COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/../run_tests -c ${test} ${extra_args} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.. + ) + set_tests_properties(${test} PROPERTIES + PROCESSORS ${num_procs} + ) +endforeach () From 46d2fd590ab4ed3041222419a203d410893abc26 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Wed, 21 Feb 2024 09:57:49 +0100 Subject: [PATCH 2/8] Reconfigure GH Actions Signed-off-by: Cristian Le --- .github/workflows/ci.yaml | 51 +++++++++++++ .github/workflows/step_docs.yaml | 28 ++++++++ .github/workflows/step_pre-commit.yaml | 20 ++++++ .../{main.yml => step_test-makefile.yaml} | 36 ++-------- .github/workflows/step_test.yaml | 71 +++++++++++++++++++ 5 files changed, 174 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/step_docs.yaml create mode 100644 .github/workflows/step_pre-commit.yaml rename .github/workflows/{main.yml => step_test-makefile.yaml} (62%) create mode 100644 .github/workflows/step_test.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..3f4e32442 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,51 @@ +name: CI +run-name: > + CI (${{ github.event_name }}) + ${{ github.event_name == 'pull_request' && format('PR#{0}', github.event.number) || '' }} + +on: + workflow_dispatch: + pull_request: + branches: [ develop ] + push: + branches: [ develop ] + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + pre-commit: + name: pre-commit + uses: ./.github/workflows/step_pre-commit.yaml + + tests: + name: test + needs: [ pre-commit ] + uses: ./.github/workflows/step_test.yaml + with: + mask-experimental: ${{ github.event_name == 'push' }} + + tests-makefile: + name: test Makefile + needs: [ pre-commit ] + uses: ./.github/workflows/step_test-makefile.yaml + + docs: + name: ๐Ÿ“˜ docs + needs: [ pre-commit ] + uses: ./.github/workflows/step_docs.yaml + + pass: + name: โœ… Pass + needs: [ pre-commit, tests, tests-makefile, docs ] + runs-on: ubuntu-latest + steps: + - name: Check all CI jobs + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} + if: always() diff --git a/.github/workflows/step_docs.yaml b/.github/workflows/step_docs.yaml new file mode 100644 index 000000000..b3af83feb --- /dev/null +++ b/.github/workflows/step_docs.yaml @@ -0,0 +1,28 @@ +name: ๐Ÿ“˜ test-docs + +on: + workflow_call: + +permissions: + contents: read + +jobs: + docs: + name: Validate mkdocs links + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + # use the latest stable version + python-version: "3.x" + cache: "pip" + # `pybtex` uses `pkg_resources` which is deprecated. Use workaround until upstream `mkdocs_bibtext`decides on a solution + # https://github.com/shyamd/mkdocs-bibtex/issues/228 + # https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with + - run: pip install -r docs/requirements.txt setuptools + - run: mkdocs build --strict + working-directory: ./docs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ENABLE_MKDOCS_GIT_COMMITTERS: False diff --git a/.github/workflows/step_pre-commit.yaml b/.github/workflows/step_pre-commit.yaml new file mode 100644 index 000000000..fbd8b279c --- /dev/null +++ b/.github/workflows/step_pre-commit.yaml @@ -0,0 +1,20 @@ +name: pre-commit + +on: + workflow_call: + +permissions: + contents: read + +jobs: + pre-commit: + name: Check pre-commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/main.yml b/.github/workflows/step_test-makefile.yaml similarity index 62% rename from .github/workflows/main.yml rename to .github/workflows/step_test-makefile.yaml index 4b8520b0a..64d3b1462 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/step_test-makefile.yaml @@ -1,19 +1,11 @@ -name: CI +name: test Makefile on: - pull_request: - push: - branches: - - develop + workflow_call: +permissions: + contents: read jobs: - pre-commit: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.0 - build: runs-on: ubuntu-20.04 strategy: @@ -66,23 +58,3 @@ jobs: path: | test-suite/tests/test*/test.err* test-suite/tests/test*/test.out* - - docs: - name: Validate mkdocs links - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - # use the latest stable version - python-version: "3.x" - cache: "pip" - # `pybtex` uses `pkg_resources` which is deprecated. Use workaround until upstream `mkdocs_bibtext`decides on a solution - # https://github.com/shyamd/mkdocs-bibtex/issues/228 - # https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with - - run: pip install -r docs/requirements.txt setuptools - - run: mkdocs build --strict - working-directory: ./docs - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ENABLE_MKDOCS_GIT_COMMITTERS: False diff --git a/.github/workflows/step_test.yaml b/.github/workflows/step_test.yaml new file mode 100644 index 000000000..162f3815c --- /dev/null +++ b/.github/workflows/step_test.yaml @@ -0,0 +1,71 @@ +name: test + +on: + workflow_call: + inputs: + mask-experimental: + type: boolean + default: true + description: Always report experimental test as successful + +permissions: + contents: read + +jobs: + tests: + name: > + ๐Ÿ–ฅ๏ธ ${{ matrix.os || 'Fedora' }} + ${{ !matrix.os && format('๐Ÿ› ๏ธ {0}', matrix.toolchain) || '' }} + ${{ matrix.mpi && format('๐Ÿ–ง {0}', matrix.mpi) || '' }} + ${{ matrix.experimental && '[๐Ÿงช Experimental]' || '' }} + runs-on: ${{ matrix.os || 'ubuntu-latest' }} + container: ${{ !matrix.os && 'ghcr.io/lecrisut/dev-env:main' || '' }} + continue-on-error: ${{ matrix.experimental || false }} + strategy: + fail-fast: false + matrix: + toolchain: [ gcc, llvm, intel ] + mpi: [false, openmpi, mpich, intel] + include: + # flang is missing features in 16.0.6 + - toolchain: llvm + experimental: true + steps: + - name: Install missing packages + run: dnf install -y bzip2 python-unversioned-command which + - name: Load mpi module ${{ matrix.mpi || '' }} + run: | + # Get interactive profile to be able to load modules + source /etc/profile + + # Save the current environment since we only want the added difference + printenv > orig_env + + # Load the relevant mpi module + module load mpi/${{ matrix.mpi }} + printenv > module_env + + diff orig_env module_env | sed -n 's/> //p' >> $GITHUB_ENV + + # Set MPI flag on + echo "WITH_MPI=ON" >> $GITHUB_ENV + if: matrix.mpi + - name: Enable msvc toolchain on windows + uses: ilammy/msvc-dev-cmd@v1 + if: contains(matrix.os, 'windows') + - name: Activate Intel compilers + # Not elegant, it will propagate all environment variable. + # Intel does not provide a way to output the environment variables to a file + # Note: PATH needs to be exported to GITHUB_PATH otherwise it can be overwritten + run: | + source /opt/intel/oneapi/setvars.sh + printenv >> $GITHUB_ENV + echo $PATH >> $GITHUB_PATH + if: matrix.toolchain == 'intel' + - uses: actions/checkout@v3 + - uses: lukka/get-cmake@latest + - name: Run CMake workflow ${{ matrix.toolchain }}-ci + uses: lukka/run-cmake@v10.3 + with: + workflowPreset: "${{ matrix.toolchain }}-ci" + continue-on-error: ${{ matrix.experimental && inputs.mask-experimental}} From 63a7ebaa7bd81e696edb9c888f46c1a83143d11b Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 22 Feb 2024 11:43:25 +0100 Subject: [PATCH 3/8] [WIP] Fix demo.F90 Signed-off-by: Cristian Le --- test-suite/libv2-demo/CMakeLists.txt | 2 +- .../CMakeLists.txt | 5 +- .../demo.f90 => lib-gas-opt/demo.F90} | 74 +++++++++++-------- .../gaas.amn | 0 .../gaas.eig | 0 .../gaas.mmn | 0 .../makefile | 2 +- 7 files changed, 49 insertions(+), 34 deletions(-) rename test-suite/libv2-demo/{lib-gas-opt-pllel => lib-gas-opt}/CMakeLists.txt (60%) rename test-suite/libv2-demo/{lib-gas-opt-pllel/demo.f90 => lib-gas-opt/demo.F90} (59%) rename test-suite/libv2-demo/{lib-gas-opt-pllel => lib-gas-opt}/gaas.amn (100%) rename test-suite/libv2-demo/{lib-gas-opt-pllel => lib-gas-opt}/gaas.eig (100%) rename test-suite/libv2-demo/{lib-gas-opt-pllel => lib-gas-opt}/gaas.mmn (100%) rename test-suite/libv2-demo/{lib-gas-opt-pllel => lib-gas-opt}/makefile (75%) diff --git a/test-suite/libv2-demo/CMakeLists.txt b/test-suite/libv2-demo/CMakeLists.txt index dfdc9654b..0d4178209 100644 --- a/test-suite/libv2-demo/CMakeLists.txt +++ b/test-suite/libv2-demo/CMakeLists.txt @@ -3,7 +3,7 @@ set_property(DIRECTORY APPEND ) set(test_names - lib-gas-opt-pllel + lib-gas-opt libc-gas-mix-serial libc-gas-mix-serial-clash ) diff --git a/test-suite/libv2-demo/lib-gas-opt-pllel/CMakeLists.txt b/test-suite/libv2-demo/lib-gas-opt/CMakeLists.txt similarity index 60% rename from test-suite/libv2-demo/lib-gas-opt-pllel/CMakeLists.txt rename to test-suite/libv2-demo/lib-gas-opt/CMakeLists.txt index c29fffba1..37ab722a3 100644 --- a/test-suite/libv2-demo/lib-gas-opt-pllel/CMakeLists.txt +++ b/test-suite/libv2-demo/lib-gas-opt/CMakeLists.txt @@ -3,5 +3,8 @@ project(demo_Wannier90 LANGUAGES Fortran) find_package(Wannier90 REQUIRED) -add_executable(demo demo.f90) +add_executable(demo demo.F90) +if (Wannier90_MPI) + target_compile_definitions(demo PRIVATE Wannier90_MPI) +endif () target_link_libraries(demo PRIVATE Wannier90::wannier90) diff --git a/test-suite/libv2-demo/lib-gas-opt-pllel/demo.f90 b/test-suite/libv2-demo/lib-gas-opt/demo.F90 similarity index 59% rename from test-suite/libv2-demo/lib-gas-opt-pllel/demo.f90 rename to test-suite/libv2-demo/lib-gas-opt/demo.F90 index 7743fa5f0..5897c89ac 100644 --- a/test-suite/libv2-demo/lib-gas-opt-pllel/demo.f90 +++ b/test-suite/libv2-demo/lib-gas-opt/demo.F90 @@ -1,5 +1,7 @@ program ok +#ifdef Wannier90_MPI use mpi_f08 +#endif use w90_library implicit none @@ -18,6 +20,11 @@ program ok real(8) :: uccart(3, 3) ! cartesian unit cell type(lib_common_type), target :: w90main +#ifndef Wannier90_MPI + ! MPI dummy + integer :: mpi_comm_world = 0 +#endif + ! collect data nb = 12 nw = 8 @@ -58,10 +65,12 @@ program ok enddo enddo +#ifdef Wannier90_MPI ! setup MPI call mpi_init(ierr) call mpi_comm_size(mpi_comm_world, mpisize, ierr) call mpi_comm_rank(mpi_comm_world, mpirank, ierr) +#endif ! crude k distribution allocate (distk(nk)) @@ -73,57 +82,60 @@ program ok ! wannier interface starts ! stdout/err - call get_fortran_stdout(stdout) - call get_fortran_stderr(stderr) + call w90_get_fortran_stdout(stdout) + call w90_get_fortran_stderr(stderr) ! required settings - call set_option(w90main, 'kpoints', kpt) - call set_option(w90main, 'mp_grid', nkabc) - call set_option(w90main, 'num_bands', nb) - call set_option(w90main, 'num_kpts', nk) - call set_option(w90main, 'num_wann', nw) - call set_option(w90main, 'unit_cell_cart', uccart) + call w90_set_option(w90main, 'kpoints', kpt) + call w90_set_option(w90main, 'mp_grid', nkabc) + call w90_set_option(w90main, 'num_bands', nb) + call w90_set_option(w90main, 'num_kpts', nk) + call w90_set_option(w90main, 'num_wann', nw) + call w90_set_option(w90main, 'unit_cell_cart', uccart) ! optional settings - call set_option(w90main, 'conv_tol', 1.d-13) - call set_option(w90main, 'conv_window', 3) - call set_option(w90main, 'dis_froz_max', 14.0d0) - call set_option(w90main, 'dis_mix_ratio', 1.d0) - call set_option(w90main, 'dis_num_iter', 1200) - call set_option(w90main, 'distk', distk) - call set_option(w90main, 'dis_win_max', 24.d0) - call set_option(w90main, 'exclude_bands', exclude) - call set_option(w90main, 'fixed_step', 50.d0) - call set_option(w90main, 'iprint', 0) - call set_option(w90main, 'num_iter', 1000) - - call input_setopt(w90main, 'gaas', mpi_comm_world, stdout, stderr, ierr) ! apply settings - - call get_nn(w90main, nn, stdout, stderr, ierr); + call w90_set_option(w90main, 'conv_tol', 1.d-13) + call w90_set_option(w90main, 'conv_window', 3) + call w90_set_option(w90main, 'dis_froz_max', 14.0d0) + call w90_set_option(w90main, 'dis_mix_ratio', 1.d0) + call w90_set_option(w90main, 'dis_num_iter', 1200) + call w90_set_option(w90main, 'distk', distk) + call w90_set_option(w90main, 'dis_win_max', 24.d0) + call w90_set_option(w90main, 'exclude_bands', exclude) + call w90_set_option(w90main, 'fixed_step', 50.d0) + call w90_set_option(w90main, 'iprint', 0) + call w90_set_option(w90main, 'num_iter', 1000) + + call w90_input_setopt(w90main, 'gaas', mpi_comm_world, stdout, stderr, ierr) ! apply settings + + call w90_get_nn(w90main, nn, stdout, stderr, ierr); allocate (nnkp(nk, nn)) - call get_nnkp(w90main, nnkp, stdout, stderr, ierr); + call w90_get_nnkp(w90main, nnkp, stdout, stderr, ierr); allocate (m_matrix(nb, nb, nn, nk)) allocate (u_matrix_opt(nb, nw, nk)) - call set_m_local(w90main, m_matrix) ! m_matrix_local_orig - call set_u_opt(w90main, u_matrix_opt) + call w90_set_m_local(w90main, m_matrix) ! m_matrix_local_orig + call w90_set_u_opt(w90main, u_matrix_opt) ! read from ".mmn" and ".amn" ! and assign to m and a (now called u) ! a dft code would calculate the overlaps here instead - call overlaps(w90main, stdout, stderr, ierr) + ! TODO: Correct this reference +! call overlaps(w90main, stdout, stderr, ierr) ! final u matrix allocate (u_matrix(nw, nw, nk)) - call set_u_matrix(w90main, u_matrix) + call w90_set_u_matrix(w90main, u_matrix) - call set_eigval(w90main, eval) - call disentangle(w90main, stdout, stderr, ierr) - call wannierise(w90main, stdout, stderr, ierr) + call w90_set_eigval(w90main, eval) + call w90_disentangle(w90main, stdout, stderr, ierr) + call w90_wannierise(w90main, stdout, stderr, ierr) if (mpirank == 0) then do ib = 1, nw write (stdout, '(4f20.10)') (w90main%wannier_data%centres(ic, ib), ic=1, 3), w90main%wannier_data%spreads(ib) enddo endif +#ifdef Wannier90_MPI call mpi_finalize() +#endif end program diff --git a/test-suite/libv2-demo/lib-gas-opt-pllel/gaas.amn b/test-suite/libv2-demo/lib-gas-opt/gaas.amn similarity index 100% rename from test-suite/libv2-demo/lib-gas-opt-pllel/gaas.amn rename to test-suite/libv2-demo/lib-gas-opt/gaas.amn diff --git a/test-suite/libv2-demo/lib-gas-opt-pllel/gaas.eig b/test-suite/libv2-demo/lib-gas-opt/gaas.eig similarity index 100% rename from test-suite/libv2-demo/lib-gas-opt-pllel/gaas.eig rename to test-suite/libv2-demo/lib-gas-opt/gaas.eig diff --git a/test-suite/libv2-demo/lib-gas-opt-pllel/gaas.mmn b/test-suite/libv2-demo/lib-gas-opt/gaas.mmn similarity index 100% rename from test-suite/libv2-demo/lib-gas-opt-pllel/gaas.mmn rename to test-suite/libv2-demo/lib-gas-opt/gaas.mmn diff --git a/test-suite/libv2-demo/lib-gas-opt-pllel/makefile b/test-suite/libv2-demo/lib-gas-opt/makefile similarity index 75% rename from test-suite/libv2-demo/lib-gas-opt-pllel/makefile rename to test-suite/libv2-demo/lib-gas-opt/makefile index 25571f211..16ef2e4e2 100644 --- a/test-suite/libv2-demo/lib-gas-opt-pllel/makefile +++ b/test-suite/libv2-demo/lib-gas-opt/makefile @@ -5,5 +5,5 @@ XLIBS=$(ROOT)/libwan2.a a.out: demo.o $(MPIF90) demo.o $(LIBS) $(XLIBS) demo.o: demo.f90 - $(MPIF90) $(FCOPTS) $(XINCS) -c $< + $(MPIF90) $(FCOPTS) -DWannier90_MPI $(XINCS) -c $< From 2371623022a2b0f8f65aac1f68ba24e99db619fb Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 22 Feb 2024 13:15:00 +0100 Subject: [PATCH 4/8] Fedora packaging convention Signed-off-by: Cristian Le --- CMakeLists.txt | 5 +++-- src/CMakeLists.txt | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bf38ff6a..6ead8efd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,10 +43,11 @@ if (WANNIER90_INSTALL) include(CMakePackageConfigHelpers) # CMake does not properly support fortran module installation paths. - # Adapting the standard from fortran-stdlib # https://gitlab.kitware.com/cmake/cmake/-/issues/19608 # https://discourse.cmake.org/t/api-design-c-modules-source-listings-and-interface-properties/5389/14 - cmake_path(APPEND CMAKE_INSTALL_INCLUDEDIR ${PROJECT_NAME} "${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" + # Note: This does not follow fortran-stdlib format, instead it follows Fedora guidelines + # https://pagure.io/packaging-committee/issue/1334 + cmake_path(APPEND CMAKE_INSTALL_LIBDIR "${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" modules OUTPUT_VARIABLE _DEFAULT_CMAKE_INSTALL_MODULEDIR ) set(CMAKE_INSTALL_MODULEDIR ${_DEFAULT_CMAKE_INSTALL_MODULEDIR} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e586473e1..d2a2cba42 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,10 +35,13 @@ target_link_libraries(Wannier90_lib PRIVATE target_include_directories(Wannier90_lib PUBLIC "$" "$" - "$" + "$" ) -target_sources(Wannier90_lib INTERFACE - FILE_SET wannier90_C_Headers TYPE HEADERS FILES wannier90.hh +target_sources(Wannier90_lib + INTERFACE FILE_SET wannier90_C_Headers TYPE HEADERS FILES + wannier90.hh + INTERFACE FILE_SET wannier90_Fortran_Headers TYPE HEADERS BASE_DIRS ${CMAKE_Fortran_MODULE_DIRECTORY} FILES + ${CMAKE_Fortran_MODULE_DIRECTORY}/w90_library.mod ) if (WANNIER90_MPI) target_link_libraries(Wannier90_lib PRIVATE MPI::MPI_Fortran) @@ -55,9 +58,6 @@ if (WANNIER90_INSTALL) PUBLIC_HEADER COMPONENT Wannier90_Development RUNTIME COMPONENT Wannier90_Runtime FILE_SET wannier90_C_Headers COMPONENT Wannier90_Development + FILE_SET wannier90_Fortran_Headers DESTINATION ${CMAKE_INSTALL_MODULEDIR}/Wannier90 COMPONENT Wannier90_Development ) - install(FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/w90_library.mod - DESTINATION ${CMAKE_INSTALL_MODULEDIR} - COMPONENT Wannier90_Development - ) endif () From 07fd98478379a46031c3c2a2ee6704bf54c62a7c Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 22 Feb 2024 12:54:14 +0100 Subject: [PATCH 5/8] Fix python shebang Signed-off-by: Cristian Le --- test-suite/clean_tests | 2 +- test-suite/run_tests | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test-suite/clean_tests b/test-suite/clean_tests index 83a679cff..f766872c6 100755 --- a/test-suite/clean_tests +++ b/test-suite/clean_tests @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ This script runs the tests either asking interactively if you want to run only one, or runs them all with the proper command-line options. diff --git a/test-suite/run_tests b/test-suite/run_tests index 32af96865..204c883fc 100755 --- a/test-suite/run_tests +++ b/test-suite/run_tests @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ This script runs the tests either asking interactively if you want to run only one, or runs them all with the proper command-line options. From 15188ba53ad5de85c3e38d1c201c4835db806acd Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 11 Jun 2024 09:32:13 +0200 Subject: [PATCH 6/8] Fix executable suffix Signed-off-by: Cristian Le --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ead8efd5..5c2abc7e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,14 +86,16 @@ endif () ## Main targets add_executable(Wannier90_exe) set_target_properties(Wannier90_exe PROPERTIES - OUTPUT_NAME wannier90.x + OUTPUT_NAME wannier90 EXPORT_NAME exe + SUFFIX .x ) add_executable(Wannier90::exe ALIAS Wannier90_exe) add_executable(Wannier90_post) set_target_properties(Wannier90_post PROPERTIES - OUTPUT_NAME postw90.x + OUTPUT_NAME postw90 EXPORT_NAME post + SUFFIX .x ) add_executable(Wannier90::post ALIAS Wannier90_post) add_library(Wannier90_lib) From 9e992d267a0e653cc589104126502bad118f6c92 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 11 Jun 2024 11:07:22 +0200 Subject: [PATCH 7/8] Fix MPI support Signed-off-by: Cristian Le --- CMakeLists.txt | 5 ++++- cmake/Wannier90Config.cmake.in | 16 ++++++++++++++++ src/CMakeLists.txt | 8 +++++++- src/postw90/CMakeLists.txt | 5 +++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c2abc7e3..a9f380f70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,10 @@ set(Wannier90_MPI ${WANNIER90_WITH_MPI}) find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) if (WANNIER90_MPI) - find_package(MPI REQUIRED) + find_package(MPI REQUIRED COMPONENTS Fortran) + if (NOT MPI_Fortran_HAVE_F08_MODULE) + message(SEND_ERROR "mpi_f08 module is required for building Wannier90 with MPI") + endif () endif () #[=============================================================================[ diff --git a/cmake/Wannier90Config.cmake.in b/cmake/Wannier90Config.cmake.in index af6ec851c..062055458 100644 --- a/cmake/Wannier90Config.cmake.in +++ b/cmake/Wannier90Config.cmake.in @@ -4,5 +4,21 @@ ## Define basic variables set(Wannier90_MPI @WANNIER90_MPI@) +## Include dependencies +include(CMakeFindDependencyMacro) +if (Wannier90_MPI) + # Note: In the future the MPI support can be converted to an (optional) package component. + # This would however require a breaking change in the library definition + find_dependency(MPI COMPONENTS Fortran) + if (NOT MPI_Fortran_FOUND OR NOT MPI_Fortran_HAVE_F08_MODULE) + message(WARNING + "Wannier90 was built and packaged with MPI, but the system does not have compatible MPI support.\n" + "This is an issue with the packager of Wannier90." + ) + set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) + return() + endif () +endif () + ## Parse find_package request include(${CMAKE_CURRENT_LIST_DIR}/Wannier90Targets.cmake) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d2a2cba42..7f695d54a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,13 @@ target_sources(Wannier90_lib ${CMAKE_Fortran_MODULE_DIRECTORY}/w90_library.mod ) if (WANNIER90_MPI) - target_link_libraries(Wannier90_lib PRIVATE MPI::MPI_Fortran) + target_link_libraries(Wannier90_lib PUBLIC MPI::MPI_Fortran) + target_compile_definitions(Wannier90_lib PRIVATE + MPI08 MPI + ) + target_compile_definitions(Wannier90_exe PRIVATE + MPI08 MPI + ) endif () add_subdirectory(postw90) diff --git a/src/postw90/CMakeLists.txt b/src/postw90/CMakeLists.txt index e2a4facab..7fa81100a 100644 --- a/src/postw90/CMakeLists.txt +++ b/src/postw90/CMakeLists.txt @@ -19,6 +19,11 @@ target_sources(Wannier90_lib PRIVATE ) target_link_libraries(Wannier90_post PRIVATE Wannier90_lib BLAS::BLAS LAPACK::LAPACK) +if (WANNIER90_MPI) + target_compile_definitions(Wannier90_post PRIVATE + MPI08 MPI + ) +endif () ## Installs if (WANNIER90_INSTALL) From ef03aefa9f2fdfcfbe4b5d38e865255c7b068389 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 11 Jun 2024 11:14:36 +0200 Subject: [PATCH 8/8] Make wannier90.pc more relocatable Signed-off-by: Cristian Le --- cmake/wannier90.pc.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmake/wannier90.pc.in b/cmake/wannier90.pc.in index e1fdf3e8b..5c71772c4 100644 --- a/cmake/wannier90.pc.in +++ b/cmake/wannier90.pc.in @@ -1,9 +1,12 @@ prefix: @CMAKE_INSTALL_PREFIX@ +libdir: ${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir: ${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ +moduledir: ${prefix}/@CMAKE_INSTALL_MODULEDIR@/Wannier90 Name: wannier Version: @PROJECT_VERSION@ Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ -Cflags: -I@CMAKE_INSTALL_FULL_MODULEDIR@ -I@CMAKE_INSTALL_FULL_INCLUDEDIR@ -Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lwannier90 +Cflags: -I${moduledir} -I${includedir} +Libs: -L${libdir} -lwannier90