File indexing completed on 2025-02-22 10:31:22
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <utility>
0011
0012 #include "corecel/Config.hh"
0013
0014 #include "corecel/Assert.hh"
0015 #include "corecel/Types.hh"
0016 #include "corecel/sys/MultiExceptionHandler.hh"
0017 #include "corecel/sys/ThreadId.hh"
0018
0019 #include "ActionInterface.hh"
0020 #include "CoreParams.hh"
0021 #include "CoreState.hh"
0022 #include "KernelContextException.hh"
0023
0024 namespace celeritas
0025 {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 template<class F>
0040 void launch_core(std::string_view label,
0041 celeritas::CoreParams const& params,
0042 celeritas::CoreState<MemSpace::host>& state,
0043 F&& execute_thread)
0044 {
0045 MultiExceptionHandler capture_exception;
0046 #if defined(_OPENMP) && CELERITAS_OPENMP == CELERITAS_OPENMP_TRACK
0047 # pragma omp parallel for
0048 #endif
0049 for (size_type i = 0, size = state.size(); i != size; ++i)
0050 {
0051 CELER_TRY_HANDLE_CONTEXT(
0052 execute_thread(ThreadId{i}),
0053 capture_exception,
0054 KernelContextException(
0055 params.ref<MemSpace::host>(), state.ref(), ThreadId{i}, label));
0056 }
0057 log_and_rethrow(std::move(capture_exception));
0058 }
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 template<class F>
0074 void launch_action(CoreStepActionInterface const& action,
0075 celeritas::CoreParams const& params,
0076 celeritas::CoreState<MemSpace::host>& state,
0077 F&& execute_thread)
0078 {
0079 return launch_core(
0080 action.label(), params, state, std::forward<F>(execute_thread));
0081 }
0082
0083
0084 }