|
|
|||
File indexing completed on 2026-01-05 10:07:26
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. 0026 * 0027 * This allows using a custom number of threads rather than the state size. 0028 */ 0029 template<class F> 0030 void launch_action(size_type num_threads, F&& execute_thread) 0031 { 0032 MultiExceptionHandler capture_exception; 0033 #if defined(_OPENMP) && CELERITAS_OPENMP == CELERITAS_OPENMP_TRACK 0034 # pragma omp parallel for 0035 #endif 0036 for (size_type i = 0; i < num_threads; ++i) 0037 { 0038 CELER_TRY_HANDLE(execute_thread(ThreadId{i}), capture_exception); 0039 } 0040 log_and_rethrow(std::move(capture_exception)); 0041 } 0042 0043 //---------------------------------------------------------------------------// 0044 /*! 0045 * Helper function to run an action in parallel on CPU over all states. 0046 * 0047 * Example: 0048 * \code 0049 void FooAction::step(CoreParams const& params, 0050 CoreStateHost& state) const 0051 { 0052 launch_action(state, make_blah_executor(params, state, blah)); 0053 } 0054 * \endcode 0055 */ 0056 template<class F> 0057 void launch_action(CoreState<MemSpace::host>& state, F&& execute_thread) 0058 { 0059 return launch_action(state.size(), std::forward<F>(execute_thread)); 0060 } 0061 0062 //---------------------------------------------------------------------------// 0063 } // namespace optical 0064 } // 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 |
|