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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 // G4GeometryManager
 27 //
 28 // Class description:
 29 //
 30 // A class responsible for high level geometrical functions, and for
 31 // high level objects in the geometry subdomain.
 32 // The class is a `singleton', with access via the static method
 33 // G4GeometryManager::GetInstance().
 34 //
 35 // Member data:
 36 //
 37 //   - fgInstance
 38 //     Ptr to the unique instance of class (per Thread)
 39 
 40 // 26.07.95, P.Kent - Initial version, including optimisation build
 41 // 12.06.24, J.Apostolakis - Added parallel optimisation in workers
 42 // --------------------------------------------------------------------
 43 #ifndef G4GEOMETRYMANAGER_HH
 44 #define G4GEOMETRYMANAGER_HH 1
 45 
 46 #include <vector>
 47 
 48 #include "G4Types.hh"
 49 #include "G4SmartVoxelStat.hh"
 50 #include "G4ios.hh"
 51 
 52 class G4VPhysicalVolume;
 53 class G4Timer;
 54 
 55 class G4GeometryManager
 56 {
 57   public:
 58   
 59     G4bool CloseGeometry(G4bool pOptimise = true, G4bool verbose = false,
 60                          G4VPhysicalVolume* vol = nullptr);
 61       // Close (`lock') the geometry: perform sanity and `completion' checks
 62       // and optionally [default=yes] build optimisation information.
 63       // Applies to just a specific subtree if a physical volume is specified.
 64 
 65     void OpenGeometry(G4VPhysicalVolume* vol = nullptr);
 66       // Open (`unlock') the geometry and remove optimisation information if
 67       // present. Applies to just a specific subtree if a physical volume is
 68       // specified.
 69 
 70     inline G4bool IsGeometryClosed() { return fIsClosed; }
 71       // Return true/false according to state of optimised geometry.
 72 
 73     void SetWorldMaximumExtent(G4double worldExtent);
 74       // Set the maximum extent of the world volume. The operation is
 75       // allowed only if NO solids have been created already.
 76 
 77     static G4GeometryManager* GetInstance();
 78       // Return ptr to singleton instance of the class, creating it if
 79       // not existing.
 80 
 81     static G4GeometryManager* GetInstanceIfExist();
 82       // Return ptr to singleton instance.
 83 
 84     void OptimiseInParallel(G4bool val = true);
 85       // Request optimisation using threads (if MT is enabled & used ).
 86   
 87     void UndertakeOptimisation();
 88       // Method that contributes to (Voxel) optimisation until all work is done.
 89       // Must be called by Worker thread initialisation - not a user callable
 90       // method.
 91 
 92     void RequestParallelOptimisation(G4bool val = true,
 93                                      G4bool verbose = true);
 94       // Detailed method for user to request parallel Optimisation
 95       // (if verbosity is required). Calling this is enough to ask for it.
 96       // It will be used if Geant4 is built with MT/tasks.
 97 
 98     void ChooseSequentialOptimisation(G4bool verbose = false);
 99       // Simple way to avoid parallel optimisation.
100   
101     G4bool IsParallelOptimisationConfigured();
102       // Check whether parallel optimisation was requested.
103     G4bool IsParallelOptimisationFinished();
104       // Report whether parallel optimisation is done.
105   
106     ~G4GeometryManager();
107       // Destructor; called by G4RunManagerKernel.
108 
109   private:
110 
111     G4GeometryManager() = default;
112       // Private constructor. Set the geometry to be open.
113 
114     G4bool BuildOptimisations(G4bool allOpt, G4bool verbose = false);  
115        // Optimise all or just multi-volumes (parameterisations, .. ).
116     void BuildOptimisations(G4bool allOpt, G4VPhysicalVolume* vol);
117        // Optimise one volume or subtree only.
118     void DeleteOptimisations();
119     void DeleteOptimisations(G4VPhysicalVolume* vol);
120   
121     void ReportVoxelStats( std::vector<G4SmartVoxelStat>& stats,
122                            G4double totalCpuTime,
123                            std::ostream &os = G4cout );
124     void ReportVoxelInfo(G4LogicalVolume * logVolume, std::ostream& os);
125    
126     void PrepareParallelOptimisation(G4bool allOpts, G4bool verbose = true);
127     void BuildOptimisationsSequential(G4bool allOpts, G4bool verbose = true);
128 
129     // Methods for parallel initialization
130     void CreateListOfVolumesToOptimise(G4bool allOpts, G4bool verbose);
131       // Build vector of relevant volumes.
132     G4LogicalVolume* ObtainVolumeToOptimise();
133 
134     void ConfigureParallelOptimisation(G4bool verbose);
135       // Prepare for parallel optimisation.
136 
137     G4int ReportWorkerIsDoneOptimising(unsigned int numVolumesOptimised);
138       // Thread-safe method for worker to report it's finished its work.
139       // It counts the number of workers that finished, and returns count.
140       // It counts the number of volumes optimised; if all workers have
141       // reported, it results in a 'Finished' state.
142   
143     void InformOptimisationIsFinished(G4bool verbose);
144       // Returns true if all workers are finished (or all work is done).
145   
146     void ResetListOfVolumesToOptimise();
147       // Resets (empties) the list of candidate volumes for optimisation.
148       // Must be called when Optimisation is finished.
149   
150     G4int CheckOptimisation();
151       // Check volumes marked to optimised are done, and report number
152       // that are missing voxel header.
153   
154     void WaitForVoxelisationFinish(G4bool verbose = false);
155       // Wait until the voxelisation is all done.
156 
157   private:
158 
159     static G4ThreadLocal G4GeometryManager* fgInstance;
160     G4bool fIsClosed = false;
161 
162     static std::vector<G4LogicalVolume*> fVolumesToOptimise;
163       // The list of volumes which threads need to optimise.
164     static std::vector<G4LogicalVolume*>::const_iterator fLogVolumeIterator;
165       // Iterator used by UndertakeOptimisation().
166 
167     static std::vector<G4SmartVoxelStat> fGlobVoxelStats;
168       // Statistics container shared by all workers
169   
170     // Flags for parallel initialization
171     // ---------------------------------
172     static G4bool fVerboseParallel;
173     static G4bool fParallelVoxelOptimisationRequested;
174       // Flag to register it was requested.
175     static G4bool fOptimiseInParallelConfigured;
176       // Not just requested, but adopted (i.e. also in MT/tasking mode).
177     static G4bool fParallelVoxelOptimisationUnderway; // It has started
178     static G4bool fParallelVoxelOptimisationFinished; // It is done
179     static G4bool fUsingExistingWorkers; // Can and will use existing MT/tasks.
180 
181     // Statistics for parallel Optimisation - used in 'verbose' mode
182     // ------------------------------------
183     static G4double fSumVoxelTime;
184     static G4int fNumberThreadsReporting;
185     static unsigned int fTotalNumberVolumesOptimised;
186       // Counters.
187   
188     // For Wall Clock time in parallel mode ...
189     //
190     static G4Timer* fWallClockTimer;   // Owned by master thread
191     static G4bool fWallClockStarted;
192 };
193 
194 #endif
195