|
|
|||
Warning, file /include/Geant4/G4VoxelisationHelper.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4VoxelisationHelper 0027 // 0028 // Class description: 0029 // 0030 // A helper class to undertake voxelisation in parallel, aiding 0031 // and off-loading the work of G4GeometryManager. 0032 // 0033 // Only one instance must exist, and it must be owned by G4GeometryManager 0034 // -- by the master thread's instance for the time being. 0035 // 0036 // It is designed to be thread safe, and its methods re-entrant. 0037 // The following methods are expected to be called asynchronously 0038 // by threads safely. 0039 0040 // Author: John Apostolakis (CERN), 10.02.2025 0041 // ------------------------------------------------------------------- 0042 #ifndef G4VOXELISATIONHELPER_HH 0043 #define G4VOXELISATIONHELPER_HH 0044 0045 #include <vector> 0046 0047 #include "G4Types.hh" 0048 #include "G4SmartVoxelStat.hh" 0049 #include "G4ios.hh" 0050 0051 class G4VPhysicalVolume; 0052 class G4Timer; 0053 0054 /** 0055 * @brief G4VoxelisationHelper is a helper class to undertake voxelisation 0056 * in parallel, aiding and off-loading the work of G4GeometryManager. 0057 */ 0058 0059 class G4VoxelisationHelper 0060 { 0061 public: 0062 0063 /** 0064 * Constructor & Destructor. 0065 */ 0066 G4VoxelisationHelper(); 0067 ~G4VoxelisationHelper(); 0068 0069 /** 0070 * Key method that creates a list of volumes and resets the state 0071 * to prepare for the parallel optimisation. 0072 */ 0073 void PrepareParallelOptimisation(G4bool allOpts, G4bool verbose); 0074 0075 /** 0076 * Contributes to voxel optimisation until all work is done. 0077 * To be called by a worker thread initialisation, not by the user. 0078 */ 0079 void UndertakeOptimisation(); 0080 0081 // Methods that can be used by this Helper, Geometry Manager and others 0082 // -------------------------------------------------------------------- 0083 0084 /** 0085 * Methods to report statistics on the voxelisation process. 0086 */ 0087 static void ReportVoxelStats( std::vector<G4SmartVoxelStat>& stats, 0088 G4double totalCpuTime, 0089 std::ostream &os = G4cout ); 0090 void ReportVoxelInfo(G4LogicalVolume* logVolume, std::ostream& os); 0091 0092 /** 0093 * Sets verbosity mode. 0094 */ 0095 inline void SetVerbosity(G4bool verbose) { fVerboseParallel = verbose; } 0096 0097 /** 0098 * Returns true if all workers are finished (or all work is done). 0099 */ 0100 G4bool IsParallelOptimisationFinished(); 0101 0102 // Auxiliary method - may be useful elsewhere 0103 0104 /** 0105 * Check that volumes marked to optimise are done, and report number 0106 * of those that are missing voxel header. 0107 */ 0108 G4int CheckOptimisation(); 0109 0110 private: // Methods used to implement the parallel optimisation 0111 0112 /** 0113 * Builds a vector of relevant volumes. 0114 */ 0115 void CreateListOfVolumesToOptimise(G4bool allOpts, G4bool verbose); 0116 0117 /** 0118 * Returns a pointer to the logical volume to optimise. 0119 */ 0120 G4LogicalVolume* ObtainVolumeToOptimise(); 0121 0122 /** 0123 * Prepares for doing the work in parallel. 0124 * Called in preparation (not MT safe). 0125 */ 0126 void ReSetParallelOptimisation(G4bool verbose); 0127 0128 /** 0129 * Resets (empties) the list of candidate volumes for optimisation. 0130 * Must be called when optimisation is finished. 0131 */ 0132 void ResetListOfVolumesToOptimise(); 0133 0134 /** 0135 * Thread-safe method for a worker to report it's finished its work. 0136 * It counts the number of workers that finished, and returns count. 0137 * It counts the number of volumes optimised; if all workers have 0138 * reported, it results in a 'Finished' state. 0139 */ 0140 G4int ReportWorkerIsDoneOptimising(unsigned int numVolumesOptimised); 0141 0142 /** 0143 * Method called when all work is done -- all workers are finished. 0144 */ 0145 void RecordOptimisationIsFinished(G4bool verbose); 0146 0147 /** 0148 * Waits until the voxelisation is all done. 0149 */ 0150 void WaitForVoxelisationFinish(G4bool verbose = false); 0151 0152 private: 0153 0154 /** The list of volumes which threads need to optimise. */ 0155 std::vector<G4LogicalVolume*> fVolumesToOptimise; 0156 0157 /** Iterator used by UndertakeOptimisation(). */ 0158 std::vector<G4LogicalVolume*>::const_iterator fLogVolumeIterator; 0159 0160 /** Statistics container shared by all workers. */ 0161 std::vector<G4SmartVoxelStat> fGlobVoxelStats; 0162 0163 // Flags for parallel initialization 0164 // --------------------------------- 0165 0166 G4bool fVerboseParallel = false; 0167 G4bool fParallelVoxelOptimisationUnderway = false; // It has started 0168 G4bool fParallelVoxelOptimisationFinished = false; // It is done 0169 0170 // Statistics for parallel Optimisation - used in 'verbose' mode 0171 // ------------------------------------ 0172 0173 /** Counters. */ 0174 G4double fSumVoxelTime = -9999999.9999; 0175 G4int fNumberThreadsReporting = -99999; // Must be set correctly later 0176 unsigned long fTotalNumberVolumesOptimised = -9999999; 0177 0178 /** For Wall Clock time in parallel mode ... */ 0179 G4Timer* fWallClockTimer = nullptr; 0180 G4bool fWallClockStarted = false; 0181 }; 0182 0183 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|