![]() |
|
|||
File indexing completed on 2025-09-18 09:09:09
0001 //------------------------------- -*- C++ -*- -------------------------------// 0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details 0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0004 //---------------------------------------------------------------------------// 0005 //! \file celeritas/optical/action/ActionLauncher.hh 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 #include "celeritas/optical/CoreState.hh" 0018 0019 namespace celeritas 0020 { 0021 namespace optical 0022 { 0023 //---------------------------------------------------------------------------// 0024 /*! 0025 * Helper function to run an action in parallel on CPU over all states. 0026 * 0027 * Example: 0028 * \code 0029 void FooAction::step(CoreParams const& params, 0030 CoreStateHost& state) const 0031 { 0032 launch_action(state, make_blah_executor(params, state, blah)); 0033 } 0034 * \endcode 0035 */ 0036 template<class F> 0037 void launch_action(CoreState<MemSpace::host>& state, F&& execute_thread) 0038 { 0039 MultiExceptionHandler capture_exception; 0040 size_type const size = state.size(); 0041 #if defined(_OPENMP) && CELERITAS_OPENMP == CELERITAS_OPENMP_TRACK 0042 # pragma omp parallel for 0043 #endif 0044 for (size_type i = 0; i < size; ++i) 0045 { 0046 CELER_TRY_HANDLE(execute_thread(ThreadId{i}), capture_exception); 0047 } 0048 log_and_rethrow(std::move(capture_exception)); 0049 } 0050 0051 //---------------------------------------------------------------------------// 0052 } // namespace optical 0053 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |