Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows support #930

Merged
merged 29 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
119cb5b
Fix corecel errors/warnings on windows
sethrj Sep 7, 2023
f493f9b
Fix truncation warning
sethrj Sep 7, 2023
98364a4
Fix missing include
sethrj Sep 7, 2023
b2ca9fe
Instantiate aligned plane explicitly
sethrj Sep 7, 2023
524564c
Use 'if constexpr' to avoid choking msvc
sethrj Sep 7, 2023
a91783a
Define windows macros
sethrj Sep 7, 2023
ca78569
Fix compiler failure from divide by zero
sethrj Sep 7, 2023
c70a631
Fix integer overflow in windows integer literal
sethrj Sep 7, 2023
2ee19a1
Fix conversion warnings
sethrj Sep 7, 2023
1e434b5
Disable dominance warning
sethrj Sep 7, 2023
6be5026
Fix implicit cast in step conversion
sethrj Sep 7, 2023
ac55d87
Fix MSVC implicit capture weirdness
sethrj Sep 7, 2023
ad5a197
Fix use of SIGUSR2
sethrj Sep 7, 2023
190c05d
Fix narrowing conversion
sethrj Sep 7, 2023
80f8a1e
Fix missing symbol
sethrj Sep 7, 2023
23096cf
Work around windows environ definition
sethrj Sep 7, 2023
13d5367
Explicitly specify enum type
sethrj Sep 7, 2023
7b88218
Fix windows issues with paths
sethrj Sep 7, 2023
dc5f03c
Improve dependency logic for building inside another project
sethrj Sep 7, 2023
26b76d4
fixup! Improve dependency logic for building inside another project
sethrj Sep 8, 2023
8c69634
Clang-format
sethrj Sep 9, 2023
0c5a57e
Work around dumb GCC attribute warning
sethrj Sep 11, 2023
32359d2
Document
sethrj Sep 11, 2023
e4eb459
Add default type to quantity based on underlying unit
sethrj Sep 12, 2023
95ee81e
Mark quantity functions as noexcept
sethrj Sep 12, 2023
adc543b
Use size_t instead of ptrdiff_t and long int for scoped mem
sethrj Sep 12, 2023
c583a9a
fixup! Add default type to quantity based on underlying unit
sethrj Sep 12, 2023
e117158
Merge remote-tracking branch 'upstream/develop' into fix-windows-build
sethrj Sep 12, 2023
21ac428
iwyu
sethrj Sep 12, 2023
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
29 changes: 18 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down Expand Up @@ -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()

Expand All @@ -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"
)
Expand All @@ -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(
Expand Down Expand Up @@ -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
#----------------------------------------------------------------------------#
Expand Down
7 changes: 7 additions & 0 deletions app/celer-sim/RunnerInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
#include "celeritas/phys/PrimaryGeneratorOptions.hh"
#include "celeritas/user/RootStepWriter.hh"

#ifdef _WIN32
#include <cstdlib>
#ifdef environ
#undef environ
#endif
#endif

namespace celeritas
{
namespace app
Expand Down
4 changes: 4 additions & 0 deletions app/celer-sim/Transporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ auto Transporter<M>::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;
Expand Down
7 changes: 7 additions & 0 deletions src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ if(NOT CELERITAS_USE_OpenMP
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-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 "$<$<COMPILE_LANGUAGE:CXX>:/wd4267$<SEMICOLON>/wd4250>"
)
endif()


celeritas_target_link_libraries(celeritas
PRIVATE ${PRIVATE_DEPS}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/interactor/RayleighInteractor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/model/RayleighModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/model/RelativisticBremModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/em/model/WentzelModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void WentzelModel::build_data(HostVal<WentzelData>& 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);

Expand Down
2 changes: 2 additions & 0 deletions src/celeritas/ext/GeantSetup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
12 changes: 6 additions & 6 deletions src/celeritas/field/DormandPrinceStepper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ DormandPrinceStepper<E>::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;

Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/field/RZMapFieldData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/grid/VectorUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::vector<double> space_impl(double start, double stop, size_type n)
result.front() = start;
for (auto i : range<size_type>(1, n - 1))
{
result[i] = interp(i);
result[i] = interp(static_cast<double>(i));
}
// Manually set last point to avoid any differences due to roundoff
result.back() = stop;
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/phys/PhysicsData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ inline void resize(PhysicsStateData<Ownership::value, M>* 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_type>(size * params.scalars.secondary_stack_factor));
}

//---------------------------------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/random/XorwowRngData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void resize(XorwowRngStateData<Ownership::value, M>* state,

// Seed sequence to generate well-distributed seed numbers, including
// stream ID to give strings different starting contributions
std::vector<unsigned int> host_seeds(params.seed.begin(),
std::vector<std::seed_seq::result_type> host_seeds(params.seed.begin(),
params.seed.end());
if (stream != StreamId{0})
{
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/track/detail/TrackSortUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ template<>
void shuffle_track_slots<MemSpace::host>(
Span<TrackSlotId::size_type> track_slots, StreamId)
{
unsigned int seed = track_slots.size();
auto seed = static_cast<unsigned int>(track_slots.size());
std::mt19937 g{seed};
std::shuffle(track_slots.begin(), track_slots.end(), g);
}
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/track/detail/TrackSortUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct alive_predicate
{
ObserverPtr<TrackStatus const> 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;
}
Expand All @@ -93,7 +93,7 @@ struct action_comparator
{
ObserverPtr<ActionId const> 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];
}
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/user/SimpleCalo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void SimpleCalo::output(JsonPimpl* j) const
std::vector<int> ids;
for (VolumeId vid : volume_ids_)
{
ids.push_back(vid.get());
ids.push_back(static_cast<int>(vid.get()));
}
obj["volume_ids"] = std::move(ids);
obj["volume_labels"] = volume_labels_;
Expand Down
16 changes: 15 additions & 1 deletion src/corecel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<COMPILE_LANGUAGE:CXX>: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
$<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus /Zc:preprocessor>
)
endif()
endif()


celeritas_target_include_directories(corecel
PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion src/corecel/cont/Range.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Range
template<class U, std::enable_if_t<std::is_unsigned<U>::value, bool> = true>
CELER_CONSTEXPR_FUNCTION detail::StepRange<step_type<U>> step(U step)
{
return {*begin_, *end_, step};
return {*begin_, *end_, static_cast<size_type>(step)};
}
//! \endcond

Expand Down
2 changes: 1 addition & 1 deletion src/corecel/data/Collection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_type>(this->storage().size());
pcanal marked this conversation as resolved.
Show resolved Hide resolved
}
CELER_FORCEINLINE_FUNCTION bool empty() const
{
Expand Down
6 changes: 5 additions & 1 deletion src/corecel/io/ColorUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <cstdio>
#include <cstdlib>
#include <string>
#ifndef _WIN32
#include <unistd.h>
#endif

#include "corecel/sys/Environment.hh"

Expand All @@ -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())
{
Expand All @@ -44,11 +46,13 @@ bool use_color()
// Color is explicitly enabled
return true;
}
#ifndef _WIN32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a Windows equivalent to tell if there a terminal attached or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure at all... even if there is, the Windows terminals don't natively support ANSI color sequences (only when running through something like git-bash). Either way, for the use cases of concern to SCALE, we won't be running through the command line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

humm ... isn't the code then

#ifdef _WIN32
     return false;
#else 
... existing code...
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could be running through git-bash but compiled against only regular windows. (This is how I was testing.) In that case the ANSI sequences are processed correctly because git-bash defines the TERM variable.

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)
Expand Down
2 changes: 1 addition & 1 deletion src/corecel/io/StringUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ std::string_view trim(std::string_view input)
{
--stop;
}
return {start, static_cast<std::size_t>(stop - start)};
return {&(*start), static_cast<std::size_t>(stop - start)};
}

//---------------------------------------------------------------------------//
Expand Down
16 changes: 13 additions & 3 deletions src/corecel/math/Algorithms.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int N, class T>
CELER_CONSTEXPR_FUNCTION T ipow(T v) noexcept
{
return (N == 0) ? 1
: (N % 2 == 0) ? ipow<N / 2>(v) * ipow<N / 2>(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<N / 2>(v) * ipow<N / 2>(v);
}
else
{
return v * ipow<(N - 1) / 2>(v) * ipow<(N - 1) / 2>(v);
}
}

//---------------------------------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion src/corecel/math/detail/MathImpl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ inline void sincospi(T x, T* sptr, T* cptr)
}
else
{
x *= m_pi;
x *= static_cast<T>(m_pi);
pcanal marked this conversation as resolved.
Show resolved Hide resolved
cval = std::cos(x);
sval = std::sin(x);
}
Expand Down
4 changes: 2 additions & 2 deletions src/corecel/sys/Environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace celeritas
*/
Environment& environment()
{
static Environment environ;
return environ;
static Environment result;
return result;
}

//---------------------------------------------------------------------------//
Expand Down
4 changes: 2 additions & 2 deletions src/corecel/sys/MemRegistry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace celeritas
//! SI prefix for multiples of 1024
struct Kibi
{
static CELER_CONSTEXPR_FUNCTION int value() { return 1024; }
static CELER_CONSTEXPR_FUNCTION long int value() { return 1024; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the purpose of that change? Rather than long int, do we mean int64_t ? (And almost more important how to we remember to use the right type in similar future construct?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int is 32-bit on windows and I wanted something "long"er. I try to steer away from special integer types for JSON I/O though now that I think about it, I'm not sure why. I'll unify all this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted something "long"er

Why does it matter here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because any memory change over 2GB overflows int on windows.

Copy link
Contributor

@pcanal pcanal Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I should have look up the usage :).

But then why using size_t isn't the right type? (or make_signed<size_t>)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was the conversion between size_t and ptrdiff_t that was throwing me off. I've replaced it all with size_t.

static char const* label() { return "kibi"; }
};

//! 1024 bytes
using KibiBytes = Quantity<Kibi, int>;
using KibiBytes = Quantity<Kibi, long int>;
//! Ordered identifiers for memory allocation segments
using MemUsageId = OpaqueId<struct MemUsageEntry>;

Expand Down
Loading