![]() |
|
|||
File indexing completed on 2025-02-21 09:29: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 accel/SimpleOffload.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 class G4Run; 0011 class G4Event; 0012 class G4Track; 0013 0014 namespace celeritas 0015 { 0016 class SharedParams; 0017 struct SetupOptions; 0018 class LocalTransporter; 0019 0020 //---------------------------------------------------------------------------// 0021 /*! 0022 * Compressed interface for running Celeritas in a multithread Geant4 app. 0023 * 0024 * This class *must* be a thread-local instance with references to data that 0025 * exceed the lifetime of the class: e.g. SharedParams can be a global 0026 * variable, and LocalTransporter can be a global variable with \c thread_local 0027 * storage duration. 0028 * 0029 * The \c CELER_DISABLE environment variable, if set and non-empty, will 0030 * disable offloading so that Celeritas will not be built nor kill tracks. 0031 * 0032 * The method names correspond to methods in Geant4 User Actions and *must* be 0033 * called from all threads, both worker and master. 0034 */ 0035 class SimpleOffload 0036 { 0037 public: 0038 //! Construct with celeritas disabled 0039 SimpleOffload() = default; 0040 0041 // Construct from a reference to shared params and local data 0042 SimpleOffload(SetupOptions const* setup, 0043 SharedParams* params, 0044 LocalTransporter* local); 0045 0046 //! Lazy initialization of this class on a worker thread 0047 void Build(SetupOptions const* setup, 0048 SharedParams* params, 0049 LocalTransporter* local) 0050 { 0051 *this = {setup, params, local}; 0052 } 0053 0054 //! Lazy initialization of this class on the master thread 0055 void BuildForMaster(SetupOptions const* setup, SharedParams* params) 0056 { 0057 *this = {setup, params, nullptr}; 0058 } 0059 0060 // Initialize celeritas data from setup options 0061 void BeginOfRunAction(G4Run const* run); 0062 0063 // Send Celeritas the event ID 0064 void BeginOfEventAction(G4Event const* event); 0065 0066 // Send tracks to Celeritas if applicable and "StopAndKill" if so 0067 void PreUserTrackingAction(G4Track* track); 0068 0069 // Flush offloaded tracks from Celeritas 0070 void EndOfEventAction(G4Event const* event); 0071 0072 // Finalize 0073 void EndOfRunAction(G4Run const* run); 0074 0075 //! Whether offloading is enabled 0076 explicit operator bool() const { return setup_ != nullptr; } 0077 0078 private: 0079 SetupOptions const* setup_{nullptr}; 0080 SharedParams* params_{nullptr}; 0081 LocalTransporter* local_{nullptr}; 0082 }; 0083 0084 //---------------------------------------------------------------------------// 0085 } // 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 |
![]() ![]() |