From 92133db4e23bff0f4378f9e851d0266927625490 Mon Sep 17 00:00:00 2001 From: "Seth R. Johnson" Date: Tue, 12 Sep 2023 21:41:48 -0400 Subject: [PATCH] Add Windows support (#930) * Fix corecel errors/warnings on windows Remove isatty for windows: ``` E:\scale\external\celeritas\src\corecel\io\ColorUtils.cc(13): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory ``` String view iterator is not a const char*: ``` E:\scale\external\celeritas\src\corecel\io\StringUtils.cc(66): note: 'std::basic_string_view>:: basic_string_view(const char *const ,const std::basic_string_view>::size_type) noexcept': canno t convert argument 1 from 'std::_String_view_iterator<_Traits>' to 'const char *const ' with [ _Traits=std::char_traits ] ``` 'environ' is a macro on windows (boo) ``` E:\scale\external\celeritas\src\corecel\sys\Environment.cc(31): error C2267: '__p__environ': static functions with block scope are illegal ``` psapi must be included *after* windows.h ``` C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um\psapi.h(132): error C2146: syntax error: missing ';' before identifier 'WINAPI' ``` ptrdiff_t is implicitly converted to long ``` E:\scale\external\celeritas\src\corecel\sys\ScopedMem.cc(125): warning C4244: 'argument': conversion from 'ptrdiff_t' to 'long', possible loss of dat a ``` * Fix truncation warning * Fix missing include * Instantiate aligned plane explicitly * Use 'if constexpr' to avoid choking msvc This might have relied on compiler optimization stopping the template instantiation early. With 'if constexpr' this should always be correct. * Define windows macros * Fix compiler failure from divide by zero ``` E:\scale\external\celeritas\test\corecel\math\NumericLimits.test.cc(40): error C2124: divide or mod by zero ``` * Fix integer overflow in windows integer literal ``` E:\scale\external\celeritas\src\celeritas/field/DormandPrinceStepper.hh(144): warning C4146: unary minus operator applied to unsigned type, result st ill unsigned ``` * Fix conversion warnings * Disable dominance warning ``` E:\scale\external\celeritas\src\celeritas\geo\detail\BoundaryAction.hh(37): warning C4250: 'celeritas::detail::BoundaryAction': inherits 'celeritas::C oncreteAction::celeritas::ConcreteAction::action_id' via dominance E:\scale\external\celeritas\src\celeritas/global/ActionInterface.hh(151): note: see declaration of 'celeritas::ConcreteAction::action_id' E:\scale\external\celeritas\src\celeritas\geo\detail\BoundaryAction.hh(37): warning C4250: 'celeritas::detail::BoundaryAction': inherits 'celeritas::C oncreteAction::celeritas::ConcreteAction::label' via dominance E:\scale\external\celeritas\src\celeritas/global/ActionInterface.hh(154): note: see declaration of 'celeritas::ConcreteAction::label' E:\scale\external\celeritas\src\celeritas\geo\detail\BoundaryAction.hh(37): warning C4250: 'celeritas::detail::BoundaryAction': inherits 'celeritas::C oncreteAction::celeritas::ConcreteAction::description' via dominance ``` * Fix implicit cast in step conversion * Fix MSVC implicit capture weirdness There are weird scoping rules about static const for lambdas. ``` E:\scale\external\celeritas\test\celeritas\track\TrackInit.test.cc(417): error C3493: 'num_tracks' cannot be implicitly captured because no default ca pture mode has been specified ``` * Fix use of SIGUSR2 ``` E:\scale\external\celeritas\app\celer-sim\Transporter.cc(70): error C2065: 'SIGUSR2': undeclared identifier ``` * Fix narrowing conversion ``` E:\scale\external\celeritas\test\celeritas\em\UrbanMsc.test.cc(281): error C2397: conversion from 'const int' to 'T' requires a narrowing conversion with [T=celeritas::real_type ] ``` More conversion warnings * Fix missing symbol * Work around windows environ definition * Explicitly specify enum type ``` E:\scale\external\celeritas\test\corecel\cont\Range.test.cc(215): error: Value of: (std::is_same::type, unsigne d int>::value) Actual: false Expected: true ``` * Fix windows issues with paths * Improve dependency logic for building inside another project * Clang-format * Work around dumb GCC attribute warning * Document * Add default type to quantity based on underlying unit * Mark quantity functions as noexcept * Use size_t instead of ptrdiff_t and long int for scoped mem --- CMakeLists.txt | 29 +++-- app/celer-sim/RunnerInput.hh | 7 ++ app/celer-sim/Transporter.cc | 4 + scripts/cmake-presets/wildstyle.json | 2 +- src/celeritas/CMakeLists.txt | 7 ++ .../em/interactor/RayleighInteractor.hh | 4 +- src/celeritas/em/model/RayleighModel.cc | 2 +- .../em/model/RelativisticBremModel.cc | 2 +- src/celeritas/em/model/WentzelModel.cc | 2 +- src/celeritas/ext/GeantSetup.hh | 2 + src/celeritas/field/DormandPrinceStepper.hh | 12 +-- src/celeritas/field/RZMapFieldData.hh | 2 +- src/celeritas/grid/VectorUtils.cc | 2 +- src/celeritas/phys/PhysicsData.hh | 4 +- src/celeritas/random/XorwowRngData.cc | 4 +- src/celeritas/track/detail/TrackSortUtils.cc | 2 +- src/celeritas/track/detail/TrackSortUtils.hh | 4 +- src/celeritas/user/SimpleCalo.cc | 2 +- src/corecel/CMakeLists.txt | 16 ++- src/corecel/cont/Range.hh | 2 +- src/corecel/data/Collection.hh | 2 +- src/corecel/io/ColorUtils.cc | 8 +- src/corecel/io/StringUtils.cc | 2 +- src/corecel/math/Algorithms.hh | 16 ++- src/corecel/math/Quantity.hh | 100 ++++++++++-------- src/corecel/math/detail/MathImpl.hh | 2 +- src/corecel/sys/Environment.cc | 4 +- src/corecel/sys/KernelRegistry.hh | 11 +- src/corecel/sys/MemRegistry.hh | 17 +-- src/corecel/sys/ScopedMem.cc | 23 +++- src/corecel/sys/ScopedMem.hh | 7 +- src/corecel/sys/Stream.cc | 14 ++- src/corecel/sys/Version.cc | 2 +- src/orange/CMakeLists.txt | 1 + src/orange/construct/detail/NodeSimplifier.cc | 5 + src/orange/detail/UnitInserter.cc | 4 +- src/orange/surf/PlaneAligned.cc | 19 ++++ .../surf/detail/QuadricPlaneConverter.hh | 3 + test/CMakeLists.txt | 2 +- test/Test.cc | 11 +- test/celeritas/em/BetheHeitler.test.cc | 2 +- test/celeritas/em/UrbanMsc.test.cc | 9 +- test/celeritas/ext/GeantImporter.test.cc | 26 ++--- test/celeritas/grid/CalculatorTestBase.cc | 2 +- test/celeritas/random/SequenceEngine.hh | 4 +- test/celeritas/track/TrackInit.test.cc | 14 +-- test/corecel/cont/Range.test.cc | 6 +- test/corecel/io/Join.test.cc | 2 +- test/corecel/math/NumericLimits.test.cc | 2 + test/corecel/math/Quantity.test.cc | 13 ++- test/corecel/sys/ScopedSignalHandler.test.cc | 2 + test/testdetail/TestMacrosImpl.hh | 4 +- 52 files changed, 289 insertions(+), 161 deletions(-) create mode 100644 src/orange/surf/PlaneAligned.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index ba584a17a0..20f37e7825 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,6 +180,10 @@ if(BUILD_SHARED_LIBS) # Do not relink libs/binaries when dependent shared libs change celeritas_set_default(CMAKE_LINK_DEPENDS_NO_SHARED ON) endif() +if(BUILD_SHARED_LIBS OR CELERITAS_USE_ROOT) + # Make sure modules, sub-libraries, etc. are relocatable + celeritas_set_default(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() ### Installation flags ### # When developing add checking for proper usage of `install(` @@ -219,13 +223,17 @@ if(CELERITAS_USE_Geant4 AND NOT Geant4_FOUND) find_package(Geant4 REQUIRED) endif() -if(CELERITAS_USE_HepMC3 AND NOT HepMC3_FOUND) - find_package(HepMC3 REQUIRED) +if(CELERITAS_USE_HepMC3) + if(NOT HepMC3_FOUND) + find_package(HepMC3 REQUIRED) + endif() set(HepMC3_LIBRARIES HepMC3::HepMC3) endif() -if(CELERITAS_USE_JSON AND NOT nlohmann_json_FOUND) - find_package(nlohmann_json 3.7.0 REQUIRED) +if(CELERITAS_USE_JSON) + if(NOT nlohmann_json_FOUND) + find_package(nlohmann_json 3.7.0 REQUIRED) + endif() set(nlohmann_json_LIBRARIES nlohmann_json::nlohmann_json) endif() @@ -242,7 +250,9 @@ if(CELERITAS_USE_Python) if(CELERITAS_USE_SWIG) list(APPEND _components Development) endif() - find_package(Python 3.6 REQUIRED COMPONENTS ${_components}) + if(NOT Python_FOUND) + find_package(Python 3.6 REQUIRED COMPONENTS ${_components}) + endif() set(CELERITAS_PYTHONPATH "$ENV{PYTHONPATH}" CACHE STRING "Python path used for finding modules and generating documentation" ) @@ -259,7 +269,9 @@ if(CELERITAS_USE_SWIG AND NOT SWIG_FOUND) endif() if(CELERITAS_USE_VecGeom) - find_package(VecGeom 1.1.17 REQUIRED) + if(NOT VecGeom_FOUND) + find_package(VecGeom 1.1.17 REQUIRED) + endif() if(CELERITAS_USE_CUDA AND NOT VecGeom_CUDA_FOUND) celeritas_error_incompatible_option( @@ -319,11 +331,6 @@ if(CELERITAS_BUILD_DOCS) endif() endif() -if(BUILD_SHARED_LIBS OR CELERITAS_USE_ROOT) - # Make sure modules, sub-libraries, etc. are relocatable - set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) -endif() - #----------------------------------------------------------------------------# # LIBRARY #----------------------------------------------------------------------------# diff --git a/app/celer-sim/RunnerInput.hh b/app/celer-sim/RunnerInput.hh index 310841b14d..dda9d433c2 100644 --- a/app/celer-sim/RunnerInput.hh +++ b/app/celer-sim/RunnerInput.hh @@ -18,6 +18,13 @@ #include "celeritas/phys/PrimaryGeneratorOptions.hh" #include "celeritas/user/RootStepWriter.hh" +#ifdef _WIN32 +# include +# ifdef environ +# undef environ +# endif +#endif + namespace celeritas { namespace app diff --git a/app/celer-sim/Transporter.cc b/app/celer-sim/Transporter.cc index 5d2b4a7411..5752b38f46 100644 --- a/app/celer-sim/Transporter.cc +++ b/app/celer-sim/Transporter.cc @@ -67,7 +67,11 @@ auto Transporter::operator()(SpanConstPrimary primaries) }; // Abort cleanly for interrupt and user-defined signals +#ifndef _WIN32 ScopedSignalHandler interrupted{SIGINT, SIGUSR2}; +#else + ScopedSignalHandler interrupted{SIGINT}; +#endif CELER_LOG(status) << "Transporting"; Stopwatch get_step_time; diff --git a/scripts/cmake-presets/wildstyle.json b/scripts/cmake-presets/wildstyle.json index 0218ca1d4a..6a714c3940 100644 --- a/scripts/cmake-presets/wildstyle.json +++ b/scripts/cmake-presets/wildstyle.json @@ -18,7 +18,7 @@ "CELERITAS_USE_SWIG": {"type": "BOOL", "value": "OFF"}, "CELERITAS_USE_VecGeom": {"type": "BOOL", "value": "OFF"}, "CMAKE_CXX_COMPILER": "/usr/bin/g++", - "CMAKE_CXX_FLAGS": "-Wall -Wextra -pedantic -Werror -Wno-error=deprecated-declarations -Wno-attributes -fdiagnostics-color=always", + "CMAKE_CXX_FLAGS": "-Wall -Wextra -pedantic -Werror -Wno-error=deprecated-declarations -fdiagnostics-color=always", "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O2 -g -DNDEBUG -fno-inline -fno-omit-frame-pointer", "CMAKE_CXX_FLAGS_RELEASE": "-O3 -DNDEBUG -march=skylake-avx512 -mtune=skylake-avx512", "CMAKE_CUDA_FLAGS": "-Werror all-warnings -Wno-deprecated-gpu-targets", diff --git a/src/celeritas/CMakeLists.txt b/src/celeritas/CMakeLists.txt index e22757db9b..abf84d898d 100644 --- a/src/celeritas/CMakeLists.txt +++ b/src/celeritas/CMakeLists.txt @@ -311,6 +311,13 @@ if(NOT CELERITAS_USE_OpenMP PRIVATE $<$:-Wno-unknown-pragmas> ) endif() +if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # Inheriting via dominance is correct behavior + celeritas_target_compile_options(celeritas + PUBLIC "$<$:/wd4267$/wd4250>" + ) +endif() + celeritas_target_link_libraries(celeritas PRIVATE ${PRIVATE_DEPS} diff --git a/src/celeritas/em/interactor/RayleighInteractor.hh b/src/celeritas/em/interactor/RayleighInteractor.hh index 5f04a60dd0..f08f658a77 100644 --- a/src/celeritas/em/interactor/RayleighInteractor.hh +++ b/src/celeritas/em/interactor/RayleighInteractor.hh @@ -128,8 +128,8 @@ CELER_FUNCTION Interaction RayleighInteractor::operator()(Engine& rng) do { // Sample index from input.prob - unsigned int const index = celeritas::make_selector( - [&input](unsigned int i) { return input.prob[i]; }, + auto const index = celeritas::make_selector( + [&input](size_type i) { return input.prob[i]; }, input.prob.size())(rng); const real_type w = input.weight[index]; diff --git a/src/celeritas/em/model/RayleighModel.cc b/src/celeritas/em/model/RayleighModel.cc index 8fbb49a106..052b61606a 100644 --- a/src/celeritas/em/model/RayleighModel.cc +++ b/src/celeritas/em/model/RayleighModel.cc @@ -119,7 +119,7 @@ ActionId RayleighModel::action_id() const void RayleighModel::build_data(HostValue* data, MaterialParams const& materials) { // Number of elements - unsigned int num_elements = materials.num_elements(); + auto num_elements = materials.num_elements(); // Build data for available elements auto params = make_builder(&data->params); diff --git a/src/celeritas/em/model/RelativisticBremModel.cc b/src/celeritas/em/model/RelativisticBremModel.cc index 08be979b63..f50c2a90c7 100644 --- a/src/celeritas/em/model/RelativisticBremModel.cc +++ b/src/celeritas/em/model/RelativisticBremModel.cc @@ -143,7 +143,7 @@ void RelativisticBremModel::build_data(HostValue* data, real_type particle_mass) { // Build element data for available elements - unsigned int num_elements = materials.num_elements(); + auto num_elements = materials.num_elements(); auto elem_data = make_builder(&data->elem_data); elem_data.reserve(num_elements); diff --git a/src/celeritas/em/model/WentzelModel.cc b/src/celeritas/em/model/WentzelModel.cc index a0438acd09..60d4e3a567 100644 --- a/src/celeritas/em/model/WentzelModel.cc +++ b/src/celeritas/em/model/WentzelModel.cc @@ -138,7 +138,7 @@ void WentzelModel::build_data(HostVal& host_data, MaterialParams const& materials) { // Build element data - unsigned int const num_elements = materials.num_elements(); + size_type const num_elements = materials.num_elements(); auto elem_data = make_builder(&host_data.elem_data); elem_data.reserve(num_elements); diff --git a/src/celeritas/ext/GeantSetup.hh b/src/celeritas/ext/GeantSetup.hh index abfa692406..a9dcbb611a 100644 --- a/src/celeritas/ext/GeantSetup.hh +++ b/src/celeritas/ext/GeantSetup.hh @@ -97,6 +97,8 @@ G4VPhysicalVolume const* GeantSetup::world() const } #if !CELERITAS_USE_GEANT4 +inline void GeantSetup::disable_signal_handler() {} + inline GeantSetup::GeantSetup(std::string const&, Options) { CELER_NOT_CONFIGURED("Geant4"); diff --git a/src/celeritas/field/DormandPrinceStepper.hh b/src/celeritas/field/DormandPrinceStepper.hh index 4638d0b2c6..ca7565d928 100644 --- a/src/celeritas/field/DormandPrinceStepper.hh +++ b/src/celeritas/field/DormandPrinceStepper.hh @@ -139,12 +139,12 @@ DormandPrinceStepper::operator()(real_type step, constexpr R d77 = -1 / R(40); // Coefficients for the mid point calculation by Shampine - constexpr R c71 = 6025192743 / R(30085553152); - constexpr R c73 = 51252292925 / R(65400821598); - constexpr R c74 = -2691868925 / R(45128329728); - constexpr R c75 = 187940372067 / R(1594534317056); - constexpr R c76 = -1776094331 / R(19743644256); - constexpr R c77 = 11237099 / R(235043384); + constexpr R c71 = R(6025192743.) / R(30085553152.); + constexpr R c73 = R(51252292925.) / R(65400821598.); + constexpr R c74 = R(-2691868925.) / R(45128329728.); + constexpr R c75 = R(187940372067.) / R(1594534317056.); + constexpr R c76 = R(-1776094331.) / R(19743644256.); + constexpr R c77 = R(11237099.) / R(235043384.); result_type result; diff --git a/src/celeritas/field/RZMapFieldData.hh b/src/celeritas/field/RZMapFieldData.hh index cef8e3b149..6444412592 100644 --- a/src/celeritas/field/RZMapFieldData.hh +++ b/src/celeritas/field/RZMapFieldData.hh @@ -70,7 +70,7 @@ struct RZMapFieldParamsData && r >= grids.data_r.front && r <= grids.data_r.back); } - inline CELER_FUNCTION ElementId id(int idx_z, int idx_r) const + inline CELER_FUNCTION ElementId id(size_type idx_z, size_type idx_r) const { CELER_EXPECT(grids.data_r); return ElementId(idx_z * grids.data_r.size + idx_r); diff --git a/src/celeritas/grid/VectorUtils.cc b/src/celeritas/grid/VectorUtils.cc index 9220e151c6..a7eff07a11 100644 --- a/src/celeritas/grid/VectorUtils.cc +++ b/src/celeritas/grid/VectorUtils.cc @@ -28,7 +28,7 @@ std::vector space_impl(double start, double stop, size_type n) result.front() = start; for (auto i : range(1, n - 1)) { - result[i] = interp(i); + result[i] = interp(static_cast(i)); } // Manually set last point to avoid any differences due to roundoff result.back() = stop; diff --git a/src/celeritas/phys/PhysicsData.hh b/src/celeritas/phys/PhysicsData.hh index 56c410b4de..3331768e22 100644 --- a/src/celeritas/phys/PhysicsData.hh +++ b/src/celeritas/phys/PhysicsData.hh @@ -473,7 +473,9 @@ inline void resize(PhysicsStateData* state, resize(&state->per_process_xs, size * params.scalars.max_particle_processes); resize(&state->relaxation, params.hardwired.relaxation_data, size); - resize(&state->secondaries, size * params.scalars.secondary_stack_factor); + resize( + &state->secondaries, + static_cast(size * params.scalars.secondary_stack_factor)); } //---------------------------------------------------------------------------// diff --git a/src/celeritas/random/XorwowRngData.cc b/src/celeritas/random/XorwowRngData.cc index 97d53f3611..348a89a4a6 100644 --- a/src/celeritas/random/XorwowRngData.cc +++ b/src/celeritas/random/XorwowRngData.cc @@ -33,8 +33,8 @@ void resize(XorwowRngStateData* state, // Seed sequence to generate well-distributed seed numbers, including // stream ID to give strings different starting contributions - std::vector host_seeds(params.seed.begin(), - params.seed.end()); + std::vector host_seeds(params.seed.begin(), + params.seed.end()); if (stream != StreamId{0}) { // For backward compatibility with prior RNG seed, don't modify the diff --git a/src/celeritas/track/detail/TrackSortUtils.cc b/src/celeritas/track/detail/TrackSortUtils.cc index 439a582361..536b4ed75d 100644 --- a/src/celeritas/track/detail/TrackSortUtils.cc +++ b/src/celeritas/track/detail/TrackSortUtils.cc @@ -96,7 +96,7 @@ template<> void shuffle_track_slots( Span track_slots, StreamId) { - unsigned int seed = track_slots.size(); + auto seed = static_cast(track_slots.size()); std::mt19937 g{seed}; std::shuffle(track_slots.begin(), track_slots.end(), g); } diff --git a/src/celeritas/track/detail/TrackSortUtils.hh b/src/celeritas/track/detail/TrackSortUtils.hh index 2ffe7f7bfe..aaa9de3c09 100644 --- a/src/celeritas/track/detail/TrackSortUtils.hh +++ b/src/celeritas/track/detail/TrackSortUtils.hh @@ -83,7 +83,7 @@ struct alive_predicate { ObserverPtr status_; - CELER_FUNCTION bool operator()(unsigned int track_slot) const + CELER_FUNCTION bool operator()(size_type track_slot) const { return status_.get()[track_slot] == TrackStatus::alive; } @@ -93,7 +93,7 @@ struct action_comparator { ObserverPtr action_; - CELER_FUNCTION bool operator()(unsigned int a, unsigned int b) const + CELER_FUNCTION bool operator()(size_type a, size_type b) const { return action_.get()[a] < action_.get()[b]; } diff --git a/src/celeritas/user/SimpleCalo.cc b/src/celeritas/user/SimpleCalo.cc index e73b6462ca..40b8a5e1fe 100644 --- a/src/celeritas/user/SimpleCalo.cc +++ b/src/celeritas/user/SimpleCalo.cc @@ -175,7 +175,7 @@ void SimpleCalo::output(JsonPimpl* j) const std::vector ids; for (VolumeId vid : volume_ids_) { - ids.push_back(vid.get()); + ids.push_back(static_cast(vid.get())); } obj["volume_ids"] = std::move(ids); obj["volume_labels"] = volume_labels_; diff --git a/src/corecel/CMakeLists.txt b/src/corecel/CMakeLists.txt index f3d2861195..3b89e13aba 100644 --- a/src/corecel/CMakeLists.txt +++ b/src/corecel/CMakeLists.txt @@ -88,11 +88,25 @@ endif() celeritas_add_library(corecel ${SOURCES}) -# Require at least C++14 +# Require at least C++17 target_compile_features(corecel PUBLIC cxx_std_17) if(CELERITAS_USE_CUDA) target_compile_features(corecel PUBLIC cuda_std_17) endif() +if(WIN32) + target_compile_definitions(corecel PUBLIC + $<$:NOMINMAX NOGDI> + ) + + # By default MSVC has __cplusplus at 199711L, this flag + # forces it to follow the standard + if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + target_compile_options(corecel PUBLIC + $<$:/Zc:__cplusplus /Zc:preprocessor> + ) + endif() +endif() + celeritas_target_include_directories(corecel PUBLIC diff --git a/src/corecel/cont/Range.hh b/src/corecel/cont/Range.hh index bb06a2cd9c..5148c4d6f4 100644 --- a/src/corecel/cont/Range.hh +++ b/src/corecel/cont/Range.hh @@ -137,7 +137,7 @@ class Range template::value, bool> = true> CELER_CONSTEXPR_FUNCTION detail::StepRange> step(U step) { - return {*begin_, *end_, step}; + return {*begin_, *end_, static_cast(step)}; } //! \endcond diff --git a/src/corecel/data/Collection.hh b/src/corecel/data/Collection.hh index 28412c0808..22704573f0 100644 --- a/src/corecel/data/Collection.hh +++ b/src/corecel/data/Collection.hh @@ -294,7 +294,7 @@ class Collection //! Direct accesors to underlying data CELER_FORCEINLINE_FUNCTION size_type size() const { - return this->storage().size(); + return static_cast(this->storage().size()); } CELER_FORCEINLINE_FUNCTION bool empty() const { diff --git a/src/corecel/io/ColorUtils.cc b/src/corecel/io/ColorUtils.cc index 8a85af9a78..6cf49c492f 100644 --- a/src/corecel/io/ColorUtils.cc +++ b/src/corecel/io/ColorUtils.cc @@ -10,7 +10,9 @@ #include #include #include -#include +#ifndef _WIN32 +# include +#endif #include "corecel/sys/Environment.hh" @@ -23,7 +25,7 @@ namespace celeritas bool use_color() { const static bool result = [] { - FILE* stream = stderr; + [[maybe_unused]] FILE* stream = stderr; std::string color_str = celeritas::getenv("CELER_COLOR"); if (color_str.empty()) { @@ -44,11 +46,13 @@ bool use_color() // Color is explicitly enabled return true; } +#ifndef _WIN32 if (!isatty(fileno(stream))) { // This stream is not a user-facing terminal return false; } +#endif if (const char* term_str = std::getenv("TERM")) { if (std::string{term_str}.find("xterm") != std::string::npos) diff --git a/src/corecel/io/StringUtils.cc b/src/corecel/io/StringUtils.cc index c83cce0e32..38dcb0e616 100644 --- a/src/corecel/io/StringUtils.cc +++ b/src/corecel/io/StringUtils.cc @@ -63,7 +63,7 @@ std::string_view trim(std::string_view input) { --stop; } - return {start, static_cast(stop - start)}; + return {&(*start), static_cast(stop - start)}; } //---------------------------------------------------------------------------// diff --git a/src/corecel/math/Algorithms.hh b/src/corecel/math/Algorithms.hh index 2ed0358b1f..30e7360717 100644 --- a/src/corecel/math/Algorithms.hh +++ b/src/corecel/math/Algorithms.hh @@ -406,14 +406,24 @@ CELER_FORCEINLINE_FUNCTION ForwardIt min_element(ForwardIt first, * Example: \code assert(9.0 == ipow<2>(3.0)); assert(256 == ipow<8>(2)); + static_assert(256 == ipow<8>(2)); \endcode */ template CELER_CONSTEXPR_FUNCTION T ipow(T v) noexcept { - return (N == 0) ? 1 - : (N % 2 == 0) ? ipow(v) * ipow(v) - : v * ipow<(N - 1) / 2>(v) * ipow<(N - 1) / 2>(v); + if constexpr (N == 0) + { + return 1; + } + else if constexpr (N % 2 == 0) + { + return ipow(v) * ipow(v); + } + else + { + return v * ipow<(N - 1) / 2>(v) * ipow<(N - 1) / 2>(v); + } } //---------------------------------------------------------------------------// diff --git a/src/corecel/math/Quantity.hh b/src/corecel/math/Quantity.hh index 5f5de76960..019b08bcc0 100644 --- a/src/corecel/math/Quantity.hh +++ b/src/corecel/math/Quantity.hh @@ -100,13 +100,13 @@ using AccessorResultType = typename AccessorTraits::result_type; * * \note The Quantity is designed to be a simple "strong type" class, not a * complex mathematical class. To operate on quantities, you must use - `value_as` + * `value_as` * (to operate within the Quantity's unit system) or `native_value_from` (to * operate in the Celeritas native unit system), use the resulting numeric * values in your mathematical expressions, then return a new Quantity class * with the resulting value and correct type. */ -template +template class Quantity { public: @@ -122,13 +122,15 @@ class Quantity constexpr Quantity() = default; //! Construct with value in celeritas native units - explicit CELER_CONSTEXPR_FUNCTION Quantity(value_type value) + explicit CELER_CONSTEXPR_FUNCTION Quantity(value_type value) noexcept : value_(value) { } //! Construct implicitly from a unitless quantity - CELER_CONSTEXPR_FUNCTION Quantity(Unitless uq) : value_(uq.value_) {} + CELER_CONSTEXPR_FUNCTION Quantity(Unitless uq) noexcept : value_(uq.value_) + { + } //!@{ //! Access the underlying numeric value, discarding units @@ -149,33 +151,33 @@ class Quantity //---------------------------------------------------------------------------// //! \cond -#define CELER_DEFINE_QUANTITY_CMP(TOKEN) \ - template \ - CELER_CONSTEXPR_FUNCTION bool operator TOKEN(Quantity lhs, \ - Quantity rhs) \ - { \ - return lhs.value() TOKEN rhs.value(); \ - } \ - template \ - CELER_CONSTEXPR_FUNCTION bool operator TOKEN( \ - Quantity lhs, detail::UnitlessQuantity rhs) \ - { \ - return lhs.value() TOKEN rhs.value_; \ - } \ - template \ - CELER_CONSTEXPR_FUNCTION bool operator TOKEN( \ - detail::UnitlessQuantity lhs, Quantity rhs) \ - { \ - return lhs.value_ TOKEN rhs.value(); \ - } \ - namespace detail \ - { \ - template \ - CELER_CONSTEXPR_FUNCTION bool \ - operator TOKEN(UnitlessQuantity lhs, UnitlessQuantity rhs) \ - { \ - return lhs.value_ TOKEN rhs.value_; \ - } \ +#define CELER_DEFINE_QUANTITY_CMP(TOKEN) \ + template \ + CELER_CONSTEXPR_FUNCTION bool operator TOKEN( \ + Quantity lhs, Quantity rhs) noexcept \ + { \ + return lhs.value() TOKEN rhs.value(); \ + } \ + template \ + CELER_CONSTEXPR_FUNCTION bool operator TOKEN( \ + Quantity lhs, detail::UnitlessQuantity rhs) noexcept \ + { \ + return lhs.value() TOKEN rhs.value_; \ + } \ + template \ + CELER_CONSTEXPR_FUNCTION bool operator TOKEN( \ + detail::UnitlessQuantity lhs, Quantity rhs) noexcept \ + { \ + return lhs.value_ TOKEN rhs.value(); \ + } \ + namespace detail \ + { \ + template \ + CELER_CONSTEXPR_FUNCTION bool \ + operator TOKEN(UnitlessQuantity lhs, UnitlessQuantity rhs) noexcept \ + { \ + return lhs.value_ TOKEN rhs.value_; \ + } \ } //!@{ @@ -194,40 +196,41 @@ CELER_DEFINE_QUANTITY_CMP(>=) //! Math operator for Quantity template CELER_CONSTEXPR_FUNCTION auto -operator+(Quantity lhs, Quantity rhs) -> decltype(auto) +operator+(Quantity lhs, Quantity rhs) noexcept -> decltype(auto) { return Quantity>{lhs.value() + rhs.value()}; } template CELER_CONSTEXPR_FUNCTION auto -operator-(Quantity lhs, Quantity rhs) -> decltype(auto) +operator-(Quantity lhs, Quantity rhs) noexcept -> decltype(auto) { return Quantity>{lhs.value() - rhs.value()}; } template -CELER_CONSTEXPR_FUNCTION auto operator-(Quantity q) -> Quantity +CELER_CONSTEXPR_FUNCTION auto operator-(Quantity q) noexcept + -> Quantity { return Quantity{-q.value()}; } template -CELER_CONSTEXPR_FUNCTION auto operator*(Quantity lhs, T2 rhs) +CELER_CONSTEXPR_FUNCTION auto operator*(Quantity lhs, T2 rhs) noexcept -> decltype(auto) { return Quantity>{lhs.value() * rhs}; } template -CELER_CONSTEXPR_FUNCTION auto operator*(T rhs, Quantity lhs) +CELER_CONSTEXPR_FUNCTION auto operator*(T rhs, Quantity lhs) noexcept -> decltype(auto) { return Quantity>{rhs * lhs.value()}; } template -CELER_CONSTEXPR_FUNCTION auto operator/(Quantity lhs, T2 rhs) +CELER_CONSTEXPR_FUNCTION auto operator/(Quantity lhs, T2 rhs) noexcept -> decltype(auto) { return Quantity>{lhs.value() / rhs}; @@ -241,7 +244,7 @@ template struct UnitDivide { //! Get the conversion factor of the resulting unit - static CELER_CONSTEXPR_FUNCTION auto value() -> decltype(auto) + static CELER_CONSTEXPR_FUNCTION auto value() noexcept -> decltype(auto) { return C1::value() / C2::value(); } @@ -252,7 +255,7 @@ template struct UnitProduct { //! Get the conversion factor of the resulting unit - static CELER_CONSTEXPR_FUNCTION auto value() -> decltype(auto) + static CELER_CONSTEXPR_FUNCTION auto value() noexcept -> decltype(auto) { return C1::value() * C2::value(); } @@ -264,7 +267,8 @@ struct UnitProduct /*! * Get a zero quantity (analogous to nullptr). */ -CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity zero_quantity() +CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity +zero_quantity() noexcept { return {0}; } @@ -273,7 +277,8 @@ CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity zero_quantity() /*! * Get a quantitity greater than any other numeric quantity. */ -CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity max_quantity() +CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity +max_quantity() noexcept { return {numeric_limits::infinity()}; } @@ -282,7 +287,8 @@ CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity max_quantity() /*! * Get a quantitity less than any other numeric quantity. */ -CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity neg_max_quantity() +CELER_CONSTEXPR_FUNCTION detail::UnitlessQuantity +neg_max_quantity() noexcept { return {-numeric_limits::infinity()}; } @@ -310,8 +316,8 @@ swap(Quantity& a, Quantity& b) noexcept * \endcode */ template -CELER_CONSTEXPR_FUNCTION auto native_value_from(Quantity quant) - -> decltype(auto) +CELER_CONSTEXPR_FUNCTION auto +native_value_from(Quantity quant) noexcept -> decltype(auto) { return quant.value() * UnitT::value(); } @@ -329,7 +335,7 @@ CELER_CONSTEXPR_FUNCTION auto native_value_from(Quantity quant) * \endcode */ template -CELER_CONSTEXPR_FUNCTION Q native_value_to(typename Q::value_type value) +CELER_CONSTEXPR_FUNCTION Q native_value_to(typename Q::value_type value) noexcept { return Q{value / Q::unit_type::value()}; } @@ -346,8 +352,8 @@ CELER_CONSTEXPR_FUNCTION Q native_value_to(typename Q::value_type value) * \endcode */ template -CELER_CONSTEXPR_FUNCTION auto value_as(Quantity quant) - -> ValueT +CELER_CONSTEXPR_FUNCTION auto +value_as(Quantity quant) noexcept -> ValueT { static_assert(std::is_same>::value, "quantity units do not match"); diff --git a/src/corecel/math/detail/MathImpl.hh b/src/corecel/math/detail/MathImpl.hh index a2b1b0813f..b0481cb0f7 100644 --- a/src/corecel/math/detail/MathImpl.hh +++ b/src/corecel/math/detail/MathImpl.hh @@ -55,7 +55,7 @@ inline void sincospi(T x, T* sptr, T* cptr) } else { - x *= m_pi; + x *= static_cast(m_pi); cval = std::cos(x); sval = std::sin(x); } diff --git a/src/corecel/sys/Environment.cc b/src/corecel/sys/Environment.cc index dcabc1e4c4..d1a086cd4d 100644 --- a/src/corecel/sys/Environment.cc +++ b/src/corecel/sys/Environment.cc @@ -24,8 +24,8 @@ namespace celeritas */ Environment& environment() { - static Environment environ; - return environ; + static Environment result; + return result; } //---------------------------------------------------------------------------// diff --git a/src/corecel/sys/KernelRegistry.hh b/src/corecel/sys/KernelRegistry.hh index 6d8af00bfd..a7eef4bbf1 100644 --- a/src/corecel/sys/KernelRegistry.hh +++ b/src/corecel/sys/KernelRegistry.hh @@ -8,6 +8,7 @@ #pragma once #include +#include #include // IWYU pragma: keep #include #include @@ -25,13 +26,15 @@ namespace celeritas //---------------------------------------------------------------------------// struct KernelProfiling { + using value_type = std::uint_least64_t; + //!< Number of times launched - std::atomic num_launches{0}; + std::atomic num_launches{0}; //!< Number of threads integrated over all launches - std::atomic accum_threads{0}; + std::atomic accum_threads{0}; // Increment atomic counters given the number of threads - inline void log_launch(int num_threads); + inline void log_launch(value_type num_threads); }; //---------------------------------------------------------------------------// @@ -107,7 +110,7 @@ std::ostream& operator<<(std::ostream& os, KernelMetadata const& md); /*! * Accumulate counters for a kernel launch. */ -void KernelProfiling::log_launch(int num_threads) +void KernelProfiling::log_launch(value_type num_threads) { CELER_EXPECT(num_threads > 0); diff --git a/src/corecel/sys/MemRegistry.hh b/src/corecel/sys/MemRegistry.hh index b2e059732b..863570f7fb 100644 --- a/src/corecel/sys/MemRegistry.hh +++ b/src/corecel/sys/MemRegistry.hh @@ -7,6 +7,7 @@ //---------------------------------------------------------------------------// #pragma once +#include #include #include @@ -20,12 +21,14 @@ namespace celeritas //! SI prefix for multiples of 1024 struct Kibi { - static CELER_CONSTEXPR_FUNCTION int value() { return 1024; } + using value_type = std::size_t; + + static CELER_CONSTEXPR_FUNCTION value_type value() { return 1024u; } static char const* label() { return "kibi"; } }; //! 1024 bytes -using KibiBytes = Quantity; +using KibiBytes = Quantity; //! Ordered identifiers for memory allocation segments using MemUsageId = OpaqueId; @@ -39,20 +42,20 @@ struct MemUsageEntry //! Difference in CPU memory usage from beginning to end KibiBytes cpu_delta{}; //! Reported CPU "high water mark" at the end the block - KibiBytes cpu_hwm{-1}; + KibiBytes cpu_hwm{}; //! Difference in GPU memory usage from beginning to end KibiBytes gpu_delta{}; //! Reported GPU "high water mark" at the end the block - KibiBytes gpu_usage{-1}; + KibiBytes gpu_usage{}; }; //---------------------------------------------------------------------------// /*! * Track memory usage across the application. * - * This class is not thread-safe and should generally be used during setup. The - * memory usage entries are a tree. Pushing and popping should be done with \c - * ScopedMem . + * This class is \em not thread-safe and should generally be used during setup. + * The memory usage entries are a tree. Pushing and popping should be done with + * \c ScopedMem . */ class MemRegistry { diff --git a/src/corecel/sys/ScopedMem.cc b/src/corecel/sys/ScopedMem.cc index 4fa5540c21..8bcc5d4627 100644 --- a/src/corecel/sys/ScopedMem.cc +++ b/src/corecel/sys/ScopedMem.cc @@ -13,9 +13,11 @@ #elif defined(__linux__) # include #elif defined(_WIN32) -# include # include +// Note: windows header *must* precede psapi +# include #endif +#include #include #include "corecel/device_runtime_api.h" @@ -74,13 +76,13 @@ MemResult get_cpu_mem() return result; } -std::ptrdiff_t get_gpu_mem() +std::size_t get_gpu_mem() { std::size_t free{0}; std::size_t total{0}; CELER_DEVICE_CALL_PREFIX(MemGetInfo(&free, &total)); CELER_ASSERT(total > free); - return std::ptrdiff_t(total) - std::ptrdiff_t(free); + return total - free; } //---------------------------------------------------------------------------// @@ -120,16 +122,27 @@ ScopedMem::~ScopedMem() MemUsageEntry& entry = registry_.value()->get(id_); // Save CPU stats - std::ptrdiff_t stop_hwm = get_cpu_mem().hwm; + auto stop_hwm = get_cpu_mem().hwm; entry.cpu_hwm = native_value_to(stop_hwm); + if (CELER_UNLIKELY(stop_hwm < cpu_start_hwm_)) + { + std::cerr << "An error occurred while calculating CPU memory " + "usage for '" + << entry.label << ": end HWM " + << native_value_to(stop_hwm).value() + << " KiB is less than beginning HWM " + << native_value_to(cpu_start_hwm_).value() + << " KiB\n"; + } entry.cpu_delta = native_value_to(stop_hwm - cpu_start_hwm_); if (celeritas::device()) { try { - std::ptrdiff_t stop_usage = get_gpu_mem(); + auto stop_usage = get_gpu_mem(); entry.gpu_usage = native_value_to(stop_usage); + CELER_ASSERT(stop_usage >= gpu_start_used_); entry.gpu_delta = native_value_to(stop_usage - gpu_start_used_); } diff --git a/src/corecel/sys/ScopedMem.hh b/src/corecel/sys/ScopedMem.hh index adc5519bdd..4a36b6e289 100644 --- a/src/corecel/sys/ScopedMem.hh +++ b/src/corecel/sys/ScopedMem.hh @@ -7,7 +7,6 @@ //---------------------------------------------------------------------------// #pragma once -#include #include #include "corecel/cont/InitializedValue.hh" @@ -62,10 +61,12 @@ class ScopedMem //!@} private: + using value_type = KibiBytes::value_type; + InitializedValue registry_; MemUsageId id_; - std::ptrdiff_t cpu_start_hwm_{0}; - std::ptrdiff_t gpu_start_used_{0}; + value_type cpu_start_hwm_{0}; + value_type gpu_start_used_{0}; }; //---------------------------------------------------------------------------// diff --git a/src/corecel/sys/Stream.cc b/src/corecel/sys/Stream.cc index aae9de441a..1de3d7c5ab 100644 --- a/src/corecel/sys/Stream.cc +++ b/src/corecel/sys/Stream.cc @@ -17,6 +17,13 @@ namespace celeritas { +#if CELER_USE_DEVICE +// GCC 8 and 9 are known to print a warning for "maybe unused" variables that +// are actually used (after preprocessor logic). +# define CELER_UNUSED_UNLESS_DEVICE +#else +# define CELER_UNUSED_UNLESS_DEVICE [[maybe_unused]] +#endif //---------------------------------------------------------------------------// /*! @@ -24,7 +31,7 @@ namespace celeritas */ template auto AsyncMemoryResource::do_allocate( - [[maybe_unused]] std::size_t bytes, std::size_t) -> pointer + CELER_UNUSED_UNLESS_DEVICE std::size_t bytes, std::size_t) -> pointer { void* ret; CELER_DEVICE_CALL_PREFIX(MallocAsync(&ret, bytes, stream_)); @@ -36,9 +43,8 @@ auto AsyncMemoryResource::do_allocate( * Deallocate device memory. */ template -void AsyncMemoryResource::do_deallocate([[maybe_unused]] pointer p, - std::size_t, - std::size_t) +void AsyncMemoryResource::do_deallocate( + CELER_UNUSED_UNLESS_DEVICE pointer p, std::size_t, std::size_t) { try { diff --git a/src/corecel/sys/Version.cc b/src/corecel/sys/Version.cc index 4d1d05849d..254fa2a947 100644 --- a/src/corecel/sys/Version.cc +++ b/src/corecel/sys/Version.cc @@ -38,7 +38,7 @@ Version Version::from_string(std::string_view sv) // No version component given return size_type{0}; } - int result = std::atoi(submatch.first); + int result = std::atoi(&(*submatch.first)); return static_cast(result); }; diff --git a/src/orange/CMakeLists.txt b/src/orange/CMakeLists.txt index fb69f39a4e..aea1633399 100644 --- a/src/orange/CMakeLists.txt +++ b/src/orange/CMakeLists.txt @@ -29,6 +29,7 @@ list(APPEND SOURCES surf/CylAligned.cc surf/GeneralQuadric.cc surf/Plane.cc + surf/PlaneAligned.cc surf/SimpleQuadric.cc surf/Sphere.cc surf/SurfaceIO.cc diff --git a/src/orange/construct/detail/NodeSimplifier.cc b/src/orange/construct/detail/NodeSimplifier.cc index 56068851eb..e0857c9e67 100644 --- a/src/orange/construct/detail/NodeSimplifier.cc +++ b/src/orange/construct/detail/NodeSimplifier.cc @@ -7,6 +7,11 @@ //---------------------------------------------------------------------------// #include "NodeSimplifier.hh" +#include +#include + +#include "../CsgTypes.hh" + namespace celeritas { namespace csg diff --git a/src/orange/detail/UnitInserter.cc b/src/orange/detail/UnitInserter.cc index eb6e4f0f7e..b6e2758df3 100644 --- a/src/orange/detail/UnitInserter.cc +++ b/src/orange/detail/UnitInserter.cc @@ -306,7 +306,7 @@ VolumeRecord UnitInserter::insert_volume(SurfacesRecord const& surf_record, // Mark as 'simple safety' if all the surfaces are simple bool simple_safety = true; - logic_int max_intersections = 0; + size_type max_intersections = 0; for (LocalSurfaceId sid : v.faces) { @@ -334,7 +334,7 @@ VolumeRecord UnitInserter::insert_volume(SurfacesRecord const& surf_record, .insert_back(v.faces.begin(), v.faces.end()); output.logic = make_builder(&orange_data_->logic_ints) .insert_back(input_logic.begin(), input_logic.end()); - output.max_intersections = max_intersections; + output.max_intersections = static_cast(max_intersections); output.flags = v.flags; if (simple_safety) { diff --git a/src/orange/surf/PlaneAligned.cc b/src/orange/surf/PlaneAligned.cc new file mode 100644 index 0000000000..740f33e989 --- /dev/null +++ b/src/orange/surf/PlaneAligned.cc @@ -0,0 +1,19 @@ +//----------------------------------*-C++-*----------------------------------// +// Copyright 2023 UT-Battelle, LLC, and other Celeritas developers. +// See the top-level COPYRIGHT file for details. +// SPDX-License-Identifier: (Apache-2.0 OR MIT) +//---------------------------------------------------------------------------// +//! \file orange/surf/PlaneAligned.cc +//---------------------------------------------------------------------------// +#include "PlaneAligned.hh" + +namespace celeritas +{ +//---------------------------------------------------------------------------// + +template class PlaneAligned; +template class PlaneAligned; +template class PlaneAligned; + +//---------------------------------------------------------------------------// +} // namespace celeritas diff --git a/src/orange/surf/detail/QuadricPlaneConverter.hh b/src/orange/surf/detail/QuadricPlaneConverter.hh index ea365606b0..0cca06c86d 100644 --- a/src/orange/surf/detail/QuadricPlaneConverter.hh +++ b/src/orange/surf/detail/QuadricPlaneConverter.hh @@ -7,6 +7,9 @@ //---------------------------------------------------------------------------// #pragma once +#include + +#include "corecel/Assert.hh" #include "corecel/math/SoftEqual.hh" #include "orange/surf/Plane.hh" #include "orange/surf/SimpleQuadric.hh" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6b3ef0477e..821216eb1b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,7 +10,7 @@ include(CeleritasAddTest) # TEST HARNESS #-----------------------------------------------------------------------------# -set(CELERITAS_SOURCE_DIR "${PROJECT_SOURCE_DIR}") +file(TO_CMAKE_PATH "${PROJECT_SOURCE_DIR}" CELERITAS_SOURCE_DIR) configure_file(celeritas_test_config.h.in celeritas_test_config.h @ONLY) celeritas_add_library(testcel_harness diff --git a/test/Test.cc b/test/Test.cc index b4f8ed43dc..412aa76b63 100644 --- a/test/Test.cc +++ b/test/Test.cc @@ -31,10 +31,13 @@ Test::test_data_path(std::string_view subdir, std::string_view filename) std::ostringstream os; os << celeritas_source_dir << "/test/" << subdir << "/data/" << filename; - std::string result = os.str(); - CELER_VALIDATE(std::ifstream(result).good(), - << "Failed to open test data file at " << result); - return result; + std::string path = os.str(); + if (!filename.empty()) + { + CELER_VALIDATE(std::ifstream(path).good(), + << "Failed to open test data file at '" << path << "'"); + } + return path; } //---------------------------------------------------------------------------// diff --git a/test/celeritas/em/BetheHeitler.test.cc b/test/celeritas/em/BetheHeitler.test.cc index 873e19036e..73fcdafc89 100644 --- a/test/celeritas/em/BetheHeitler.test.cc +++ b/test/celeritas/em/BetheHeitler.test.cc @@ -241,7 +241,7 @@ TEST_F(BetheHeitlerInteractorTest, distributions) const auto electron = out.secondaries.front(); double eps = (electron.energy.value() + data_.electron_mass.value()) / inc_energy; - int eps_bin = eps * nbins; + auto eps_bin = static_cast(eps * nbins); if (eps_bin >= 0 && eps_bin < nbins) { ++eps_dist[eps_bin]; diff --git a/test/celeritas/em/UrbanMsc.test.cc b/test/celeritas/em/UrbanMsc.test.cc index 9c0f4304c6..56a0dc087f 100644 --- a/test/celeritas/em/UrbanMsc.test.cc +++ b/test/celeritas/em/UrbanMsc.test.cc @@ -278,7 +278,7 @@ TEST_F(UrbanMscTest, step_conversion) msc_params_->host_ref(), helper, energy, lambda, range); LogInterp calc_pstep({0, 0.9 * params.limit_min_fix()}, - {pstep_points, range}); + {static_cast(pstep_points), range}); for (auto ppt : celeritas::range(pstep_points + 1)) { // Calculate given a physics step between "tiny" and the maximum @@ -300,8 +300,9 @@ TEST_F(UrbanMscTest, step_conversion) msc_step.alpha = gp.alpha; MscStepFromGeo geo_to_true( msc_params_->host_ref().params, msc_step, range, lambda); - LogInterp calc_gstep({0, 0.9 * params.limit_min_fix()}, - {gstep_points, gp.step}); + LogInterp calc_gstep( + {0, 0.9 * params.limit_min_fix()}, + {static_cast(gstep_points), gp.step}); for (auto gpt : celeritas::range(gstep_points + 1)) { // Calculate between a nearby hypothetical geometric boundary @@ -372,7 +373,7 @@ TEST_F(UrbanMscTest, msc_scattering) 0.102364, 0.0465336, 0.00708839}; - constexpr unsigned int nsamples = std::end(energy) - std::begin(energy); + constexpr auto nsamples = std::size(energy); // Calculate range instead of hardcoding to ensure step and range values // are bit-for-bit identical when range limits the step. The first three diff --git a/test/celeritas/ext/GeantImporter.test.cc b/test/celeritas/ext/GeantImporter.test.cc index 54b2f6c7d8..25c6f38269 100644 --- a/test/celeritas/ext/GeantImporter.test.cc +++ b/test/celeritas/ext/GeantImporter.test.cc @@ -201,13 +201,13 @@ auto GeantImporterTest::summarize(VecModelMaterial const& materials) const void GeantImporterTest::ImportXsSummary::print_expected() const { cout << "/*** ADD THE FOLLOWING UNIT TEST CODE ***/\n" - << "static const real_type expected_size[] = " << repr(this->size) + << "static size_type const expected_size[] = " << repr(this->size) << ";\n" << "EXPECT_VEC_EQ(expected_size, result.size);\n" - << "static const real_type expected_e[] = " << repr(this->energy) + << "static real_type const expected_e[] = " << repr(this->energy) << ";\n" << "EXPECT_VEC_SOFT_EQ(expected_e, result.energy);\n" - << "static const real_type expected_xs[] = " << repr(this->xs) + << "static real_type const expected_xs[] = " << repr(this->xs) << ";\n" << "EXPECT_VEC_SOFT_EQ(expected_xs, result.xs);\n" << "/*** END CODE ***/\n"; @@ -686,12 +686,12 @@ TEST_F(FourSteelSlabsEmStandard, ebrems) EXPECT_EQ(2, model.materials.size()); auto result = summarize(model.materials); - static const real_type expected_size[] = {7ul, 5ul}; + static size_type const expected_size[] = {7ul, 5ul}; EXPECT_VEC_EQ(expected_size, result.size); - static const real_type expected_e[] + static real_type const expected_e[] = {0.001, 1000, 0.020822442086622, 1000}; EXPECT_VEC_SOFT_EQ(expected_e, result.energy); - static const real_type expected_xs[] = {19.90859573288, + static real_type const expected_xs[] = {19.90859573288, 77.272184544415, 16.869369978465, 66.694254412524, @@ -706,12 +706,12 @@ TEST_F(FourSteelSlabsEmStandard, ebrems) EXPECT_EQ(2, model.materials.size()); auto result = summarize(model.materials); - static const real_type expected_size[] = {6ul, 6ul}; + static size_type const expected_size[] = {6ul, 6ul}; EXPECT_VEC_EQ(expected_size, result.size); - static const real_type expected_e[] + static real_type const expected_e[] = {1000, 100000000, 1000, 100000000}; EXPECT_VEC_SOFT_EQ(expected_e, result.energy); - static const real_type expected_xs[] = {77.086886023111, + static real_type const expected_xs[] = {77.086886023111, 14.346968386977, 66.448046061979, 12.347652116819, @@ -737,12 +737,12 @@ TEST_F(FourSteelSlabsEmStandard, conv) auto result = summarize(model.materials); - static const real_type expected_size[] = {9ul, 9ul}; + static size_type const expected_size[] = {9ul, 9ul}; EXPECT_VEC_EQ(expected_size, result.size); - static const real_type expected_e[] + static real_type const expected_e[] = {1.02199782, 100000000, 1.02199782, 100000000}; EXPECT_VEC_SOFT_EQ(expected_e, result.energy); - static const real_type expected_xs[] = {1.4603666285612, + static real_type const expected_xs[] = {1.4603666285612, 4.4976609946794, 1.250617083013, 3.8760336885145, @@ -1186,7 +1186,7 @@ TEST_F(OneSteelSphere, physics) EXPECT_EQ(2, model.materials.size()); auto result = summarize(model.materials); - static const real_type expected_size[] = {6u, 5u}; + static size_type const expected_size[] = {6u, 5u}; EXPECT_VEC_EQ(expected_size, result.size); static double const expected_energy[] = {1000, 100000000, 9549.6516356879, 100000000}; diff --git a/test/celeritas/grid/CalculatorTestBase.cc b/test/celeritas/grid/CalculatorTestBase.cc index ff7c178c98..5bf5e89aaa 100644 --- a/test/celeritas/grid/CalculatorTestBase.cc +++ b/test/celeritas/grid/CalculatorTestBase.cc @@ -33,7 +33,7 @@ void CalculatorTestBase::build(real_type emin, real_type emax, size_type count) {0.0, emin}, {count - 1.0, emax}); for (auto i : range(temp_xs.size())) { - temp_xs[i] = calc_xs(i); + temp_xs[i] = calc_xs(static_cast(i)); } value_storage_ = {}; diff --git a/test/celeritas/random/SequenceEngine.hh b/test/celeritas/random/SequenceEngine.hh index e7a64363c4..50674237f3 100644 --- a/test/celeritas/random/SequenceEngine.hh +++ b/test/celeritas/random/SequenceEngine.hh @@ -112,7 +112,7 @@ SequenceEngine SequenceEngine::from_reals(Span values) using real_type = double; CELER_EXPECT(!values.empty()); - const real_type range = SequenceEngine::max() + real_type(1); + real_type const range = SequenceEngine::max() + real_type(1); SequenceEngine::VecResult elements(values.size() * 2); auto dst = elements.begin(); @@ -128,7 +128,7 @@ SequenceEngine SequenceEngine::from_reals(Span values) v *= range; // Store values - *dst++ = std::floor(v); + *dst++ = static_cast(std::floor(v)); *dst++ = second; } CELER_ENSURE(dst == elements.end()); diff --git a/test/celeritas/track/TrackInit.test.cc b/test/celeritas/track/TrackInit.test.cc index ddec9b9d51..1b74b52671 100644 --- a/test/celeritas/track/TrackInit.test.cc +++ b/test/celeritas/track/TrackInit.test.cc @@ -300,16 +300,16 @@ TYPED_TEST(TrackInitTest, run) TYPED_TEST(TrackInitTest, primaries) { - const size_type num_sets = 4; - const size_type num_primaries = 16; - const size_type num_tracks = 16; + size_type num_sets = 4; + size_type num_primaries = 16; + size_type num_tracks = 16; this->build_states(num_tracks); this->init_tracks(); // Kill half the tracks in each interaction and don't produce secondaries - auto interact = [] { + auto interact = [&] { std::vector alloc(num_tracks, 0); std::vector alive(num_tracks); for (size_type i = 0; i < num_tracks; ++i) @@ -360,8 +360,8 @@ TYPED_TEST(TrackInitTest, primaries) TYPED_TEST(TrackInitTest, extend_from_secondaries) { // Basic setup - const size_type num_primaries = 8; - const size_type num_tracks = 8; + size_type num_primaries = 8; + size_type num_tracks = 8; std::vector const alive = {true, false, false, true, true, false, false, true}; @@ -417,7 +417,7 @@ TYPED_TEST(TrackInitTest, extend_from_secondaries) EXPECT_TRUE(std::all_of( std::begin(result.track_ids), std::end(result.track_ids), - [i](unsigned int id) { return id < num_tracks + (i + 1) * 4; })); + [&](unsigned int id) { return id < num_tracks + (i + 1) * 4; })); // Parent ids may not be deterministic, but all non-killed tracks are // guaranteed to be primaries at every iteration. At end of first diff --git a/test/corecel/cont/Range.test.cc b/test/corecel/cont/Range.test.cc index 1102974e5d..6a064ec757 100644 --- a/test/corecel/cont/Range.test.cc +++ b/test/corecel/cont/Range.test.cc @@ -38,7 +38,7 @@ enum class WontWorkColors namespace pokemon { -enum Pokemon +enum Pokemon : int { charmander = 0, bulbasaur, @@ -211,8 +211,8 @@ TEST(RangeTest, different_enums) TEST(RangeTest, enum_step) { - EXPECT_TRUE((std::is_same::type, - unsigned int>::value)); + EXPECT_TRUE( + (std::is_same_v, int>)); std::vector vals; for (auto p : range(pokemon::size_).step(3u)) diff --git a/test/corecel/io/Join.test.cc b/test/corecel/io/Join.test.cc index 6c6b5e1c9c..9ec51499ff 100644 --- a/test/corecel/io/Join.test.cc +++ b/test/corecel/io/Join.test.cc @@ -90,7 +90,7 @@ TEST_F(JoinTest, DISABLED_ginormous) { std::ofstream out(this->make_unique_filename(".txt")); - auto r = range(1e7); + auto r = range(1000000000ull); out << join(r.begin(), r.end(), "\n"); } diff --git a/test/corecel/math/NumericLimits.test.cc b/test/corecel/math/NumericLimits.test.cc index 2828c17afa..6549656d8f 100644 --- a/test/corecel/math/NumericLimits.test.cc +++ b/test/corecel/math/NumericLimits.test.cc @@ -37,7 +37,9 @@ TYPED_TEST(RealNumericLimitsTest, host) EXPECT_EQ(std_limits_t::infinity(), celer_limits_t::infinity()); EXPECT_EQ(std_limits_t::max(), celer_limits_t::max()); EXPECT_TRUE(std::isnan(celer_limits_t::quiet_NaN())); +#ifndef _MSC_VER EXPECT_EQ(std_limits_t::infinity(), TypeParam(1) / TypeParam(0)); +#endif } #if CELER_USE_DEVICE diff --git a/test/corecel/math/Quantity.test.cc b/test/corecel/math/Quantity.test.cc index 5f67302ac9..fe4531e1b4 100644 --- a/test/corecel/math/Quantity.test.cc +++ b/test/corecel/math/Quantity.test.cc @@ -31,7 +31,7 @@ struct TwoPi { static double value() { return 2 * pi; } }; -using Revolution = Quantity; +using Revolution = Quantity; struct DozenUnit { @@ -43,11 +43,14 @@ struct DozenUnit // TESTS //---------------------------------------------------------------------------// -TEST(QuantityTest, simplicity) +TEST(QuantityTest, constexpr_attributes) { + EXPECT_TRUE((std::is_same_v)); EXPECT_EQ(sizeof(Revolution), sizeof(double)); EXPECT_TRUE(std::is_standard_layout::value); EXPECT_TRUE(std::is_default_constructible::value); + + EXPECT_TRUE((std::is_same_v::value_type, int>)); } TEST(QuantityTest, usage) @@ -69,7 +72,7 @@ TEST(QuantityTest, usage) EXPECT_DOUBLE_EQ(0.5, value_as(half_rev)); // Check integer division works correctly - using Dozen = Quantity; + using Dozen = Quantity; auto two_dozen = native_value_to(24); EXPECT_TRUE((std::is_same_v)); EXPECT_EQ(2, value_as(two_dozen)); @@ -190,7 +193,7 @@ TEST(QuantityTest, math) TEST(QuantityTest, swappiness) { - using Dozen = Quantity; + using Dozen = Quantity; Dozen dozen{1}, gross{12}; { // ADL should prefer swap implementation @@ -212,7 +215,7 @@ TEST(QuantityTest, swappiness) TEST(QuantityTest, TEST_IF_CELERITAS_JSON(io)) { #if CELERITAS_USE_JSON - using Dozen = Quantity; + using Dozen = Quantity; { SCOPED_TRACE("Input as scalar"); diff --git a/test/corecel/sys/ScopedSignalHandler.test.cc b/test/corecel/sys/ScopedSignalHandler.test.cc index 21de144d6a..c3868a254a 100644 --- a/test/corecel/sys/ScopedSignalHandler.test.cc +++ b/test/corecel/sys/ScopedSignalHandler.test.cc @@ -40,6 +40,7 @@ TEST(ScopedSignalHandlerTest, single) } } +#ifndef _WIN32 TEST(ScopedSignalHandlerTest, multiple) { using FuncPtr = int (*)(int); @@ -63,6 +64,7 @@ TEST(ScopedSignalHandlerTest, multiple) } } } +#endif TEST(ScopedSignalHandlerTest, nested) { diff --git a/test/testdetail/TestMacrosImpl.hh b/test/testdetail/TestMacrosImpl.hh index 0cd540a637..aa1bbf83eb 100644 --- a/test/testdetail/TestMacrosImpl.hh +++ b/test/testdetail/TestMacrosImpl.hh @@ -322,7 +322,7 @@ std::string failure_msg(char const* expected_expr, using std::setw; // Calculate how many digits we need to space out - int idig = num_digits(failures.back().index); + int idig = num_digits(static_cast(failures.back().index)); int vdig = 16; // Construct our own stringstream because google test ignores setw @@ -361,7 +361,7 @@ std::string float_failure_msg(char const* expected_expr, using std::setw; // Calculate how many digits we need to space out the index - int idig = num_digits(failures.back().index); + int idig = num_digits(static_cast(failures.back().index)); int vdig = std::max(std::numeric_limits::digits10, std::numeric_limits::digits10);