File indexing completed on 2025-12-23 09:43:48
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <utility>
0010
0011 #include "corecel/Config.hh"
0012
0013 #include "corecel/Assert.hh"
0014 #include "corecel/Types.hh"
0015 #include "corecel/sys/MultiExceptionHandler.hh"
0016 #include "corecel/sys/ThreadId.hh"
0017
0018 #include "ActionInterface.hh"
0019 #include "CoreParams.hh"
0020 #include "CoreState.hh"
0021 #include "KernelContextException.hh"
0022
0023 namespace celeritas
0024 {
0025
0026
0027
0028
0029
0030
0031 template<class F>
0032 void launch_core(size_type num_threads,
0033 std::string_view label,
0034 celeritas::CoreParams const& params,
0035 celeritas::CoreState<MemSpace::host>& state,
0036 F&& execute_thread)
0037 {
0038 MultiExceptionHandler capture_exception;
0039 #if defined(_OPENMP) && CELERITAS_OPENMP == CELERITAS_OPENMP_TRACK
0040 # pragma omp parallel for
0041 #endif
0042 for (size_type i = 0; i < num_threads; ++i)
0043 {
0044 CELER_TRY_HANDLE_CONTEXT(
0045 execute_thread(ThreadId{i}),
0046 capture_exception,
0047 KernelContextException(
0048 params.ref<MemSpace::host>(), state.ref(), ThreadId{i}, label));
0049 }
0050 log_and_rethrow(std::move(capture_exception));
0051 }
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 template<class F>
0067 void launch_core(std::string_view label,
0068 celeritas::CoreParams const& params,
0069 celeritas::CoreState<MemSpace::host>& state,
0070 F&& execute_thread)
0071 {
0072 return launch_core(
0073 state.size(), label, params, state, std::forward<F>(execute_thread));
0074 }
0075
0076
0077
0078
0079
0080
0081
0082 template<class F>
0083 void launch_action(CoreStepActionInterface const& action,
0084 size_type num_threads,
0085 celeritas::CoreParams const& params,
0086 celeritas::CoreState<MemSpace::host>& state,
0087 F&& execute_thread)
0088 {
0089 return launch_core(num_threads,
0090 action.label(),
0091 params,
0092 state,
0093 std::forward<F>(execute_thread));
0094 }
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 template<class F>
0110 void launch_action(CoreStepActionInterface const& action,
0111 celeritas::CoreParams const& params,
0112 celeritas::CoreState<MemSpace::host>& state,
0113 F&& execute_thread)
0114 {
0115 return launch_core(
0116 action.label(), params, state, std::forward<F>(execute_thread));
0117 }
0118
0119
0120 }