![]() |
|
|||
File indexing completed on 2025-09-17 08:54: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 corecel/sys/KernelLauncher.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <utility> 0010 0011 #include "corecel/Config.hh" 0012 0013 #include "MultiExceptionHandler.hh" 0014 #include "ThreadId.hh" 0015 0016 namespace celeritas 0017 { 0018 //---------------------------------------------------------------------------// 0019 /*! 0020 * Helper function to run an executor in parallel on CPU. 0021 * 0022 * The function should be an executor with the signature 0023 * \code void(*)(ThreadId) \endcode . 0024 * 0025 * Example: 0026 * \code 0027 void do_something() 0028 { 0029 launch_kernel(num_threads, make_blah_executor(blah)); 0030 } 0031 * \endcode 0032 */ 0033 template<class F> 0034 void launch_kernel(size_type num_threads, F&& execute_thread) 0035 { 0036 MultiExceptionHandler capture_exception; 0037 #if defined(_OPENMP) && CELERITAS_OPENMP == CELERITAS_OPENMP_TRACK 0038 # pragma omp parallel for 0039 #endif 0040 for (size_type i = 0; i < num_threads; ++i) 0041 { 0042 CELER_TRY_HANDLE(execute_thread(ThreadId{i}), capture_exception); 0043 } 0044 log_and_rethrow(std::move(capture_exception)); 0045 } 0046 0047 //---------------------------------------------------------------------------// 0048 } // 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 |
![]() ![]() |