Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25) # Needed for CUDA, MPI, and CTest features

project(
EXP
VERSION "7.11.3"
VERSION "7.11.4"
HOMEPAGE_URL https://github.com/EXP-code/EXP
LANGUAGES C CXX Fortran)

Expand Down Expand Up @@ -61,6 +61,11 @@ option(ENABLE_XDR "Enable RPC/XDR support for Tipsy standard" FALSE)
option(ENABLE_VTK "Configure VTK if available" FALSE)
option(ENABLE_CUDA_SINGLE "Use real*4 instead of real*8 for CUDA" FALSE)
option(ENABLE_USER "Enable compilation of user modules" ON)
set(EXP_USER_MODULE_DIR "user" CACHE STRING "User module directory name under the install prefix's lib directory")
if(NOT EXP_USER_MODULE_DIR MATCHES "^[A-Za-z0-9_][A-Za-z0-9_.+-]*$")
message(FATAL_ERROR "EXP_USER_MODULE_DIR must be a directory name under lib")
endif()
set(EXP_USER_MODULE_DESTINATION "lib/${EXP_USER_MODULE_DIR}")
option(ENABLE_SLCHECK "Enable *careful* Sturm-Liouville solutions" TRUE)
option(ENABLE_TESTS "Enable build tests for EXP, pyEXP and helpers" ON)
option(ENABLE_MINIMAL "Compile EXP support libraries only" OFF)
Expand Down Expand Up @@ -274,6 +279,26 @@ include_directories(${PROJECT_SOURCE_DIR}/extern/QuickDigest5/include)
# Report to the user
message("Configuring build for ${GIT_BRANCH}/${GIT_COMMIT} at ${COMPILE_TIME}")

# Git provenance (GIT_BRANCH, GIT_COMMIT, COMPILE_TIME) for the code is
# generated at BUILD time into exp_git_version.h, so that it always
# describes the tree actually compiled, including uncommitted changes
# (<hash>-dirty-<diff fingerprint>), without having to re-run cmake.
# The header is rewritten only when the git state changes. The values
# above are for this configure message only.
set(EXP_GIT_VERSION_ARGS
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DSRC_DIR=${CMAKE_SOURCE_DIR}
-DTEMPLATE=${CMAKE_SOURCE_DIR}/exp_git_version.h_in
-DOUT=${CMAKE_BINARY_DIR}/exp_git_version.h)
execute_process(COMMAND ${CMAKE_COMMAND} ${EXP_GIT_VERSION_ARGS}
-P ${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake)
add_custom_target(exp_git_version ALL
COMMAND ${CMAKE_COMMAND} ${EXP_GIT_VERSION_ARGS}
-P ${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake
BYPRODUCTS ${CMAKE_BINARY_DIR}/exp_git_version.h
COMMENT "Checking git provenance"
VERBATIM)

add_subdirectory(extern/yaml-cpp)
if (NOT DISABLE_PYTHON)
add_subdirectory(extern/pybind11)
Expand All @@ -288,6 +313,17 @@ set(H5_USE_EIGEN TRUE CACHE BOOL "Eigen3 support in HighFive")

add_subdirectory(extern/HighFive EXCLUDE_FROM_ALL)

if(ENABLE_USER)
configure_file(cmake/UserModuleInstall.in.cmake UserModuleInstall.cmake @ONLY)
# Hold the lock across installation and pruning, including installs
# of the Unspecified component that contains the module targets.
install(CODE "
set(exp_module_install_begin TRUE)
include(\"${CMAKE_CURRENT_BINARY_DIR}/UserModuleInstall.cmake\")
unset(exp_module_install_begin)
")
endif()

# Configure the remaining native subdirectories
add_subdirectory(exputil)
add_subdirectory(expui)
Expand Down Expand Up @@ -419,3 +455,7 @@ set(CMAKE_CXX_FLAGS_UBSAN
# from the same source.
configure_file(${CMAKE_SOURCE_DIR}/config_cmake.h_in ${CMAKE_BINARY_DIR}/config_exp.h)
include_directories(${PROJECT_BINARY_DIR})

if(ENABLE_USER)
install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/UserModuleInstall.cmake")
endif()
74 changes: 74 additions & 0 deletions cmake/GitVersion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# GitVersion.cmake -- write git provenance into a generated source file.
#
# Run in script mode at BUILD time (from a custom target), so that the
# recorded state is always that of the tree actually being compiled,
# not that of the last `cmake` run:
#
# cmake -DGIT_EXECUTABLE=... -DSRC_DIR=<repo dir> -DTEMPLATE=<file.in>
# -DOUT=<generated file> -P GitVersion.cmake
#
# Variables available to the @VAR@ template:
# GIT_BRANCH current branch
# GIT_COMMIT full hash of HEAD; if tracked files have uncommitted
# changes: <hash>-dirty-<8 hex digits of MD5(git diff HEAD)>,
# so that every distinct uncommitted state is identifiable
# GIT_HASH same as GIT_COMMIT
# GIT_DIRTY 0 or 1
# GIT_DATE date of the HEAD commit
# GIT_COMMIT_MSG subject line of the HEAD commit (C-string escaped)
# COMPILE_TIME time of the first build of this exact source state
#
# OUT is rewritten only when the git state changes, so an unchanged tree
# triggers no recompilation. Untracked files and changes inside
# submodules are not counted as "dirty".

if(NOT GIT_EXECUTABLE)
set(GIT_EXECUTABLE git)
endif()

macro(_git var)
execute_process(COMMAND "${GIT_EXECUTABLE}" ${ARGN}
WORKING_DIRECTORY "${SRC_DIR}"
OUTPUT_VARIABLE ${var} RESULT_VARIABLE _rc
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _rc EQUAL 0)
set(${var} "unknown")
endif()
endmacro()

_git(GIT_BRANCH rev-parse --abbrev-ref HEAD)
_git(GIT_COMMIT rev-parse HEAD)
_git(GIT_DATE log -1 --format=%ad --date=local)
_git(GIT_COMMIT_MSG log -1 --format=%s)
_git(_status status --porcelain --untracked-files=no --ignore-submodules=dirty)

set(GIT_DIRTY 0)
if(_status AND NOT _status STREQUAL "unknown")
set(GIT_DIRTY 1)
_git(_diff diff HEAD --ignore-submodules=dirty)
string(MD5 _md5 "${_diff}")
string(SUBSTRING "${_md5}" 0 8 _md5)
set(GIT_COMMIT "${GIT_COMMIT}-dirty-${_md5}")
endif()
set(GIT_HASH "${GIT_COMMIT}")

# Escape for use inside a C string literal
foreach(v GIT_BRANCH GIT_DATE GIT_COMMIT_MSG)
string(REPLACE "\\" "\\\\" ${v} "${${v}}")
string(REPLACE "\"" "\\\"" ${v} "${${v}}")
endforeach()

# Regenerate only if the state changed (the key excludes the time)
set(_key "${GIT_BRANCH}|${GIT_COMMIT}|${GIT_DATE}|${GIT_COMMIT_MSG}|${TEMPLATE}")
set(_keyfile "${OUT}.gitkey")
set(_old "")
if(EXISTS "${_keyfile}" AND EXISTS "${OUT}")
file(READ "${_keyfile}" _old)
endif()

if(NOT _old STREQUAL _key)
string(TIMESTAMP COMPILE_TIME "%Y-%m-%d %H:%M:%S %Z")
configure_file("${TEMPLATE}" "${OUT}" @ONLY)
file(WRITE "${_keyfile}" "${_key}")
message(STATUS "Git provenance for ${SRC_DIR}: ${GIT_BRANCH}/${GIT_COMMIT}")
endif()
64 changes: 64 additions & 0 deletions cmake/UserModuleInstall.in.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# CMake's install manifest paths omit DESTDIR, while filesystem operations
# must use the staged path when DESTDIR is set.
if(CMAKE_INSTALL_LOCAL_ONLY)
return()
endif()
set(exp_module_destination "${CMAKE_INSTALL_PREFIX}/@EXP_USER_MODULE_DESTINATION@")
set(exp_module_directory "$ENV{DESTDIR}${exp_module_destination}")
set(exp_module_manifest "${exp_module_directory}/.exp-user-modules")

if(exp_module_install_begin)
file(MAKE_DIRECTORY "${exp_module_directory}")
file(LOCK "${exp_module_manifest}.lock" GUARD PROCESS TIMEOUT 60)
return()
endif()

# A component install cannot determine which modules have been retired.
if(NOT "${CMAKE_INSTALL_COMPONENT}" STREQUAL "")
return()
endif()

set(exp_module_filename_pattern "^lib[A-Za-z0-9_.+-]+\\.(so(\\.[0-9]+)*|dylib|a)$")
set(exp_module_files)
foreach(exp_installed_file IN LISTS CMAKE_INSTALL_MANIFEST_FILES)
get_filename_component(exp_installed_dir "${exp_installed_file}" DIRECTORY)
if(exp_installed_dir STREQUAL exp_module_destination)
get_filename_component(exp_installed_name "${exp_installed_file}" NAME)
if(exp_installed_name MATCHES "${exp_module_filename_pattern}")
list(APPEND exp_module_files "${exp_installed_name}")
endif()
endif()
endforeach()
list(REMOVE_DUPLICATES exp_module_files)
list(SORT exp_module_files)

if(IS_SYMLINK "${exp_module_manifest}" OR IS_DIRECTORY "${exp_module_manifest}")
message(FATAL_ERROR "Invalid EXP user module manifest: ${exp_module_manifest}")
endif()
if(EXISTS "${exp_module_manifest}")
file(STRINGS "${exp_module_manifest}" exp_previous_modules)
foreach(exp_previous_module IN LISTS exp_previous_modules)
# Accept library basenames only. Never remove a path outside this directory.
if(NOT exp_previous_module MATCHES "${exp_module_filename_pattern}")
message(FATAL_ERROR "Invalid entry in ${exp_module_manifest}: ${exp_previous_module}")
endif()
endforeach()
foreach(exp_previous_module IN LISTS exp_previous_modules)
if(NOT exp_previous_module IN_LIST exp_module_files)
set(exp_obsolete_module "${exp_module_directory}/${exp_previous_module}")
if(IS_DIRECTORY "${exp_obsolete_module}")
message(WARNING "Keeping directory at obsolete EXP module path: ${exp_obsolete_module}")
elseif(EXISTS "${exp_obsolete_module}" OR IS_SYMLINK "${exp_obsolete_module}")
message(STATUS "Removing obsolete EXP user module: ${exp_obsolete_module}")
file(REMOVE "${exp_obsolete_module}")
if(EXISTS "${exp_obsolete_module}" OR IS_SYMLINK "${exp_obsolete_module}")
message(FATAL_ERROR "Could not remove obsolete EXP user module: ${exp_obsolete_module}")
endif()
endif()
endif()
endforeach()
endif()

list(JOIN exp_module_files "\n" exp_module_contents)
file(CONFIGURE OUTPUT "${exp_module_manifest}.tmp" CONTENT "${exp_module_contents}\n" @ONLY)
file(RENAME "${exp_module_manifest}.tmp" "${exp_module_manifest}")
10 changes: 2 additions & 8 deletions config_cmake.h_in
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,5 @@
/* Version number of package */
#define VERSION "@PROJECT_VERSION@"

/* Git commit at configure */
#define GIT_COMMIT "@GIT_COMMIT@"

/* Git branch at configure */
#define GIT_BRANCH "@GIT_BRANCH@"

/* Date/time at configure */
#define COMPILE_TIME "@COMPILE_TIME@"
/* GIT_COMMIT, GIT_BRANCH and COMPILE_TIME are generated at build time
in exp_git_version.h (see cmake/GitVersion.cmake) */
2 changes: 1 addition & 1 deletion doc/exp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = EXP
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 7.11.3
PROJECT_NUMBER = 7.11.4

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion doc/exp.cfg.breathe
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = EXP
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 7.11.3
PROJECT_NUMBER = 7.11.4

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
14 changes: 14 additions & 0 deletions exp_git_version.h_in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Generated at build time by cmake/GitVersion.cmake -- do not edit.
//
// Kept separate from config_exp.h so that a change of the git state
// recompiles only the few files that report it.
#pragma once

//! Current git branch
#define GIT_BRANCH "@GIT_BRANCH@"

//! Git commit hash; <hash>-dirty-<diff fingerprint> for uncommitted changes
#define GIT_COMMIT "@GIT_COMMIT@"

//! Time of the first build of this source state
#define COMPILE_TIME "@COMPILE_TIME@"
1 change: 1 addition & 0 deletions pyEXP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pybind11_add_module(pyEXP PyWrappers.cc CoefWrappers.cc
UtilWrappers.cc BasisWrappers.cc FieldWrappers.cc
ParticleReaderWrappers.cc MSSAWrappers.cc EDMDWrappers.cc)
target_link_libraries(pyEXP PUBLIC expui exputil ${common_LINKLIB})
add_dependencies(pyEXP exp_git_version) # exp_git_version.h
target_include_directories(pyEXP PUBLIC ${common_INCLUDE})
# TODO: Should find a proper solution for this, but for now, don't add OpenMP compile
# options if compiling on macOS with Clang
Expand Down
1 change: 1 addition & 0 deletions pyEXP/PyWrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <pybind11/stl.h>

#include "config_exp.h"
#include "exp_git_version.h" // GIT_BRANCH, GIT_COMMIT, COMPILE_TIME

namespace py = pybind11;

Expand Down
1 change: 1 addition & 0 deletions pyEXP/UtilWrappers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace py = pybind11;
#include "Centering.H"
#include "KDdensity.H"
#include "ParticleIterator.H"
#include "exp_git_version.h" // GIT_BRANCH, GIT_COMMIT, COMPILE_TIME

void UtilityClasses(py::module &m) {

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if(ENABLE_XDR AND TIRPC_FOUND)
endif()

add_library(EXPlib ${exp_SOURCES})
add_dependencies(EXPlib exp_git_version) # exp_git_version.h (parse.cc, OutHDF5.cc)
set_target_properties(EXPlib PROPERTIES OUTPUT_NAME EXPlib)
target_include_directories(EXPlib PUBLIC ${common_INCLUDE_DIRS})
target_link_libraries(EXPlib PUBLIC ${common_LINKLIB})
Expand Down
4 changes: 4 additions & 0 deletions src/ExternalCollection.H
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public:

//! Call the finish member for all external forces
void finish();

//! Call the step-end hook of the external forces that request it at
//! this time (see ExternalForce::wantStepEnd)
void stepEnd();
};

#endif
22 changes: 22 additions & 0 deletions src/ExternalCollection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string>

#include "ExternalCollection.H"
#include "OutputContainer.H"

#include "tidalField.H"
#include "externalShock.H"
Expand Down Expand Up @@ -280,3 +281,24 @@ void ExternalCollection::finish()
for (auto p : force_list) p->finish();
}

void ExternalCollection::stepEnd()
{
// Which forces want the hook at this time?
std::vector<ExternalForce*> want;
for (auto ext : force_list)
if (ext->wantStepEnd(tnow)) want.push_back(ext);

if (want.empty()) return;

#if HAVE_LIBCUDA==1
// The hook reads the host copy of the particles: fetch it from the
// device once, only at the times when some force wants the hook.
// (Done here, in EXP proper, so that user modules need no CUDA code.)
if (use_cuda) {
output->synchronize();
for (auto c : comp->components) c->CudaToParticles();
Comment thread
The9Cat marked this conversation as resolved.
Resolved
}
#endif

for (auto ext : want) ext->stepEnd();
}
26 changes: 26 additions & 0 deletions src/ExternalForce.H
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ public:
//! Finish and clean-up (caching data necessary for restart)
virtual void finish() {}

//@{
/** Optional step-end hook.

The force evaluation (determine_acceleration_and_potential) runs
between the drift and the closing velocity kick, where the
positions are at the new time but the velocities are still half a
step behind. A force that needs a synchronized phase space (for
example, to measure actions or energies) can instead use this
hook: EXP calls stepEnd() at every synchronized point, that is,
once after initialization and once at the end of every full step
(after the closing kick, before the output routines run), but
only if wantStepEnd(tnow) returns true. The default is never, so
existing forces are not affected.

wantStepEnd() must return the same value on all MPI ranks (e.g.
decide from tnow only). stepEnd() is called on all ranks and must
not change the particles. On a GPU run, EXP copies the particles
from the device to the host before calling stepEnd(), but only at
the times when some force asks for the hook, so a force using it
needs no CUDA code of its own (and can declare itself cuda aware
to avoid the per-step copies of the force evaluation).
*/
virtual bool wantStepEnd(double time) { return false; }
virtual void stepEnd() {}
//@}

// #if HAVE_LIBCUDA==1
#if HAVE_LIBCUDA==1
//! Copy particles from device for non-cuda forces
Expand Down
8 changes: 6 additions & 2 deletions src/OrbTrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ void OrbTrace::initialize()

void OrbTrace::Run(int n, int mstep, bool last)
{
if (n % nint && !last && !tcomp && norb) return;
if (mstep % nintsub !=0 && !tcomp && norb) return;
if (!tcomp || norb == 0) return; // Nothing to trace

if (!last) {
if (n % nint) return; // Output cadence in major steps
if (multistep>1 && mstep % nintsub !=0) return;
}
if (tnow <= prev) return;

prev = tnow; // Record current time
Expand Down
1 change: 1 addition & 0 deletions src/OutHDF5.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "global.H"

#include "OutHDF5.H"
#include "exp_git_version.h" // GIT_BRANCH, GIT_COMMIT, COMPILE_TIME

const std::set<std::string>
OutHDF5::valid_keys = {
Expand Down
Loading
Loading