diff --git a/.cmake-format.py b/.cmake-format.py new file mode 100644 index 00000000..6f2c0fee --- /dev/null +++ b/.cmake-format.py @@ -0,0 +1,243 @@ +# ---------------------------------- +# Options affecting listfile parsing +# ---------------------------------- +with section("parse"): + + # Specify structure for custom cmake functions + additional_commands = { + 'setup_test': { 'kwargs': {'GPUONLY': '0', 'LABELS': '+', 'MPI': '0', 'SOURCES': '+'}, + 'pargs': {'flags': ['2'], 'nargs': '0'}}, + } + + # Override configurations per-command where available + override_spec = {} + + # Specify variable tags. + vartags = [] + + # Specify property tags. + proptags = [] + +# ----------------------------- +# Options affecting formatting. +# ----------------------------- +with section("format"): + + # Disable formatting entirely, making cmake-format a no-op + disable = False + + # How wide to allow formatted cmake files + line_width = 100 + + # How many spaces to tab for indent + tab_size = 2 + + # If true, lines are indented using tab characters (utf-8 0x09) instead of + # space characters (utf-8 0x20). In cases where the layout would + # require a fractional tab character, the behavior of the fractional + # indentation is governed by + use_tabchars = False + + # If is True, then the value of this variable indicates how + # fractional indentions are handled during whitespace replacement. If set to + # 'use-space', fractional indentation is left as spaces (utf-8 0x20). If set + # to `round-up` fractional indentation is replaced with a single tab character + # (utf-8 0x09) effectively shifting the column to the next tabstop + fractional_tab_policy = 'use-space' + + # If an argument group contains more than this many sub-groups (parg or kwarg + # groups) then force it to a vertical layout. + max_subgroups_hwrap = 2 + + # If a positional argument group contains more than this many arguments, then + # force it to a vertical layout. + max_pargs_hwrap = 6 + + # If a cmdline positional group consumes more than this many lines without + # nesting, then invalidate the layout (and nest) + max_rows_cmdline = 2 + + # If true, separate flow control names from their parentheses with a space + separate_ctrl_name_with_space = False + + # If true, separate function names from parentheses with a space + separate_fn_name_with_space = False + + # If a statement is wrapped to more than one line, than dangle the closing + # parenthesis on its own line. + dangle_parens = True + + # If the trailing parenthesis must be 'dangled' on its on line, then align it + # to this reference: `prefix`: the start of the statement, `prefix-indent`: + # the start of the statement, plus one indentation level, `child`: align to + # the column of the arguments + dangle_align = 'prefix' + + # If the statement spelling length (including space and parenthesis) is + # smaller than this amount, then force reject nested layouts. + min_prefix_chars = 4 + + # If the statement spelling length (including space and parenthesis) is larger + # than the tab width by more than this amount, then force reject un-nested + # layouts. + max_prefix_chars = 10 + + # If a candidate layout is wrapped horizontally but it exceeds this many + # lines, then reject the layout. + max_lines_hwrap = 2 + + # What style line endings to use in the output. + line_ending = 'unix' + + # Format command names consistently as 'lower' or 'upper' case + command_case = 'canonical' + + # Format keywords consistently as 'lower' or 'upper' case + keyword_case = 'unchanged' + + # A list of command names which should always be wrapped + always_wrap = [] + + # If true, the argument lists which are known to be sortable will be sorted + # lexicographicall + enable_sort = True + + # If true, the parsers may infer whether or not an argument list is sortable + # (without annotation). + autosort = False + + # By default, if cmake-format cannot successfully fit everything into the + # desired linewidth it will apply the last, most aggressive attempt that it + # made. If this flag is True, however, cmake-format will print error, exit + # with non-zero status code, and write-out nothing + require_valid_layout = False + + # A dictionary mapping layout nodes to a list of wrap decisions. See the + # documentation for more information. + layout_passes = {} + +# ------------------------------------------------ +# Options affecting comment reflow and formatting. +# ------------------------------------------------ +with section("markup"): + + # What character to use for bulleted lists + bullet_char = '*' + + # What character to use as punctuation after numerals in an enumerated list + enum_char = '.' + + # If comment markup is enabled, don't reflow the first comment block in each + # listfile. Use this to preserve formatting of your copyright/license + # statements. + first_comment_is_literal = False + + # If comment markup is enabled, don't reflow any comment block which matches + # this (regex) pattern. Default is `None` (disabled). + literal_comment_pattern = None + + # Regular expression to match preformat fences in comments default= + # ``r'^\s*([`~]{3}[`~]*)(.*)$'`` + fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$' + + # Regular expression to match rulers in comments default= + # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'`` + ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$' + + # If a comment line matches starts with this pattern then it is explicitly a + # trailing comment for the preceding argument. Default is '#<' + explicit_trailing_pattern = '#<' + + # If a comment line starts with at least this many consecutive hash + # characters, then don't lstrip() them off. This allows for lazy hash rulers + # where the first hash char is not separated by space + hashruler_min_length = 10 + + # If true, then insert a space between the first hash char and remaining hash + # chars in a hash ruler, and normalize its length to fill the column + canonicalize_hashrulers = True + + # enable comment markup parsing and reflow + enable_markup = True + +# ---------------------------- +# Options affecting the linter +# ---------------------------- +with section("lint"): + + # a list of lint codes to disable + disabled_codes = [] + + # regular expression pattern describing valid function names + function_pattern = '[0-9a-z_]+' + + # regular expression pattern describing valid macro names + macro_pattern = '[0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # (cache) scope + global_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # scope (but internal semantic) + internal_var_pattern = '_[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with local + # scope + local_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for privatedirectory + # variables + private_var_pattern = '_[0-9a-z_]+' + + # regular expression pattern describing valid names for public directory + # variables + public_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for function/macro + # arguments and loop variables. + argument_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for keywords used in + # functions or macros + keyword_pattern = '[A-Z][0-9A-Z_]+' + + # In the heuristic for C0201, how many conditionals to match within a loop in + # before considering the loop a parser. + max_conditionals_custom_parser = 2 + + # Require at least this many newlines between statements + min_statement_spacing = 1 + + # Require no more than this many newlines between statements + max_statement_spacing = 2 + max_returns = 6 + max_branches = 12 + max_arguments = 5 + max_localvars = 15 + max_statements = 50 + +# ------------------------------- +# Options affecting file encoding +# ------------------------------- +with section("encode"): + + # If true, emit the unicode byte-order mark (BOM) at the start of the file + emit_byteorder_mark = False + + # Specify the encoding of the input file. Defaults to utf-8 + input_encoding = 'utf-8' + + # Specify the encoding of the output file. Defaults to utf-8. Note that cmake + # only claims to support utf-8 so be careful when using anything else + output_encoding = 'utf-8' + +# ------------------------------------- +# Miscellaneous configurations options. +# ------------------------------------- +with section("misc"): + + # A dictionary containing any per-command configuration overrides. Currently + # only `command_case` is supported. + per_command = {} + diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9aa7e602..e4b94dd3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,6 +19,18 @@ MALLOC_PERTURB_: 1 +check-format: + stage: .pre + image: $CI_REGISTRY/nexgf/libnegf/check-format + script: + - >- + find . -name CMakeLists.txt -print0 + | xargs -0 -L1 -- cmake-format --check -- + - >- + find . -iname '*.cu' -o -iname '*.cpp' -print0 + | xargs -0 -L1 -- clang-format --dry-run -Werror -- + + build: extends: .setup stage: build @@ -47,4 +59,5 @@ test: stage: test script: - cd "$BUILD_DIR" - - ctest -L normal --output-on-failure + - ctest --output-on-failure -LE long + - ctest --output-on-failure -L long diff --git a/CMakeLists.txt b/CMakeLists.txt index da5accb0..cc04720b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.18) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.31) + cmake_policy(SET CMP0177 NEW) +endif() + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) include(LibNegfUtils) libnegf_load_build_settings() @@ -7,37 +11,41 @@ libnegf_load_build_settings() # Some setting output message(STATUS "libNEGF WITH_MPI: " ${WITH_MPI}) message(STATUS "libNEGF WITH_GPU: " ${WITH_TRANSPORT_GPU}) -#message(STATUS "libNEGF WITH_HILBERT: " ${WITH_HILBERT}) +# message(STATUS "libNEGF WITH_HILBERT: " ${WITH_HILBERT}) if(WITH_TRANSPORT_GPU) - project(libNEGF VERSION 1.2.1 LANGUAGES Fortran C CUDA CXX) + project( + libNEGF + VERSION 1.2.1 + LANGUAGES Fortran C CUDA CXX + ) else() - project(libNEGF VERSION 1.2.1 LANGUAGES Fortran C CXX) + project( + libNEGF + VERSION 1.2.1 + LANGUAGES Fortran C CXX + ) endif() - # disable compiler-specific extensions set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) -# Note: enforcing a standard in Fortran compilers has a different effect that in C compilers, c.f. [cmake#22235](https://gitlab.kitware.com/cmake/cmake/-/issues/22235). - +# Note: enforcing a standard in Fortran compilers has a different effect that in C compilers, c.f. +# [cmake#22235](https://gitlab.kitware.com/cmake/cmake/-/issues/22235). include(externalMpifx) include(CMakePackageConfigHelpers) - # find a Python3 interpreter for FYPP include(FindPython3) find_package(Python3 REQUIRED COMPONENTS Interpreter) - set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ext_fypp/;${CMAKE_PREFIX_PATH}") find_program(FYPP "fypp") include(GNUInstallDirs) - if(LAPACK_LIBRARIES AND LAPACK_LIBRARY_DIRS) message(STATUS "libNEGF LAPACK DIR: " ${LAPACK_LIBRARY_DIRS}) message(STATUS "libNEGF BLAS: " ${BLAS_LIBRARY}) @@ -53,7 +61,6 @@ if(WITH_MPI) find_or_fetch_mpifx() endif() - # Subdirectories. add_subdirectory(ext_system) add_subdirectory(src) @@ -64,12 +71,13 @@ if(BUILD_TESTING) add_subdirectory(tests) endif() - # # Installation # -set(CMAKE_INSTALL_PREFIX "/usr/local/libnegf${libNEGF_VERSION_MAJOR}.${libNEGF_VERSION_MINOR}" CACHE PATH - "default installation path") +set(CMAKE_INSTALL_PREFIX + "/usr/local/libnegf${libNEGF_VERSION_MAJOR}.${libNEGF_VERSION_MINOR}" + CACHE PATH "default installation path" +) message(STATUS "Default installation path: " ${CMAKE_INSTALL_PREFIX}) @@ -77,23 +85,27 @@ add_library(Negf INTERFACE) target_link_libraries(Negf INTERFACE negf) install(TARGETS Negf EXPORT negf-targets) -install(EXPORT negf-targets +install( + EXPORT negf-targets FILE negf-targets.cmake NAMESPACE Negf:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/negf" - EXPORT_LINK_INTERFACE_LIBRARIES) + EXPORT_LINK_INTERFACE_LIBRARIES +) configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/utils/export/negf-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/negf-config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/negf) + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/negf +) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/cmake/negf-config-version.cmake VERSION ${PROJECT_VERSION} - COMPATIBILITY SameMajorVersion) + COMPATIBILITY SameMajorVersion +) -install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/negf-config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/cmake/negf-config-version.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/negf) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/negf-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cmake/negf-config-version.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/negf +) diff --git a/README.adoc b/README.adoc index 49369adb..871dea27 100644 --- a/README.adoc +++ b/README.adoc @@ -1,5 +1,4 @@ -libNEGF -======= += libNEGF libNEGF is a general library for Non Equilibrium Green's Functions. @@ -37,6 +36,60 @@ Running the tests additionally requires git-lfs for downloading test inputs. The extension of test input files is `.dat`. +== Running the Tests on a Supercomputer + +On some HPC systems, front-end nodes do not feature GPUs (e.g., on LUMI) or the +front-end nodes may have an instruction set architecture different from compute +nodes (e.g., on Fugaku with its Intel front-end and Arm64FX compute nodes). On +these systems, it is best to submit all tests to the batch scheduler. + +This can be achieved with the following steps. First, determine the account name and a queue (or _partition_) for job submission. Next, select a time limit. Tests that do not possess the label `long` run quickly even on personal computers. Therefore, we suggest a time limit of at most five minutes (this is per task). Finally, determine the number of MPI tasks within the job. Our recommendation is to run on at most one node with one job per NUMA domain. + +CAUTION: Avoid large numbers of MPI tasks (e.g., by launching one task per virtual CPU core). The tests may not scale very well. + +With the values above in mind, enable `LIBNEGF_TEST_WITH_MPIEXEC`, set +`MPIEXEC_EXECUTABLE` to the absolute path to the batch scheduler executable, and +have `MPIEXEC_PREFLAGS` contain all the batch scheduler arguments as a CMake +list; in a CMake list, list items are separated by a semicolon. Here is an +example for Slurm: + +[source,shell,linenums] +---- +cmake \ + -DLIBNEGF_TEST_WITH_MPIEXEC=ON \ + -DMPIEXEC_EXECUTABLE="$(which srun)" \ + -DMPIEXEC_NUMPROC_FLAG='--ntasks' \ + -DMPIEXEC_MAX_NUMPROCS=4 \ + -DMPIEXEC_PREFLAGS='--account=mat4energy;--partition=develbooster;--nodes=1;--gpus-per-task=1;--time=1' \ + ... +---- +For faster execution, the tests can be run in an existing job allocation, e.g., +by calling `salloc` (for Slurm) or by using a reservation. Within the allocation, just call `ctest`. + +Note the following: + +* A time limit of one minute is sufficient for tests without `long` tag on JUWELS Booster and LUMI. +* The time limit of the job and the time limit of test CMake test submitting the job are two different things. +* Redirecting the output to files (e.g., with Slurm with `--output=stdout.txt`) breaks the mpifx tests because these tests examine the standard output instead of the exit status. + + + +== Contributing + +libNEGF enforces a coding style in C, C++, and CMake. Ideally, all committed code should contain only code adhering to the style guidelines. To support contributors in this regard, a sample git pre-commit hook checking the format is provided in link:git-pre-commit-hook.sh[`git-pre-commit-hook.sh`]. To install the file, append its contents to `.git/hooks/pre-commit` and make the latter file executable; the script requires cmake-format and clang-format to be installed. See the https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks[Git Book: _Customizing Git - Git Hooks_] or https://man7.org/linux/man-pages/man5/githooks.5.html[`man 5 githooks`] for more detailed instructions. The pre-commit script requires clang-format and cmake-format to be installed. + +[NOTE] +==== +Given the same source code and configuration, clang-format does _not_ promise to create the same formatting across different versions. The following clang-format major releases were tested in libnegf#117 and generate the same output unless noted otherwise: + +* 11 (Debian 11, *not* working) +* 14 (Debian 12) +* 18 (JUWELS Booster, Stages/2025) +* 19 (Debian 13) +* 20 (JUWELS Booster, Stages/2026) +==== + + == Generating libNEGF Input diff --git a/ext_system/CMakeLists.txt b/ext_system/CMakeLists.txt index adda84a1..660637a1 100644 --- a/ext_system/CMakeLists.txt +++ b/ext_system/CMakeLists.txt @@ -1,6 +1,4 @@ -set(sources - sys_calls.c - system_calls.f90) +set(sources sys_calls.c system_calls.f90) add_library(syscalls_objlib OBJECT ${sources}) @@ -9,9 +7,10 @@ set(BUILD_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) set_target_properties(syscalls_objlib PROPERTIES Fortran_MODULE_DIRECTORY ${BUILD_MOD_DIR}) set_target_properties(syscalls_objlib PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}) -target_include_directories(syscalls_objlib PUBLIC - $ - $) +target_include_directories( + syscalls_objlib PUBLIC $ + $ +) if(INSTALL_INCLUDE_FILES) install(DIRECTORY ${BUILD_MOD_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${INSTALL_MOD_DIR}) diff --git a/git-pre-commit-hook.sh b/git-pre-commit-hook.sh new file mode 100644 index 00000000..f47e90b9 --- /dev/null +++ b/git-pre-commit-hook.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Author: Christoph Conrads (Forschungszentrum Jülich) +# +# The git pre-commit hook checks if Python and C++ code is properly formatted. +# +# The code requires YAPF for Python and clang-format for C/C++/CUDA. + +set -e +set -u + + +# check for presence of formatting tools +if ! which clang-format >/dev/null +then + >/dev/stderr echo 'clang-format not found. aborting.' + exit 1 +fi + +if ! python3 -c 'import yapf' 2>/dev/null +then + >/dev/stderr echo 'Python3 module YAPF not found. aborting.' + exit 1 +fi + + +needs_format=false + + +# check files +files="$(git diff --cached --name-only --diff-filter=ACM)" + +while IFS='' read -r file +do + if [[ "$file" =~ [.]([ch]pp|cu)$ ]] + then + if ! $(clang-format --dry-run --Werror -- "$file" 2>/dev/null) + then + echo "$file must be formatted with clang-format" + needs_format=true + fi + elif [[ "$file" =~ [.]py$ ]] + then + if ! $(python3 -m yapf --quiet -- "$file") + then + echo "$file must be formatted with YAPF" + needs_format=true + fi + fi +done <<<"$files" + +if [ "$needs_format" = true ] +then + exit 1 +fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6200f754..5898155a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,43 +1,44 @@ set(sources-fpp - clock.F90 - ln_extract.F90 - input_output.F90 - ln_cache.F90 - lib_param.F90 - ln_enums.F90 - ln_precision.F90 - mpi_globals.F90 - ln_messages.F90 - contselfenergy.F90 - inversions.F90 - libnegf.F90 - ln_structure.F90 - outmatrix.F90 - distributions.F90 - ln_allocation.F90 - load.F90 - sparsekit_drv.F90 - integrations.F90 - globals.F90 - iterative.F90 - ln_constants.F90 - mat_def.F90 - population.F90 - energy_mesh.F90 - equiv_kpoints.F90 - interactions.F90 - ln_elastic.F90 - ln_inelastic.F90 - elphdd.F90 - elphdb.F90 - elphds.F90 - elphinel.F90 - self_energy.F90 - scba.F90 - sparskit/skit_blassm.F90 - sparskit/skit_formats.F90 - sparskit/skit_module.F90 - sparskit/skit_unary.F90) + clock.F90 + ln_extract.F90 + input_output.F90 + ln_cache.F90 + lib_param.F90 + ln_enums.F90 + ln_precision.F90 + mpi_globals.F90 + ln_messages.F90 + contselfenergy.F90 + inversions.F90 + libnegf.F90 + ln_structure.F90 + outmatrix.F90 + distributions.F90 + ln_allocation.F90 + load.F90 + sparsekit_drv.F90 + integrations.F90 + globals.F90 + iterative.F90 + ln_constants.F90 + mat_def.F90 + population.F90 + energy_mesh.F90 + equiv_kpoints.F90 + interactions.F90 + ln_elastic.F90 + ln_inelastic.F90 + elphdd.F90 + elphdb.F90 + elphds.F90 + elphinel.F90 + self_energy.F90 + scba.F90 + sparskit/skit_blassm.F90 + sparskit/skit_formats.F90 + sparskit/skit_module.F90 + sparskit/skit_unary.F90 +) if(WITH_HILBERT) list(APPEND sources-fpp transform.F90) @@ -48,17 +49,15 @@ if(WITH_TRANSPORT_GPU) list(APPEND sources-fpp iterative_gpu.F90) set(sources-cuda gpuroutines.cu) set_source_files_properties( - gpuroutines.cu - PROPERTIES INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include) + gpuroutines.cu PROPERTIES INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/include + ) else() list(APPEND sources-fpp iterative_cpu.F90) endif() -set(sources-f90 - api/libnegfAPICommon.f90 - api/libnegf_api.f90) +set(sources-f90 api/libnegfAPICommon.f90 api/libnegf_api.f90) -#execute_process(COMMAND git describe OUTPUT_VARIABLE gitrevision) +# execute_process(COMMAND git describe OUTPUT_VARIABLE gitrevision) set(gitrevision "000") string(TIMESTAMP compdate "%Y-%m-%d") @@ -67,7 +66,6 @@ if(WITH_MPI) list(APPEND fyppdefs -DMPI) endif() - if(WITH_TRANSPORT_GPU) list(APPEND fyppdefs -DGPU) endif() @@ -77,26 +75,25 @@ foreach(fppsrc IN LISTS sources-fpp) string(REGEX REPLACE "\\.F90" ".f90" f90src ${fppsrc}) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${f90src} - COMMAND ${FYPP} - -I${PROJECT_SOURCE_DIR}/include - ${fyppdefs} ${CMAKE_CURRENT_SOURCE_DIR}/${fppsrc} - ${CMAKE_CURRENT_BINARY_DIR}/${f90src} + COMMAND ${FYPP} -I${PROJECT_SOURCE_DIR}/include ${fyppdefs} + ${CMAKE_CURRENT_SOURCE_DIR}/${fppsrc} ${CMAKE_CURRENT_BINARY_DIR}/${f90src} MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${fppsrc} DEPENDS ${PROJECT_SOURCE_DIR}/include/assert.fypp - VERBATIM) + VERBATIM + ) list(APPEND sources-fpp-f90 ${CMAKE_CURRENT_BINARY_DIR}/${f90src}) endforeach() - - if(WITH_TRANSPORT_GPU) - add_library(negf ${sources-fpp-f90} ${sources-f90} ${sources-cuda}) - else() - add_library(negf ${sources-fpp-f90} ${sources-f90}) - endif() +if(WITH_TRANSPORT_GPU) + add_library(negf ${sources-fpp-f90} ${sources-f90} ${sources-cuda}) +else() + add_library(negf ${sources-fpp-f90} ${sources-f90}) +endif() target_sources(negf PRIVATE $) -target_include_directories(negf PUBLIC - $>) +target_include_directories( + negf PUBLIC $> +) set(BUILD_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) @@ -111,16 +108,13 @@ endif() if(WITH_MPI) find_package(MPI REQUIRED) target_link_libraries(negf PUBLIC MpiFx::MpiFx) - # MPI::MPI_Fortran cannot be made PUBLIC because the compile options of this - # target may cause errors or warnings when passed to a C compiler (e.g., when - # using MPICH 4.0.2 on Debian 12). Unfortunately we cannot manually add - # INTERFACE compile options because this leads to build problems on - # * JUWELS with Rocky Linux 8, ParaStationMPI 5.9.2-1, CMake 3.26.3 and - # * Debian 11, IntelMPI 2021, Intel Fortran 2021 - # due to malformed linker flags (the individual flags are passed as a string - # instead of a list). - # As a consequence of marking this dependency PRIVATE, every dependee of this - # target has to manually add an MPI dependency. + # MPI::MPI_Fortran cannot be made PUBLIC because the compile options of this target may cause + # errors or warnings when passed to a C compiler (e.g., when using MPICH 4.0.2 on Debian 12). + # Unfortunately we cannot manually add INTERFACE compile options because this leads to build + # problems on * JUWELS with Rocky Linux 8, ParaStationMPI 5.9.2-1, CMake 3.26.3 and * Debian 11, + # IntelMPI 2021, Intel Fortran 2021 due to malformed linker flags (the individual flags are passed + # as a string instead of a list). As a consequence of marking this dependency PRIVATE, every + # dependee of this target has to manually add an MPI dependency. target_link_libraries(negf PRIVATE MPI::MPI_Fortran) endif() @@ -129,21 +123,24 @@ if(WITH_TRANSPORT_GPU) target_link_libraries(negf PRIVATE CUDA::cudart CUDA::cusolver CUDA::cublas) endif() -if (NOT "${BLAS_LIBRARY}" STREQUAL "NONE") +if(NOT "${BLAS_LIBRARY}" STREQUAL "NONE") target_link_libraries(negf PRIVATE ${BLAS_LIBRARY}) endif() -if (NOT "${LAPACK_LIBRARY}" STREQUAL "NONE") +if(NOT "${LAPACK_LIBRARY}" STREQUAL "NONE") target_link_libraries(negf PRIVATE ${LAPACK_LIBRARY}) endif() -target_include_directories(negf PUBLIC - $ - $) +target_include_directories( + negf PUBLIC $ + $ +) -install(TARGETS negf +install( + TARGETS negf EXPORT negf-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) if(INSTALL_INCLUDE_FILES) install(DIRECTORY ${BUILD_MOD_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${INSTALL_MOD_DIR}) diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 667f2222..53c9762d 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -4,43 +4,55 @@ set(all-header-deps libnegf_api.f90 bind_fortran) add_custom_target(negf-c-binding ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libnegf.h) set(c-header-binding-deps binding/map_negf_c.txt binding/begin_c.txt binding/end_c.txt) add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libnegf.h - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${all-header-deps} ${CMAKE_CURRENT_SOURCE_DIR}/${c-header-binding-deps} - COMMENT "Generating C header" - COMMAND ./bind_fortran -f c -m binding/map_negf_c.txt -b binding/begin_c.txt -n -t -e binding/end_c.txt libnegf_api.f90 > ${CMAKE_CURRENT_BINARY_DIR}/libnegf.h - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libnegf.h + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${all-header-deps} + ${CMAKE_CURRENT_SOURCE_DIR}/${c-header-binding-deps} + COMMENT "Generating C header" + COMMAND ./bind_fortran -f c -m binding/map_negf_c.txt -b binding/begin_c.txt -n -t -e + binding/end_c.txt libnegf_api.f90 > ${CMAKE_CURRENT_BINARY_DIR}/libnegf.h + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) list(APPEND negf-interface-headers ${CMAKE_CURRENT_BINARY_DIR}/libnegf.h) add_custom_target(negf-cpp-binding ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libnegf.hpp) -set(cpp-header-binding-deps binding/map_negf_cpp_wrapped.txt binding/begin_cpp_wrapped.txt binding/end_cpp_wrapped.txt) +set(cpp-header-binding-deps binding/map_negf_cpp_wrapped.txt binding/begin_cpp_wrapped.txt + binding/end_cpp_wrapped.txt +) add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libnegf.hpp - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${all-header-deps} ${CMAKE_CURRENT_SOURCE_DIR}/${cpp-header-binding-deps} - COMMENT "Generating C++ header" - COMMAND ./bind_fortran -f c++ -m binding/map_negf_cpp_wrapped.txt -b binding/begin_cpp_wrapped.txt -t -e binding/end_cpp_wrapped.txt libnegf_api.f90 > ${CMAKE_CURRENT_BINARY_DIR}/libnegf.hpp - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libnegf.hpp + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${all-header-deps} + ${CMAKE_CURRENT_SOURCE_DIR}/${cpp-header-binding-deps} + COMMENT "Generating C++ header" + COMMAND + ./bind_fortran -f c++ -m binding/map_negf_cpp_wrapped.txt -b binding/begin_cpp_wrapped.txt -t -e + binding/end_cpp_wrapped.txt libnegf_api.f90 > ${CMAKE_CURRENT_BINARY_DIR}/libnegf.hpp + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) list(APPEND negf-interface-headers ${CMAKE_CURRENT_BINARY_DIR}/libnegf.hpp) -add_custom_target(negf-all-headers ALL DEPENDS negf-c-binding negf-cpp-binding ${CMAKE_CURRENT_BINARY_DIR}/lnParams.h) +add_custom_target( + negf-all-headers ALL DEPENDS negf-c-binding negf-cpp-binding + ${CMAKE_CURRENT_BINARY_DIR}/lnParams.h +) add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lnParams.h - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lnParams.h - COMMENT "Copying lnParams.h" - COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/lnParams.h ${CMAKE_CURRENT_BINARY_DIR}/lnParams.h + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lnParams.h + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lnParams.h + COMMENT "Copying lnParams.h" + COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/lnParams.h ${CMAKE_CURRENT_BINARY_DIR}/lnParams.h ) list(APPEND negf-interface-headers ${CMAKE_CURRENT_BINARY_DIR}/lnParams.h) -add_custom_target(negf-fort-headers ALL DEPENDS negf-cpp-binding ${CMAKE_CURRENT_BINARY_DIR}/fortran.h) +add_custom_target( + negf-fort-headers ALL DEPENDS negf-cpp-binding ${CMAKE_CURRENT_BINARY_DIR}/fortran.h +) add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fortran.h - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fortran.h - COMMENT "Copying fortran.h" - COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/fortran.h ${CMAKE_CURRENT_BINARY_DIR}/fortran.h + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fortran.h + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fortran.h + COMMENT "Copying fortran.h" + COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/fortran.h ${CMAKE_CURRENT_BINARY_DIR}/fortran.h ) list(APPEND negf-interface-headers ${CMAKE_CURRENT_BINARY_DIR}/fortran.h) if(INSTALL_INCLUDE_FILES) - install(FILES ${negf-interface-headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(FILES ${negf-interface-headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) endif() diff --git a/src/elphinel.F90 b/src/elphinel.F90 index d2abc65d..dd4dce38 100644 --- a/src/elphinel.F90 +++ b/src/elphinel.F90 @@ -234,7 +234,7 @@ subroutine ElPhonNonPO_init(this, comm, struct, basis, coupling, wq, Temp, & logical, intent(in) :: tridiag this%descriptor = & - & "Electron-Phonon inelastic model for polar-optical phonons" + & "Electron-Phonon inelastic model for non-PO phonons" this%cart_comm = comm this%scba_niter = niter diff --git a/src/gpuroutines.cu b/src/gpuroutines.cu index 6b6b1777..b8ec685d 100644 --- a/src/gpuroutines.cu +++ b/src/gpuroutines.cu @@ -988,7 +988,7 @@ extern "C" int cu_Zdecimation( extern "C" int cu_meminfo(size_t* freemem, size_t* totalmem) { //auto cudaStatus = cudaDeviceSynchronize(); - //printf("STATUS: %d\n",cudaStatus); + //printf("STATUS: %d\n",cudaStatus); //ENFORCE(cudaStatus == cudaSuccess); auto cudaStatus = cudaMemGetInfo(freemem, totalmem); ENFORCE(cudaStatus == cudaSuccess); diff --git a/src/iterative.F90 b/src/iterative.F90 index 0eeb5997..506af787 100644 --- a/src/iterative.F90 +++ b/src/iterative.F90 @@ -1741,6 +1741,9 @@ subroutine calculate_transmissions(negf, Ec, SelfEneR, tun_proj, tun_mat) if (nt.gt.1) then call calculate_Gr_tridiag_blocks(negf,ESH,gsmr,Gr,2,nt) end if +#:if defined("GPU") + call waitForGPU() +#:endif else ! When more contacts are present sometimes we can re-use previous GF ! if nt1 > nt extend the Gr calculation @@ -1749,6 +1752,9 @@ subroutine calculate_transmissions(negf, Ec, SelfEneR, tun_proj, tun_mat) nt = nt1 endif end if +#:if defined("GPU") + call waitForGPU() +#:endif call calculate_single_transmission_N_contacts(negf,nit,nft,ESH,SelfEneR,cblk,negf%tun_proj,gsmr,Gr,tun) @@ -1846,9 +1852,6 @@ subroutine calculate_transmissions_and_dos(negf, Ec, SelfEneR, GS, tun_proj, tun call calculate_Gr_tridiag_blocks(negf,ESH,gsmr,Gr,1) call calculate_Gr_tridiag_blocks(negf,ESH,gsmr,Gr,2,nbl) -#:if defined("GPU") - call waitForGPU() -#:endif !Computation of transmission(s) between contacts ni(:) -> nf(:) #:if defined("GPU") call waitForGPU() diff --git a/src/sparskit/CMakeLists.txt b/src/sparskit/CMakeLists.txt index e69de29b..8b137891 100644 --- a/src/sparskit/CMakeLists.txt +++ b/src/sparskit/CMakeLists.txt @@ -0,0 +1 @@ + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f7da815c..a34954b5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,127 +1,170 @@ +# On some HPC systems (e.g., LUMI), front-end nodes do not feature GPUs or the front-end nodes may +# have an instruction set architecture different from compute nodes (e.g., on Fugaku with its Intel +# front-end and Arm64FX compute nodes). On these systems, GPU tests or all tests, respectively, have +# to be submitted with mpiexec/mpirun. +option(LIBNEGF_TEST_WITH_MPIEXEC "Always launch tests with mpiexec/mpirun" OFF) + # Test input files may be large and are therefore managed by git-lfs. find_program(GIT_LFS git-lfs) if(NOT GIT_LFS) - message(FATAL_ERROR - "Tests cannot be run because git-lfs is missing. " - "Disable testing or install git-lfs." + message(FATAL_ERROR "Tests cannot be run because git-lfs is missing. " + "Disable testing or install git-lfs." ) endif() - # List of active tets. Each test indicates a subdirectory. set(test-directories - f90init - c_mpi_init - cpp_mpi_init - c_int - c_int_elph_deph - c_int_file - f90int - f90int_file - f90_transmission - f90elph_deph - f90read_hs - f90Si2x2 - f90Si_nin - f90Si_nin_40pl - ) + f90init + c_mpi_init + cpp_mpi_init + c_int + c_int_elph_deph + c_int_file + f90int + f90int_file + f90_transmission + f90elph_deph + f90read_hs + f90Si2x2 + f90Si_nin + f90Si_nin_40pl +) if(WITH_TRANSPORT_GPU) list(APPEND test-directories testCUDA) list(APPEND test-directories testCUDA_decimation) endif() -# Define a function wich copies over the content of the tests. -# This is used to support out-of-source build, as the test -# directory contain input files which we don't want to specify. +# Define a function wich copies over the content of the tests. This is used to support out-of-source +# build, as the test directory contain input files which we don't want to specify. function(transfer_test_data testname) - if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - add_custom_target(${testname}-data-transfer) - else() - add_custom_target( - ${testname}-data-transfer - COMMENT "Copying ${CMAKE_CURRENT_SOURCE_DIR} for out-of-source build." - COMMAND cp -f ${CMAKE_CURRENT_SOURCE_DIR}/* ${CMAKE_CURRENT_BINARY_DIR}/) - endif() - add_dependencies(${testname} ${testname}-data-transfer) + if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + add_custom_target(${testname}-data-transfer) + else() + add_custom_target( + ${testname}-data-transfer + COMMENT "Copying ${CMAKE_CURRENT_SOURCE_DIR} for out-of-source build." + COMMAND cp -f ${CMAKE_CURRENT_SOURCE_DIR}/* ${CMAKE_CURRENT_BINARY_DIR}/ + ) + endif() + add_dependencies(${testname} ${testname}-data-transfer) endfunction() function(unzip_test_data testname) - find_program(XZ NAMES xz) - if(NOT XZ) - message(FATAL_ERROR "cannot run test '${testname}' because xz executable is missing") - endif() - - if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") - add_custom_target(${testname}-data-unzip) - else() - add_custom_target( - ${testname}-data-unzip - COMMENT "unzip ${CMAKE_CURRENT_SOURCE_DIR} for out-of-source build." - COMMAND tar -xJf ${CMAKE_CURRENT_SOURCE_DIR}/*.tar.xz -C ${CMAKE_CURRENT_BINARY_DIR}) - endif() - add_dependencies(${testname}-data-unzip ${testname}-data-transfer) - add_dependencies(${testname} ${testname}-data-unzip) -endfunction() + find_program(XZ NAMES xz) + if(NOT XZ) + message(FATAL_ERROR "cannot run test '${testname}' because xz executable is missing") + endif() -# A function to setup C++ tests. -function(setup_cpp_test testname label source) - message(STATUS "add test: " ${testname} " " ${source} " " ${label}) - add_executable(${testname} ${source}) - transfer_test_data(${testname}) - target_link_libraries(${testname} MPI::MPI_CXX) - target_link_libraries(${testname} negf) - target_link_libraries(${testname} LAPACK::LAPACK) - target_include_directories(${testname} PRIVATE ${CMAKE_BINARY_DIR}/src/api) - add_test( - NAME ${testname} - COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ./${testname}) - set_property(TEST ${testname} PROPERTY LABELS ${label}) + if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + add_custom_target(${testname}-data-unzip) + else() + add_custom_target( + ${testname}-data-unzip + COMMENT "unzip ${CMAKE_CURRENT_SOURCE_DIR} for out-of-source build." + COMMAND tar -xJf ${CMAKE_CURRENT_SOURCE_DIR}/*.tar.xz -C ${CMAKE_CURRENT_BINARY_DIR} + ) + endif() + add_dependencies(${testname}-data-unzip ${testname}-data-transfer) + add_dependencies(${testname} ${testname}-data-unzip) endfunction() -# A function to setup C tests. -function(setup_c_test testname label source) - message(STATUS "add test: " ${testname} " " ${source} " " ${label}) - add_executable(${testname} ${source} ${ARGN}) - transfer_test_data(${testname}) +function(setup_test testname source_main) + set(options GPUONLY MPI) + set(multi_value_args SOURCES LABELS) + cmake_parse_arguments(PARSE_ARGV 2 LIBNEGF_TEST "${options}" "" "${multi_value_args}") + + if(LIBNEGF_TEST_UNPARSED_ARGUMENTS) + message(WARNING "could not parse the following arguments: ${LIBNEGF_TEST_UNPARSED_ARGUMENTS}") + endif() + if(LIBNEGF_TEST_KEYWORDS_MISSING_VALUES) + message( + WARNING + "the following keyword arguments are missing values: ${LIBNEGF_TEST_KEYWORDS_MISSING_VALUES}" + ) + endif() + + list(PREPEND LIBNEGF_TEST_SOURCES ${source_main}) + if(LIBNEGF_TEST_GPUONLY) + list(APPEND LIBNEGF_TEST_LABELS gpu-only) + endif() + if(LIBNEGF_TEST_MPI) + list(APPEND LIBNEGF_TEST_LABELS mpi) + endif() + + # detect implementation language + if(source_main MATCHES "[.]c$") + set(LIBNEGF_TEST_LANG C) + elseif(source_main MATCHES "[.]cpp$") + set(LIBNEGF_TEST_LANG CXX) + elseif(source_main MATCHES "[.](f|F)90$") + set(LIBNEGF_TEST_LANG Fortran) + else() + message(SEND_ERROR "unknown file extension of test source ${source_main}") + endif() + + message(DEBUG "add test: ${testname} ${LIBNEGF_TEST_SOURCES} ${LIBNEGF_TEST_LABELS}") + + # set up test compilation + add_executable(${testname} ${LIBNEGF_TEST_SOURCES}) + + if(LIBNEGF_TEST_LANG STREQUAL C) target_link_libraries(${testname} MPI::MPI_C) - target_link_libraries(${testname} negf) - target_link_libraries(${testname} LAPACK::LAPACK) target_include_directories(${testname} PRIVATE ${CMAKE_BINARY_DIR}/src/api) - add_test(${testname} ${testname}) - set_property(TEST ${testname} PROPERTY LABELS ${label}) -endfunction() - -# A function to setup F90 tests. -function(setup_f90_test testname label source) - message(STATUS "add test: " ${testname} " " ${source} " " ${label}) - add_executable(${testname} ${source} ${ARGN}) - transfer_test_data(${testname}) + elseif(LIBNEGF_TEST_LANG STREQUAL CXX) + target_link_libraries(${testname} MPI::MPI_CXX) + target_include_directories(${testname} PRIVATE ${CMAKE_BINARY_DIR}/src/api) + elseif(LIBNEGF_TEST_LANG STREQUAL Fortran) target_link_libraries(${testname} MPI::MPI_Fortran) - target_link_libraries(${testname} negf) - target_link_libraries(${testname} LAPACK::LAPACK) target_include_directories(${testname} PRIVATE ${BUILD_MOD_DIR}) - add_test(${testname} ${testname}) - set_property(TEST ${testname} PROPERTY LABELS ${label}) -endfunction() + endif() + target_link_libraries(${testname} negf) + target_link_libraries(${testname} LAPACK::LAPACK) -# A function to setup F90 tests with MPI. -function(setup_f90_mpi_test testname label source) - message(STATUS "add test: " ${testname} " " ${source} " " ${label}) - add_executable(${testname} ${source} ${ARGN}) - transfer_test_data(${testname}) - target_link_libraries(${testname} MPI::MPI_Fortran) - target_link_libraries(${testname} negf) - target_link_libraries(${testname} LAPACK::LAPACK) - target_include_directories(${testname} PRIVATE ${BUILD_MOD_DIR}) - add_test( - NAME ${testname} - COMMAND env OMP_NUM_THREADS=1 ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ./${testname}) - set_property(TEST ${testname} PROPERTY LABELS ${label}) -endfunction() + # determine how to execute the test + if(${LIBNEGF_TEST_MPI}) + set(num_procs ${MPIEXEC_MAX_NUMPROCS}) + set(cmd + # When running on a user's PC, it is possible to thrash the machine by having one MPI task + # per core and one OpenMP thread per task and per core (the default). The restriction below + # aims to avoid this scenario. + # + # `env` is wrapping the call to mpiexec/mpirun to avoid the job name `env` when + # ${MPIEXEC_EXECUTABLE} is a batch scheduler. This works with Slurm but some batch + # schedulers (e.g., OAR) filter the set of environment variables (the OAR documentation [1] + # even mentions `OMP_NUM_THREADS` explicitly). + # + # [1] https://oar.imag.fr/wiki:passing_environment_variables_to_openmpi_nodes + env + OMP_NUM_THREADS=1 + ${MPIEXEC_EXECUTABLE} + ${MPIEXEC_NUMPROC_FLAG} + ${num_procs} + ${MPIEXEC_PREFLAGS} + ./${testname} + ${MPIEXEC_POSTFLAGS} + ) + elseif(${LIBNEGF_TEST_WITH_MPIEXEC} AND NOT ${LIBNEGF_TEST_MPI}) + set(num_procs 1) + set(cmd ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${num_procs} ${MPIEXEC_PREFLAGS} + ./${testname} ${MPIEXEC_POSTFLAGS} + ) + else() + set(cmd ${testname}) + endif() + add_test(NAME ${testname} COMMAND ${cmd}) + set_property(TEST ${testname} PROPERTY LABELS ${LIBNEGF_TEST_LABELS}) + set_property(TEST ${testname} PROPERTY PROCESSORS ${num_procs}) + + transfer_test_data(${testname}) +endfunction() foreach(test-directory IN LISTS test-directories) - add_subdirectory(${test-directory}) + add_subdirectory(${test-directory}) endforeach() + +add_executable(ext_system_test ext_system_test.f90) +target_link_libraries(ext_system_test syscalls_objlib) +add_test(ext_system_test ext_system_test) diff --git a/tests/c_int/CMakeLists.txt b/tests/c_int/CMakeLists.txt index 944afcef..56f40f3a 100644 --- a/tests/c_int/CMakeLists.txt +++ b/tests/c_int/CMakeLists.txt @@ -1 +1 @@ -setup_c_test(c_int "normal" hello.c) +setup_test(c_int hello.c) diff --git a/tests/c_int_elph_deph/CMakeLists.txt b/tests/c_int_elph_deph/CMakeLists.txt index c277efad..4a25b6a5 100644 --- a/tests/c_int_elph_deph/CMakeLists.txt +++ b/tests/c_int_elph_deph/CMakeLists.txt @@ -1 +1 @@ -setup_c_test(c_int_elph_deph "normal" c_int_elph_deph.c) +setup_test(c_int_elph_deph c_int_elph_deph.c) diff --git a/tests/c_int_file/CMakeLists.txt b/tests/c_int_file/CMakeLists.txt index 97d0d72c..bd2b0526 100644 --- a/tests/c_int_file/CMakeLists.txt +++ b/tests/c_int_file/CMakeLists.txt @@ -1 +1 @@ -setup_c_test(c_int_file "normal" hello.c) +setup_test(c_int_file hello.c) diff --git a/tests/c_mpi_init/CMakeLists.txt b/tests/c_mpi_init/CMakeLists.txt index a81a8ddb..c643a2c0 100644 --- a/tests/c_mpi_init/CMakeLists.txt +++ b/tests/c_mpi_init/CMakeLists.txt @@ -1 +1 @@ -setup_c_test(c_mpi_init "normal" c_mpi_init.c) +setup_test(c_mpi_init c_mpi_init.c) diff --git a/tests/cpp_mpi_init/CMakeLists.txt b/tests/cpp_mpi_init/CMakeLists.txt index e349010d..16250a9a 100644 --- a/tests/cpp_mpi_init/CMakeLists.txt +++ b/tests/cpp_mpi_init/CMakeLists.txt @@ -1 +1 @@ -setup_cpp_test(cpp_mpi_init "normal" cpp_mpi_init.cpp) +setup_test(cpp_mpi_init cpp_mpi_init.cpp MPI) diff --git a/tests/cpp_mpi_init/cpp_mpi_init.cpp b/tests/cpp_mpi_init/cpp_mpi_init.cpp index 6ddc4ef0..9d3c1835 100644 --- a/tests/cpp_mpi_init/cpp_mpi_init.cpp +++ b/tests/cpp_mpi_init/cpp_mpi_init.cpp @@ -1,37 +1,52 @@ - +/*!!--------------------------------------------------------------------------! + *!! libNEGF: a general library for Non-Equilibrium Greens functions. ! + *!! Copyright (C) 2012 - 2026 ! + *!! ! + *!! This file is part of libNEGF: a library for ! + *!! Non Equilibrium Green's Function calculation ! + *!! ! + *!! Developers: Alessandro Pecchia, Daniele Soccodato ! + *!! Former Contributors: Gabriele Penazzi, Luca Latessa, Aldo Di Carlo ! + *!! ! + *!! libNEGF is free software: you can redistribute it and/or modify ! + *!! it under the terms of the GNU Lesse General Public License as published ! + *!! by the Free Software Foundation, either version 3 of the License, or ! + *!! (at your option) any later version. ! + *!! ! + *!! You should have received a copy of the GNU Lesser General Public ! + *!! License along with libNEGF. If not, see ! + *!! . ! + *!!--------------------------------------------------------------------------! + */ #include "libnegf.hpp" -#include -#include + #include -int main() -{ - int handler[NEGF_HSIZE]; - int *hand = &handler[0]; - int ierr; +#include +#include - ierr = MPI_Init(NULL, NULL); - if (ierr != 0) - { - printf("Error in mpi_init \n"); - return 1; - } - printf("Initializing libNEGF \n"); - negf_init_session(hand); - negf_init(hand); +int main() { + int ierr = MPI_Init(nullptr, nullptr); + if(ierr != 0) { + fprintf(stderr, "Error in mpi_init: %d\n", ierr); + return 1; + } - MPI_Fint global_comm_f = MPI_Comm_c2f(MPI_COMM_WORLD); - negf_set_mpi_fcomm(hand, global_comm_f); - MPI_Fint cart_comm, k_comm, en_comm; - negf_cartesian_init(hand, global_comm_f, 1, cart_comm, k_comm, en_comm); + printf("Initializing libNEGF\n"); + int handler[NEGF_HSIZE]; + negf_init_session(handler); + negf_init(handler); - //Release library - negf_destruct_libnegf(hand); - negf_destruct_session(hand); - printf("Done \n"); + MPI_Fint global_comm_f = MPI_Comm_c2f(MPI_COMM_WORLD); + negf_set_mpi_fcomm(handler, global_comm_f); + MPI_Fint cart_comm, k_comm, en_comm; + negf_cartesian_init(handler, global_comm_f, 1, cart_comm, k_comm, en_comm); - MPI_Finalize(); + //Release library + negf_destruct_libnegf(handler); + negf_destruct_session(handler); + printf("Done\n"); - return 0; + MPI_Finalize(); } diff --git a/ext_system/test.f90 b/tests/ext_system_test.f90 similarity index 66% rename from ext_system/test.f90 rename to tests/ext_system_test.f90 index 1f30d2e6..034c104c 100644 --- a/ext_system/test.f90 +++ b/tests/ext_system_test.f90 @@ -4,7 +4,7 @@ program test character(100) :: folder - folder = "testfolder" + folder = "ext_system_testfolder" call create_directory(trim(folder)) @@ -12,9 +12,9 @@ program test write(101, *) 'test', 101 close(101) - !call remove_file(trim(folder)//'/afile') + call remove_file(trim(folder)//'/afile') - !call remove_directory(folder) + call remove_directory(folder) end program test diff --git a/tests/f90Si2x2/CMakeLists.txt b/tests/f90Si2x2/CMakeLists.txt index 840a2cec..57f108db 100644 --- a/tests/f90Si2x2/CMakeLists.txt +++ b/tests/f90Si2x2/CMakeLists.txt @@ -1,10 +1,7 @@ -set(sources - constants.F90 - readHS.F90 - matconv.F90 - test.F90) - -setup_f90_mpi_test(f90Si2x2 "normal" ${sources}) - +setup_test( + f90Si2x2 test.F90 + MPI + SOURCES constants.F90 matconv.F90 readHS.F90 + LABELS long +) unzip_test_data(f90Si2x2 "hs.tar.xz") - diff --git a/tests/f90Si_nin/CMakeLists.txt b/tests/f90Si_nin/CMakeLists.txt index 7721c875..69b6034c 100644 --- a/tests/f90Si_nin/CMakeLists.txt +++ b/tests/f90Si_nin/CMakeLists.txt @@ -1,10 +1,7 @@ -set(sources - constants.F90 - readHS.F90 - matconv.F90 - test.F90) - -setup_f90_mpi_test(f90Si_nin "long" ${sources}) - +setup_test( + f90Si_nin test.F90 + MPI + SOURCES constants.F90 matconv.F90 readHS.F90 + LABELS long +) unzip_test_data(f90Si_nin "hs.tar.xz") - diff --git a/tests/f90Si_nin/transmission_ref.dat b/tests/f90Si_nin/transmission_ref.dat index afc74509..39516429 100644 --- a/tests/f90Si_nin/transmission_ref.dat +++ b/tests/f90Si_nin/transmission_ref.dat @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:020e400bdde24a9fdf260ea757b134afda07bda65b725b62cfb3a86bad60ad30 +oid sha256:20d144dba082e78dae2d676ae8871812d4ad7aa37879a44ff2de9f8d7424677f size 784 diff --git a/tests/f90Si_nin_40pl/CMakeLists.txt b/tests/f90Si_nin_40pl/CMakeLists.txt index a1643d9a..5a79e652 100644 --- a/tests/f90Si_nin_40pl/CMakeLists.txt +++ b/tests/f90Si_nin_40pl/CMakeLists.txt @@ -1,10 +1,7 @@ -set(sources - constants.F90 - readHS.F90 - matconv.F90 - test.F90) - -setup_f90_mpi_test(f90Si_nin_40pl "long" ${sources}) - +setup_test( + f90Si_nin_40pl test.F90 + MPI + SOURCES constants.F90 matconv.F90 readHS.F90 + LABELS long +) unzip_test_data(f90Si_nin_40pl "hs.tar.xz") - diff --git a/tests/f90Si_nin_40pl/test.F90 b/tests/f90Si_nin_40pl/test.F90 index 78b2c7fa..ba8f3839 100644 --- a/tests/f90Si_nin_40pl/test.F90 +++ b/tests/f90Si_nin_40pl/test.F90 @@ -30,8 +30,16 @@ program test call mpifx_init(impierr); call globalComm%init(); - nGroups = 1 + if (globalComm%size < 4) then + if (globalComm%lead) then + write(*,*) 'ERROR: this test is designed to run on at least 4 processes' + end if + stop + else + nGroups = 4 + end if + pnegf => negf if (globalComm%lead) write(*,*) 'Initializing libNEGF' @@ -127,10 +135,20 @@ program test ! Here we set the parameters, only the ones different from default ! ---------------------------------------------------------------------------------- call get_params(pnegf, params) - params%verbose = 100 - params%Emin = mu(1)-10.0_dp*kt(1)+0.012_dp ! -0.298 - params%Emax = mu(2)+10.0_dp*kt(1)-0.010_dp ! +0.30 - params%Estep = 0.002_dp + params%verbose = 100 + ! The following parameters are good for benchmarks (300 Epoints) + !params%Emin = mu(1)-10.0_dp*kt(1)+0.012_dp/eV2Hartree ! -0.298 + !params%Emax = mu(2)+10.0_dp*kt(1)-0.010_dp/eV2Hartree ! +0.30 + !params%Estep = 0.002_dp/eV2Hartree + + ! The following parameters are used for testing (20 Epoints) + params%Emax = mu(1)+10.0_dp*kt(1) ! mu+0.26 + params%Emin = mu(1)-0.12_dp/eV2Hartree ! mu-0.13 + params%Estep = 0.02_dp/eV2Hartree + + if (globalComm%lead) then + write(*,*) 'nPoints=',(params%Emax-params%Emin)/params%Estep + 1 + end if ! nStep = 0.598/0.002 + 1 = 300 params%delta = 1.e-5_dp !Already in Hartree params%mu(1:2) = mu diff --git a/tests/f90Si_nin_40pl/transmission_ref.dat b/tests/f90Si_nin_40pl/transmission_ref.dat new file mode 100644 index 00000000..ca415a19 --- /dev/null +++ b/tests/f90Si_nin_40pl/transmission_ref.dat @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:960ada2bac077c2f149093643bd7d6c1b2a5c1a12580f019817e6bab676155c1 +size 980 diff --git a/tests/f90_transmission/CMakeLists.txt b/tests/f90_transmission/CMakeLists.txt index ff77843b..379acd57 100644 --- a/tests/f90_transmission/CMakeLists.txt +++ b/tests/f90_transmission/CMakeLists.txt @@ -1 +1 @@ -setup_f90_test(f90_transmission "normal" hello.F90) +setup_test(f90_transmission hello.F90) diff --git a/tests/f90elph_deph/CMakeLists.txt b/tests/f90elph_deph/CMakeLists.txt index 3be2bbea..27a405da 100644 --- a/tests/f90elph_deph/CMakeLists.txt +++ b/tests/f90elph_deph/CMakeLists.txt @@ -1 +1 @@ -setup_f90_test(f90elph_deph "normal" hello.F90) +setup_test(f90elph_deph hello.F90) diff --git a/tests/f90init/CMakeLists.txt b/tests/f90init/CMakeLists.txt index e1421948..928750fb 100644 --- a/tests/f90init/CMakeLists.txt +++ b/tests/f90init/CMakeLists.txt @@ -1 +1 @@ -setup_f90_test(f90init "normal" f90init.F90) +setup_test(f90init f90init.F90) diff --git a/tests/f90int/CMakeLists.txt b/tests/f90int/CMakeLists.txt index 40128108..4b9b66ff 100644 --- a/tests/f90int/CMakeLists.txt +++ b/tests/f90int/CMakeLists.txt @@ -1 +1 @@ -setup_f90_test(f90int "normal" hello.F90) +setup_test(f90int hello.F90) diff --git a/tests/f90int_file/CMakeLists.txt b/tests/f90int_file/CMakeLists.txt index 714a6da7..c10406b4 100644 --- a/tests/f90int_file/CMakeLists.txt +++ b/tests/f90int_file/CMakeLists.txt @@ -1 +1 @@ -setup_f90_test(f90int_file "normal" hello.F90) +setup_test(f90int_file hello.F90) diff --git a/tests/f90read_hs/CMakeLists.txt b/tests/f90read_hs/CMakeLists.txt index 888f10a4..3d37ea20 100644 --- a/tests/f90read_hs/CMakeLists.txt +++ b/tests/f90read_hs/CMakeLists.txt @@ -1,7 +1,5 @@ -set(sources - constants.F90 - readHS.F90 - matconv.F90 - test.F90) - -setup_f90_test(f90read_hs "normal unit" ${sources}) +setup_test( + f90read_hs test.F90 + SOURCES constants.F90 matconv.F90 readHS.F90 + LABELS unit +) diff --git a/tests/f90read_hs/readHS.F90 b/tests/f90read_hs/readHS.F90 index 7c3a10b6..28ed4adb 100644 --- a/tests/f90read_hs/readHS.F90 +++ b/tests/f90read_hs/readHS.F90 @@ -415,7 +415,7 @@ subroutine apply_shifts(ham, over, shift) real(dp) :: tmpH(orb%mOrb,orb%mOrb), tmpS(orb%mOrb,orb%mOrb) real(dp) :: shiftBlk1(orb%mOrb,orb%mOrb) real(dp) :: shiftBlk2(orb%mOrb,orb%mOrb) - + nAtom = size(orb%nOrbAtom) shiftBlk1 = 0.0_dp shiftBlk2 = 0.0_dp @@ -427,8 +427,8 @@ subroutine apply_shifts(ham, over, shift) iAt2f = img2CentCell(iAt2) nOrb2 = orb%nOrbAtom(iAt2f) iOrig1 = iPair(iNeigh, iAt1) - iBlk1 = iAtomStart(iAt1)-1 - iBlk2 = iAtomStart(iAt2f)-1 + iBlk1 = iAtomStart(iAt1-1)-1 + iBlk2 = iAtomStart(iAt2f-1)-1 do ii = 1, nOrb1 shiftBlk1(ii,ii) = shift(iBlk1+ii) end do diff --git a/tests/testCUDA/CMakeLists.txt b/tests/testCUDA/CMakeLists.txt index 5c8bfcef..08114436 100644 --- a/tests/testCUDA/CMakeLists.txt +++ b/tests/testCUDA/CMakeLists.txt @@ -1 +1 @@ -setup_f90_test(testCUDA "normal cuda" test.f90) +setup_test(testCUDA test.f90 GPUONLY) diff --git a/tests/testCUDA_decimation/CMakeLists.txt b/tests/testCUDA_decimation/CMakeLists.txt index 5e542596..5d1c4442 100644 --- a/tests/testCUDA_decimation/CMakeLists.txt +++ b/tests/testCUDA_decimation/CMakeLists.txt @@ -1,5 +1,5 @@ -set(sources - main.f90 - random.f90) - -setup_f90_test(testCUDA_decimation "normal cuda" ${sources}) +setup_test( + testCUDA_decimation main.f90 + GPUONLY + SOURCES random.f90 +)