diff --git a/.distro/.fmf/version b/.distro/.fmf/version new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/.distro/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/.distro/plans/full.fmf b/.distro/plans/full.fmf new file mode 100644 index 000000000..94db25743 --- /dev/null +++ b/.distro/plans/full.fmf @@ -0,0 +1,7 @@ +summary: + Test the bundled ctests and pytest +discover+: + how: fmf + path: test-suite +execute: + how: tmt diff --git a/.distro/plans/main.fmf b/.distro/plans/main.fmf new file mode 100644 index 000000000..3491d2d37 --- /dev/null +++ b/.distro/plans/main.fmf @@ -0,0 +1,6 @@ +adjust+: + # Cannot use initiator: fedora-ci reliably yet + when: initiator is not defined or initiator != packit + discover: + how: fmf + dist-git-source: true diff --git a/.distro/plans/rpminspect.fmf b/.distro/plans/rpminspect.fmf new file mode 100644 index 000000000..59e9b248b --- /dev/null +++ b/.distro/plans/rpminspect.fmf @@ -0,0 +1,5 @@ +plan: + import: + url: https://github.com/packit/tmt-plans + ref: main + name: /plans/rpminspect diff --git a/.distro/plans/rpmlint.fmf b/.distro/plans/rpmlint.fmf new file mode 100644 index 000000000..1d28ff952 --- /dev/null +++ b/.distro/plans/rpmlint.fmf @@ -0,0 +1,10 @@ +prepare: + - how: shell + script: cp ./*.rpmlintrc $TMT_PLAN_DATA/ +discover: + how: fmf + filter: "tag: rpmlint" + url: https://github.com/packit/tmt-plans + ref: main +execute: + how: tmt diff --git a/.distro/wannier90.rpmlintrc b/.distro/wannier90.rpmlintrc new file mode 100644 index 000000000..e69de29bb diff --git a/.distro/wannier90.spec b/.distro/wannier90.spec new file mode 100644 index 000000000..ab8cac7b4 --- /dev/null +++ b/.distro/wannier90.spec @@ -0,0 +1,160 @@ +Name: wannier90 +Summary: Maximally-Localised Generalised Wannier Functions Code +Version: 0.0.0 +Release: %autorelease +License: GPLv2 +URL: https://www.wannier.org/ + +Source: https://github.com/wannier-developers/wannier90/archive/refs/tags/v%{version}.tar.gz + +BuildRequires: ninja-build +BuildRequires: cmake +BuildRequires: gcc-fortran +BuildRequires: flexiblas-devel +# Required for testing +BuildRequires: gcc-c++ +BuildRequires: python3 + +%global _description %{expand: +Maximally-Localised Generalised Wannier Functions Code.} + +%description +%{_description} + +%package devel +Summary: Development files for wannier90 +Requires: wannier90%{?_isa} = %{version}-%{release} + +%description devel +This package contains the development files for the wannier90 library. + +%package openmpi +Summary: Maximally-Localised Generalised Wannier Functions Code - OpenMPI version +BuildRequires: openmpi-devel + +%description openmpi +%{_description} + +This package contains the OpenMPI parallel version. + +%package openmpi-devel +Summary: Development files for wannier90 - OpenMPI version +Requires: wannier90-openmpi%{?_isa} = %{version}-%{release} + +%description openmpi-devel +This package contains the development files for the wannier90 (OpenMPI) library. + +%package mpich +Summary: Maximally-Localised Generalised Wannier Functions Code - MPICH version +BuildRequires: mpich-devel + +%description mpich +%{_description} + +This package contains the MPICH parallel version. + +%package mpich-devel +Summary: Development files for wannier90 - MPICH version +Requires: wannier90-mpich%{?_isa} = %{version}-%{release} + +%description mpich-devel +This package contains the development files for the wannier90 (MPICH) library. + + +%prep +%autosetup -n wannier90-%{version} + +# $MPI_SUFFIX will be evaluated in the loops below, set by mpi modules +%global _vpath_builddir %{_vendor}-%{_target_os}-build${MPI_SUFFIX:-_serial} +# We are running the module load/unload manually until there is a macro-like way to expand this +. /etc/profile.d/modules.sh + + +%build +cmake_common_args=( + "-G Ninja" + "-DWANNIER90_SHARED_LIBS=ON" + "-DWANNIER90_TEST=ON" +) +for mpi in '' mpich openmpi ; do + if [ -n "$mpi" ]; then + module load mpi/${mpi}-%{_arch} + cmake_mpi_args=( + "-DCMAKE_INSTALL_PREFIX=${MPI_HOME}" + "-DWANNIER90_MPI=ON" + "-DCMAKE_INSTALL_MODULEDIR=${MPI_FORTRAN_MOD_DIR}" + "-DCMAKE_INSTALL_LIBDIR=lib" + ) + else + cmake_mpi_args=( + "-DWANNIER90_MPI=OFF" + "-DCMAKE_INSTALL_MODULEDIR=%{_fmoddir}" + ) + fi + + %cmake \ + ${cmake_common_args[@]} \ + ${cmake_mpi_args[@]} + %cmake_build + + [ -n "$mpi" ] && module unload mpi/${mpi}-%{_arch} +done + + +%install +for mpi in '' mpich openmpi ; do + [ -n "$mpi" ] && module load mpi/${mpi}-%{_arch} + %cmake_install + [ -n "$mpi" ] && module unload mpi/${mpi}-%{_arch} +done + + +%check +for mpi in '' mpich %{?with_openmpi:openmpi} ; do + [ -n "$mpi" ] && module load mpi/${mpi}-%{_arch} + # TODO: re-enable tests + # %%ctest + [ -n "$mpi" ] && module unload mpi/${mpi}-%{_arch} +done + + +%files +%doc README.rst +%license LICENSE +%{_libdir}/libwannier90.so.* +%{_bindir}/wannier90.x +%{_bindir}/postw90.x + +%files devel +%{_includedir}/wannier90.hh +%{_libdir}/libwannier90.so +%{_fmoddir}/Wannier90/ +%{_libdir}/cmake/Wannier90 +%{_libdir}/pkgconfig/wannier90.pc + +%files openmpi +%{_libdir}/openmpi/bin/wannier90.x +%{_libdir}/openmpi/bin/postw90.x +%{_libdir}/openmpi/lib/libwannier90.so.* + +%files openmpi-devel +%{_libdir}/openmpi/include/wannier90.hh +%{_libdir}/openmpi/lib/libwannier90.so +%{_fmoddir}/openmpi/Wannier90/ +%{_libdir}/openmpi/lib/cmake/Wannier90 +%{_libdir}/openmpi/lib/pkgconfig/wannier90.pc + +%files mpich +%{_libdir}/mpich/bin/wannier90.x +%{_libdir}/mpich/bin/postw90.x +%{_libdir}/mpich/lib/libwannier90.so.* + +%files mpich-devel +%{_libdir}/mpich/include/wannier90.hh +%{_libdir}/mpich/lib/libwannier90.so +%{_fmoddir}/mpich/Wannier90/ +%{_libdir}/mpich/lib/cmake/Wannier90 +%{_libdir}/mpich/lib/pkgconfig/wannier90.pc + +%changelog +%autochangelog 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}} 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/.packit.yaml b/.packit.yaml new file mode 100644 index 000000000..aa33c6cb9 --- /dev/null +++ b/.packit.yaml @@ -0,0 +1,57 @@ +specfile_path: .distro/wannier90.spec +files_to_sync: + - src: .distro/ + dest: ./ + delete: true + filters: + - "protect .git*" + - "protect sources" + - "protect changelog" + - "- plans/rpminspect.fmf" + - "- plans/rpmlint.fmf" + - .packit.yaml + +upstream_package_name: wannier90 +downstream_package_name: wannier90 +upstream_tag_template: v{version} + +targets: + - fedora-all-x86_64 + - fedora-all-aarch64 + +jobs: + - &copr_build + job: copr_build + trigger: release + owner: lecris + project: release + update_release: false + - <<: *copr_build + trigger: commit + branch: develop + project: nightly + update_release: true + - &tests + job: tests + trigger: commit + branch: develop + targets: + - fedora-all-x86_64 + - fedora-all-aarch64 + fmf_path: .distro + - job: copr_build + trigger: pull_request + - <<: *tests + trigger: pull_request + - job: propose_downstream + trigger: release + dist_git_branches: + - fedora-rawhide + - job: koji_build + trigger: commit + dist_git_branches: + - fedora-all + - job: bodhi_update + trigger: commit + dist_git_branches: + - fedora-branched diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..a9f380f70 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,178 @@ +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. + # https://gitlab.kitware.com/cmake/cmake/-/issues/19608 + # https://discourse.cmake.org/t/api-design-c-modules-source-listings-and-interface-properties/5389/14 + # 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} + 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 COMPONENTS Fortran) + if (NOT MPI_Fortran_HAVE_F08_MODULE) + message(SEND_ERROR "mpi_f08 module is required for building Wannier90 with MPI") + endif () +endif () + +#[=============================================================================[ +# Main definition # +]=============================================================================] + +## Main targets +add_executable(Wannier90_exe) +set_target_properties(Wannier90_exe PROPERTIES + 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 + EXPORT_NAME post + SUFFIX .x +) +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..062055458 --- /dev/null +++ b/cmake/Wannier90Config.cmake.in @@ -0,0 +1,24 @@ +@PACKAGE_INIT@ + + +## 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/cmake/wannier90.pc.in b/cmake/wannier90.pc.in new file mode 100644 index 000000000..5c71772c4 --- /dev/null +++ b/cmake/wannier90.pc.in @@ -0,0 +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${moduledir} -I${includedir} +Libs: -L${libdir} -lwannier90 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..7f695d54a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,69 @@ +## 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 + 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 PUBLIC MPI::MPI_Fortran) + target_compile_definitions(Wannier90_lib PRIVATE + MPI08 MPI + ) + target_compile_definitions(Wannier90_exe PRIVATE + MPI08 MPI + ) +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 + FILE_SET wannier90_Fortran_Headers DESTINATION ${CMAKE_INSTALL_MODULEDIR}/Wannier90 COMPONENT Wannier90_Development + ) +endif () diff --git a/src/postw90/CMakeLists.txt b/src/postw90/CMakeLists.txt new file mode 100644 index 000000000..7fa81100a --- /dev/null +++ b/src/postw90/CMakeLists.txt @@ -0,0 +1,37 @@ +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) +if (WANNIER90_MPI) + target_compile_definitions(Wannier90_post PRIVATE + MPI08 MPI + ) +endif () + +## 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/.fmf/version b/test-suite/.fmf/version new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/test-suite/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt new file mode 100644 index 000000000..ffee17b6c --- /dev/null +++ b/test-suite/CMakeLists.txt @@ -0,0 +1,134 @@ +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) +## Add packaging tests +add_subdirectory(package) 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/ctest.fmf b/test-suite/ctest.fmf new file mode 100644 index 000000000..6db9ace24 --- /dev/null +++ b/test-suite/ctest.fmf @@ -0,0 +1,26 @@ +tag: [ cmake ] +require: + - cmake + - rsync + - gcc + - gcc-c++ + - gcc-fortran + - pkgconf + - git + # For test-suite + - bzip2 + # For testing FetchContent + - flexiblas-devel +framework: beakerlib +path: / +test: ./ctest.sh + +/serial: + environment: + MPI_VARIANT: serial +/OpenMPI: + environment: + MPI_VARIANT: openmpi +/MPICH: + environment: + MPI_VARIANT: mpich diff --git a/test-suite/ctest.sh b/test-suite/ctest.sh new file mode 100755 index 000000000..66f2a9741 --- /dev/null +++ b/test-suite/ctest.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# shellcheck disable=all +source /usr/share/beakerlib/beakerlib.sh || exit 1 + +rlJournalStart + rlPhaseStartSetup + rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" + rlRun "rsync -rL ./ $tmp" 0 "Copy test-suite project" + rlRun "pushd $tmp" + rlRun "set -o pipefail" + [[ -z "${MPI_VARIANT}" ]] && rlDie "MPI_VARIANT was not provided" + rlPhaseEnd + + rlPhaseStartTest + [[ "${MPI_VARIANT}" != "serial" ]] && rlRun "module load mpi/${MPI_VARIANT}" 0 "Load MPI" + rlRun "cmake -B ./build" 0 "CMake configure" + rlRun "cmake --build ./build" 0 "CMake build" + rlRun "ctest --test-dir ./build --output-on-failure" 0 "Run CTest" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $tmp" 0 "Remove tmp directory" + rlPhaseEnd +rlJournalEnd diff --git a/test-suite/libv2-demo/CMakeLists.txt b/test-suite/libv2-demo/CMakeLists.txt new file mode 100644 index 000000000..0d4178209 --- /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 + 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/CMakeLists.txt b/test-suite/libv2-demo/lib-gas-opt/CMakeLists.txt new file mode 100644 index 000000000..37ab722a3 --- /dev/null +++ b/test-suite/libv2-demo/lib-gas-opt/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(demo_Wannier90 LANGUAGES Fortran) + +find_package(Wannier90 REQUIRED) + +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 $< 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/package/CMakeLists.txt b/test-suite/package/CMakeLists.txt new file mode 100644 index 000000000..3bbc402cf --- /dev/null +++ b/test-suite/package/CMakeLists.txt @@ -0,0 +1,15 @@ +set_property(DIRECTORY APPEND + PROPERTY LABELS package +) + +set(test_list + FetchContent + find_package +) +if (NOT Wannier90_IS_TOP_LEVEL) + list(APPEND test_list pkg-config) +endif () + +foreach (test IN LISTS test_list) + Wannier90_add_test(${test} TEST_NAME test-${test}) +endforeach () diff --git a/test-suite/package/FetchContent/CMakeLists.txt b/test-suite/package/FetchContent/CMakeLists.txt new file mode 100644 index 000000000..1f0644936 --- /dev/null +++ b/test-suite/package/FetchContent/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(example_Wannier90 LANGUAGES Fortran) + + +include(FetchContent) + +if (DEFINED ENV{PACKIT_SOURCE_URL}) + set(git_repo $ENV{PACKIT_SOURCE_URL}) +else () + set(git_repo https://github.com/wannier-developers/wannier90) +endif () +if (DEFINED ENV{PACKIT_SOURCE_SHA}) + set(git_tag $ENV{PACKIT_SOURCE_SHA}) +elseif (DEFINED ENV{PACKIT_COMMIT_SHA}) + set(git_tag $ENV{PACKIT_COMMIT_SHA}) +else () + set(git_tag develop) +endif () + +FetchContent_Declare(Wannier90 + GIT_REPOSITORY ${git_repo} + GIT_TAG ${git_tag} +) +FetchContent_MakeAvailable(Wannier90) + +add_executable(main src/main.F90) +target_link_libraries(main PRIVATE Wannier90::wannier90) + +enable_testing() + +add_test(NAME smoke_test_lib + COMMAND $ +) +add_test(NAME smoke_test_exe + COMMAND $ --version +) +add_test(NAME smoke_test_post + COMMAND $ --version +) diff --git a/test-suite/package/FetchContent/src b/test-suite/package/FetchContent/src new file mode 120000 index 000000000..e057607ed --- /dev/null +++ b/test-suite/package/FetchContent/src @@ -0,0 +1 @@ +../src/ \ No newline at end of file diff --git a/test-suite/package/find_package/CMakeLists.txt b/test-suite/package/find_package/CMakeLists.txt new file mode 100644 index 000000000..f394c75ff --- /dev/null +++ b/test-suite/package/find_package/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(example_Wannier90 LANGUAGES Fortran) + +find_package(Wannier90 REQUIRED) + +add_executable(main src/main.F90) +target_link_libraries(main PRIVATE Wannier90::wannier90) + +enable_testing() + +add_test(NAME smoke_test_lib + COMMAND $ +) +add_test(NAME smoke_test_exe + COMMAND $ --version +) +add_test(NAME smoke_test_post + COMMAND $ --version +) diff --git a/test-suite/package/find_package/src b/test-suite/package/find_package/src new file mode 120000 index 000000000..e057607ed --- /dev/null +++ b/test-suite/package/find_package/src @@ -0,0 +1 @@ +../src/ \ No newline at end of file diff --git a/test-suite/package/pkg-config/CMakeLists.txt b/test-suite/package/pkg-config/CMakeLists.txt new file mode 100644 index 000000000..ff7e896be --- /dev/null +++ b/test-suite/package/pkg-config/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.25...3.29) +project(example_Wannier90 LANGUAGES Fortran) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(Wannier90 REQUIRED IMPORTED_TARGET wannier90) + +add_executable(main src/main.F90) +target_link_libraries(main PRIVATE PkgConfig::Wannier90) + +enable_testing() + +add_test(NAME smoke_test_lib + COMMAND $ +) diff --git a/test-suite/package/pkg-config/src b/test-suite/package/pkg-config/src new file mode 120000 index 000000000..e057607ed --- /dev/null +++ b/test-suite/package/pkg-config/src @@ -0,0 +1 @@ +../src/ \ No newline at end of file diff --git a/test-suite/package/src/main.F90 b/test-suite/package/src/main.F90 new file mode 100644 index 000000000..0ac7fc861 --- /dev/null +++ b/test-suite/package/src/main.F90 @@ -0,0 +1,6 @@ +program wannier90_example + use w90_library + implicit none + + ! TODO: Implement basic smoke test +end program wannier90_example 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. 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 ()