![]() |
|
|||
File indexing completed on 2025-02-22 10:31:26
0001 //----------------------------------*-C++-*----------------------------------// 0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers. 0003 // See the top-level COPYRIGHT file for details. 0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT) 0005 //---------------------------------------------------------------------------// 0006 //! \file celeritas/optical/action/ActionLauncher.hh 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 #include "celeritas/optical/CoreState.hh" 0019 0020 namespace celeritas 0021 { 0022 namespace optical 0023 { 0024 //---------------------------------------------------------------------------// 0025 /*! 0026 * Helper function to run an action in parallel on CPU over all states. 0027 * 0028 * Example: 0029 * \code 0030 void FooAction::step(CoreParams const& params, 0031 CoreStateHost& state) const 0032 { 0033 launch_action(state, make_blah_executor(params, state, blah)); 0034 } 0035 * \endcode 0036 */ 0037 template<class F> 0038 void launch_action(CoreState<MemSpace::host>& state, F&& execute_thread) 0039 { 0040 MultiExceptionHandler capture_exception; 0041 #if defined(_OPENMP) && CELERITAS_OPENMP == CELERITAS_OPENMP_TRACK 0042 # pragma omp parallel for 0043 #endif 0044 for (size_type i = 0, size = state.size(); 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 |
![]() ![]() |