diff --git a/.cmake-format.json b/.cmake-format.json new file mode 100644 index 00000000..3104542b --- /dev/null +++ b/.cmake-format.json @@ -0,0 +1,44 @@ +{ + "format": { + "disable": false, + "line_width": 80, + "tab_size": 2, + "use_tabchars": false, + "fractional_tab_policy": "use-space", + "max_subgroups_hwrap": 2, + "max_pargs_hwrap": 6, + "max_rows_cmdline": 2, + "separate_ctrl_name_with_space": false, + "separate_fn_name_with_space": false, + "dangle_parens": false, + "dangle_align": "prefix", + "min_prefix_chars": 4, + "max_prefix_chars": 10, + "max_lines_hwrap": 2, + "line_ending": "unix", + "command_case": "canonical", + "keyword_case": "unchanged", + "always_wrap": [], + "enable_sort": true, + "autosort": false, + "require_valid_layout": false, + "layout_passes": {} + }, + "markup": { + "bullet_char": "*", + "enum_char": ".", + "first_comment_is_literal": false, + "literal_comment_pattern": null, + "fence_pattern": "^\\s*([`~]{3}[`~]*)(.*)$", + "ruler_pattern": "^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$", + "explicit_trailing_pattern": "#<", + "hashruler_min_length": 10, + "canonicalize_hashrulers": false, + "enable_markup": true + }, + "encode": { + "emit_byteorder_mark": false, + "input_encoding": "utf-8", + "output_encoding": "utf-8" + }, +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f60ff1f8..64b38abf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,8 @@ repos: - id: clang-format types_or: [c++] args: ["-style=file", "-i"] + + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format diff --git a/CMakeLists.txt b/CMakeLists.txt index 3708e342..2436bd07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,16 +11,17 @@ find_package(Finch QUIET) if(ExaCA_REQUIRE_FINCH OR Finch_FOUND) set(ExaCA_ENABLE_FINCH ON) find_package(Finch REQUIRED COMPONENTS Finch::Core Finch::ScanPaths) - message( STATUS "Finch heat transfer enabled." ) + message(STATUS "Finch heat transfer enabled.") endif() find_package(Kokkos 4.0 REQUIRED) find_package(MPI REQUIRED) -if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") cmake_policy(SET CMP0135 NEW) endif() -option(ExaCA_REQUIRE_EXTERNAL_JSON "Build without automatic JSON dependency download" OFF) +option(ExaCA_REQUIRE_EXTERNAL_JSON + "Build without automatic JSON dependency download" OFF) if(ExaCA_REQUIRE_EXTERNAL_JSON) find_package(nlohmann_json 3.10.0 REQUIRED) else() @@ -28,10 +29,14 @@ else() if(NOT NLOHMANN_JSON_FOUND) include(FetchContent) # Using most recent release here - FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz) + FetchContent_Declare( + json + URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz + ) FetchContent_MakeAvailable(json) # Needs to be installed only in this case. - install(TARGETS nlohmann_json + install( + TARGETS nlohmann_json EXPORT ExaCA_Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -40,34 +45,32 @@ endif() find_package(Git) if(GIT_FOUND AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.git) - EXECUTE_PROCESS( - COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -n 1 + execute_process( + COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -n 1 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE ExaCA_GIT_COMMIT_HASH - ) + OUTPUT_VARIABLE ExaCA_GIT_COMMIT_HASH) else() set(ExaCA_GIT_COMMIT_HASH "Not a git repository") endif() message(STATUS "ExaCA commit: ${ExaCA_GIT_COMMIT_HASH}") -# NOTE: this order is specifically used in the unit tests. -# FIXME: remove PTHREAD +# NOTE: this order is specifically used in the unit tests. FIXME: remove PTHREAD set(EXACA_SUPPORTED_DEVICES SERIAL PTHREAD THREADS OPENMP CUDA HIP) add_subdirectory(src) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ExaCAconfig.cmakein - ${CMAKE_CURRENT_BINARY_DIR}/ExaCAconfig.cmake @ONLY) + ${CMAKE_CURRENT_BINARY_DIR}/ExaCAconfig.cmake @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ExaCAconfig.cmake" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExaCA) + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExaCA) # Install data files file(GLOB MATERIALS examples/Materials/*) file(GLOB SUBSTRATE examples/Substrate/GrainOrientation*.csv) install(FILES ${MATERIALS} - DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA) + DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA) install(FILES ${SUBSTRATE} - DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA) + DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/ExaCA) option(ExaCA_ENABLE_TESTING "Build unit tests" OFF) @@ -100,10 +103,11 @@ add_subdirectory(analysis) # clang-format set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -find_package( CLANG_FORMAT 10) +find_package(CLANG_FORMAT 10) if(CLANG_FORMAT_FOUND) file(GLOB_RECURSE FORMAT_SOURCES *.[c,h]pp) - add_custom_target(format + add_custom_target( + format COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file ${FORMAT_SOURCES} DEPENDS ${FORMAT_SOURCES}) endif() diff --git a/analysis/bin/CMakeLists.txt b/analysis/bin/CMakeLists.txt index bcffb24c..a6da2ed3 100644 --- a/analysis/bin/CMakeLists.txt +++ b/analysis/bin/CMakeLists.txt @@ -3,7 +3,7 @@ target_link_libraries(ExaCA-GrainAnalysis ExaCA-Analysis) install(TARGETS ExaCA-GrainAnalysis DESTINATION ${CMAKE_INSTALL_BINDIR}) # Symlink for backwards compatibility -add_custom_target(grain_analysis ALL - COMMAND ${CMAKE_COMMAND} -E create_symlink ExaCA-GrainAnalysis grain_analysis) +add_custom_target(grain_analysis ALL COMMAND ${CMAKE_COMMAND} -E create_symlink + ExaCA-GrainAnalysis grain_analysis) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/grain_analysis DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/analysis/src/CMakeLists.txt b/analysis/src/CMakeLists.txt index 9c753b71..278f6e1c 100644 --- a/analysis/src/CMakeLists.txt +++ b/analysis/src/CMakeLists.txt @@ -8,12 +8,14 @@ add_library(ExaCA::Analysis ALIAS ExaCA-Analysis) target_link_libraries(ExaCA-Analysis PUBLIC ExaCA-Core) -target_include_directories(ExaCA-Analysis PUBLIC - $ - $ - $) +target_include_directories( + ExaCA-Analysis + PUBLIC $ + $ + $) -install(TARGETS ExaCA-Analysis +install( + TARGETS ExaCA-Analysis EXPORT ExaCA_Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/analysis/unit_test/CMakeLists.txt b/analysis/unit_test/CMakeLists.txt index 5894adfc..b37b5fa3 100644 --- a/analysis/unit_test/CMakeLists.txt +++ b/analysis/unit_test/CMakeLists.txt @@ -1,4 +1,4 @@ include(${TEST_HARNESS_DIR}/test_harness.cmake) -ExaCA_add_tests(PACKAGE ExaCA-Analysis NAMES Utils KokkosUtils) -ExaCA_add_tests(PACKAGE ExaCA-Analysis NAMES RepresentativeRegion) +exaca_add_tests(PACKAGE ExaCA-Analysis NAMES Utils KokkosUtils) +exaca_add_tests(PACKAGE ExaCA-Analysis NAMES RepresentativeRegion) diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index fce08dde..8a268444 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -3,8 +3,8 @@ target_link_libraries(ExaCA ExaCA-Core) install(TARGETS ExaCA DESTINATION ${CMAKE_INSTALL_BINDIR}) # Symlink for backwards compatibility -add_custom_target(ExaCA-Kokkos ALL - COMMAND ${CMAKE_COMMAND} -E create_symlink ExaCA ExaCA-Kokkos) +add_custom_target(ExaCA-Kokkos ALL COMMAND ${CMAKE_COMMAND} -E create_symlink + ExaCA ExaCA-Kokkos) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ExaCA-Kokkos DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/cmake/FindCLANG_FORMAT.cmake b/cmake/FindCLANG_FORMAT.cmake index 7dd6605e..f07ba7c9 100644 --- a/cmake/FindCLANG_FORMAT.cmake +++ b/cmake/FindCLANG_FORMAT.cmake @@ -1,43 +1,42 @@ # Find clang-format # -# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable -# CLANG_FORMAT_FOUND - True if the clang-format executable was found. -# CLANG_FORMAT_VERSION - The version of clang-format found +# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable CLANG_FORMAT_FOUND +# - True if the clang-format executable was found. CLANG_FORMAT_VERSION - +# The version of clang-format found # -find_program(CLANG_FORMAT_EXECUTABLE - NAMES clang-format - clang-format-10 - clang-format-9 - clang-format-8 - clang-format-7 - clang-format-6.0 - clang-format-5.0 - clang-format-4.0 - clang-format-3.9 - clang-format-3.8 - clang-format-3.7 - clang-format-3.6 - clang-format-3.5 - clang-format-3.4 - clang-format-3.3 - DOC "clang-format executable") +find_program( + CLANG_FORMAT_EXECUTABLE + NAMES clang-format + clang-format-10 + clang-format-9 + clang-format-8 + clang-format-7 + clang-format-6.0 + clang-format-5.0 + clang-format-4.0 + clang-format-3.9 + clang-format-3.8 + clang-format-3.7 + clang-format-3.6 + clang-format-3.5 + clang-format-3.4 + clang-format-3.3 + DOC "clang-format executable") mark_as_advanced(CLANG_FORMAT_EXECUTABLE) # Extract version from command "clang-format -version" if(CLANG_FORMAT_EXECUTABLE) - execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version - OUTPUT_VARIABLE clang_format_version - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process( + COMMAND ${CLANG_FORMAT_EXECUTABLE} -version + OUTPUT_VARIABLE clang_format_version + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) if(clang_format_version MATCHES "^.*clang-format version .*") # clang_format_version sample: "clang-format version 3.9.1-4ubuntu3~16.04.1 # (tags/RELEASE_391/rc2)" - string(REGEX - REPLACE "^.*clang-format version ([.0-9]+).*" - "\\1" - CLANG_FORMAT_VERSION - "${clang_format_version}") + string(REGEX REPLACE "^.*clang-format version ([.0-9]+).*" "\\1" + CLANG_FORMAT_VERSION "${clang_format_version}") # CLANG_FORMAT_VERSION sample: "3.9.1" else() set(CLANG_FORMAT_VERSION 0.0) @@ -49,4 +48,7 @@ endif() include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set CLANG_FORMAT_FOUND to TRUE # if all listed variables are TRUE -find_package_handle_standard_args(CLANG_FORMAT REQUIRED_VARS CLANG_FORMAT_EXECUTABLE VERSION_VAR CLANG_FORMAT_VERSION) +find_package_handle_standard_args( + CLANG_FORMAT + REQUIRED_VARS CLANG_FORMAT_EXECUTABLE + VERSION_VAR CLANG_FORMAT_VERSION) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 21811a65..66c26d09 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,31 +5,32 @@ file(GLOB EXACA_SOURCES GLOB *.cpp) install(FILES ${EXACA_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CAconfig.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CAconfig.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) add_library(ExaCA-Core ${EXACA_SOURCES}) add_library(ExaCA::Core ALIAS ExaCA-Core) -target_link_libraries(ExaCA-Core PUBLIC - MPI::MPI_CXX - Kokkos::kokkos - nlohmann_json::nlohmann_json -) +target_link_libraries(ExaCA-Core PUBLIC MPI::MPI_CXX Kokkos::kokkos + nlohmann_json::nlohmann_json) if(ExaCA_ENABLE_FINCH) target_link_libraries(ExaCA-Core PUBLIC Finch::Core Finch::ScanPaths) endif() -target_include_directories(ExaCA-Core PUBLIC - $ - $ - $) +target_include_directories( + ExaCA-Core + PUBLIC $ + $ + $) -install(TARGETS ExaCA-Core +install( + TARGETS ExaCA-Core EXPORT ExaCA_Targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(EXPORT ExaCA_Targets +install( + EXPORT ExaCA_Targets FILE ExaCA_Targets.cmake NAMESPACE ExaCA:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExaCA) diff --git a/unit_test/CMakeLists.txt b/unit_test/CMakeLists.txt index 52c9c94d..3a495818 100644 --- a/unit_test/CMakeLists.txt +++ b/unit_test/CMakeLists.txt @@ -1,25 +1,48 @@ include(${TEST_HARNESS_DIR}/test_harness.cmake) -##--------------------------------------------------------------------------## -## Install example files used in tests -##--------------------------------------------------------------------------## -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallDirSolidification.json +# --------------------------------------------------------------------------## +# Install example files used in tests +# --------------------------------------------------------------------------## +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallDirSolidification.json ${CMAKE_CURRENT_BINARY_DIR}/Inp_SmallDirSolidification.json COPYONLY) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_DirSolidification.json +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_DirSolidification.json ${CMAKE_CURRENT_BINARY_DIR}/Inp_DirSolidification.json COPYONLY) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_TwoGrainDirSolidification.json +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_TwoGrainDirSolidification.json ${CMAKE_CURRENT_BINARY_DIR}/Inp_TwoGrainDirSolidification.json COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SpotMelt.json - ${CMAKE_CURRENT_BINARY_DIR}/Inp_SpotMelt.json COPYONLY) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallEquiaxedGrain.json + ${CMAKE_CURRENT_BINARY_DIR}/Inp_SpotMelt.json COPYONLY) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../examples/Inp_SmallEquiaxedGrain.json ${CMAKE_CURRENT_BINARY_DIR}/Inp_SmallEquiaxedGrain.json COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/Inconel625.json - ${CMAKE_CURRENT_BINARY_DIR}/Inconel625.json COPYONLY) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/Inconel625_Quadratic.json + ${CMAKE_CURRENT_BINARY_DIR}/Inconel625.json COPYONLY) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/Inconel625_Quadratic.json ${CMAKE_CURRENT_BINARY_DIR}/Inconel625_Quadratic.json COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../examples/Materials/SS316.json - ${CMAKE_CURRENT_BINARY_DIR}/SS316.json COPYONLY) + ${CMAKE_CURRENT_BINARY_DIR}/SS316.json COPYONLY) -ExaCA_add_tests(PACKAGE ExaCA-Core NAMES InterfacialResponse Inputs Orientation Parse Print) +exaca_add_tests( + PACKAGE + ExaCA-Core + NAMES + InterfacialResponse + Inputs + Orientation + Parse + Print) -ExaCA_add_tests(MPI PACKAGE ExaCA-Core NAMES CellData Grid Interface Nucleation Temperature Update) +exaca_add_tests( + MPI + PACKAGE + ExaCA-Core + NAMES + CellData + Grid + Interface + Nucleation + Temperature + Update) diff --git a/unit_test/test_harness.cmake b/unit_test/test_harness.cmake index a6d358d8..7f7d263b 100644 --- a/unit_test/test_harness.cmake +++ b/unit_test/test_harness.cmake @@ -1,11 +1,11 @@ -##--------------------------------------------------------------------------## -## Create main tests (all tests use Kokkos) -##--------------------------------------------------------------------------## +# --------------------------------------------------------------------------## +# Create main tests (all tests use Kokkos) +# --------------------------------------------------------------------------## macro(ExaCA_add_tests) cmake_parse_arguments(EXACA_UNIT_TEST "MPI" "PACKAGE" "NAMES" ${ARGN}) set(EXACA_UNIT_TEST_MPIEXEC_NUMPROCS 1) if(EXACA_UNIT_TEST_MPI) - foreach( _np 2 4 ) + foreach(_np 2 4) if(MPIEXEC_MAX_NUMPROCS GREATER_EQUAL ${_np}) list(APPEND EXACA_UNIT_TEST_MPIEXEC_NUMPROCS ${_np}) endif() @@ -15,7 +15,7 @@ macro(ExaCA_add_tests) endif() endif() set(EXACA_UNIT_TEST_NUMTHREADS 1) - foreach( _nt 2 4 ) + foreach(_nt 2 4) if(MPIEXEC_MAX_NUMPROCS GREATER_EQUAL ${_nt}) list(APPEND EXACA_UNIT_TEST_NUMTHREADS ${_nt}) endif() @@ -26,28 +26,35 @@ macro(ExaCA_add_tests) file(MAKE_DIRECTORY ${_dir}) foreach(_test ${EXACA_UNIT_TEST_NAMES}) set(_file ${_dir}/tst${_test}_${_device}.cpp) - file(WRITE ${_file} - "#include \n" - "#include \n" - ) + file(WRITE ${_file} "#include \n" + "#include \n") set(_target ExaCA_${_test}_test_${_device}) add_executable(${_target} ${_file} ${EXACA_UNIT_TEST_MAIN}) - target_include_directories(${_target} PRIVATE ${_dir} - ${TEST_HARNESS_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) - target_link_libraries(${_target} ${EXACA_UNIT_TEST_PACKAGE} ${gtest_target}) + target_include_directories(${_target} PRIVATE ${_dir} ${TEST_HARNESS_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}) + target_link_libraries(${_target} ${EXACA_UNIT_TEST_PACKAGE} + ${gtest_target}) foreach(_np ${EXACA_UNIT_TEST_MPIEXEC_NUMPROCS}) # FIXME: remove PTHREAD - if(_device STREQUAL PTHREAD OR _device STREQUAL THREADS OR _device STREQUAL OPENMP) + if(_device STREQUAL PTHREAD + OR _device STREQUAL THREADS + OR _device STREQUAL OPENMP) foreach(_thread ${EXACA_UNIT_TEST_NUMTHREADS}) - add_test(NAME ${_target}_np_${_np}_nt_${_thread} COMMAND - ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${_np} ${MPIEXEC_PREFLAGS} - $ ${MPIEXEC_POSTFLAGS} ${gtest_args} --kokkos-threads=${_thread}) + add_test( + NAME ${_target}_np_${_np}_nt_${_thread} + COMMAND + ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${_np} + ${MPIEXEC_PREFLAGS} $ + ${MPIEXEC_POSTFLAGS} ${gtest_args} --kokkos-threads=${_thread}) endforeach() else() - add_test(NAME ${_target}_np_${_np} COMMAND - ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${_np} ${MPIEXEC_PREFLAGS} - $ ${MPIEXEC_POSTFLAGS} ${gtest_args}) + add_test( + NAME ${_target}_np_${_np} + COMMAND + ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${_np} + ${MPIEXEC_PREFLAGS} $ + ${MPIEXEC_POSTFLAGS} ${gtest_args}) endif() endforeach() endforeach()