Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GeomSplitter< T > Class Template Reference

G4GeomSplitter is an utility class for splitting of R/W data for thread-safety from geometry classes. T is the private data from the object to be split. More...

#include <G4GeomSplitter.hh>

Public Member Functions

 G4GeomSplitter ()
T * Reallocate (G4int size)
G4int CreateSubInstance ()
void CopyMasterContents ()
void SlaveCopySubInstanceArray ()
void SlaveInitializeSubInstance ()
void SlaveReCopySubInstanceArray ()
void FreeSlave ()
T * GetOffset ()
void UseWorkArea (T *newOffset)
T * FreeWorkArea ()

Static Public Attributes

static G4GEOM_DLL G4ThreadLocal T * offset

Detailed Description

template<class T>
class G4GeomSplitter< T >

G4GeomSplitter is an utility class for splitting of R/W data for thread-safety from geometry classes. T is the private data from the object to be split.

Definition at line 50 of file G4GeomSplitter.hh.

Constructor & Destructor Documentation

◆ G4GeomSplitter()

template<class T>
G4GeomSplitter< T >::G4GeomSplitter ( )
inline

Constructor.

Definition at line 57 of file G4GeomSplitter.hh.

58 : sharedOffset(nullptr)
59 {
60 G4MUTEXINIT(mutex);
61 }
#define G4MUTEXINIT(mutex)

Member Function Documentation

◆ CopyMasterContents()

template<class T>
void G4GeomSplitter< T >::CopyMasterContents ( )
inline

Utility to copy data from master in memory.

Definition at line 96 of file G4GeomSplitter.hh.

97 {
98 G4AutoLock l(&mutex);
99 std::memcpy(offset, sharedOffset, totalspace * sizeof(T));
100 }
G4GeomSplitter is an utility class for splitting of R/W data for thread-safety from geometry classes....
static G4GEOM_DLL G4ThreadLocal T * offset

Referenced by G4GeomSplitter< G4LVData >::SlaveCopySubInstanceArray(), and G4GeomSplitter< G4LVData >::SlaveReCopySubInstanceArray().

◆ CreateSubInstance()

template<class T>
G4int G4GeomSplitter< T >::CreateSubInstance ( )
inline

Invoked by the master or work thread to create a new subinstance whenever a new split class instance is created.

Definition at line 76 of file G4GeomSplitter.hh.

77 {
78 G4AutoLock l(&mutex);
79 ++totalobj;
80 if (totalobj > totalspace)
81 {
82 offset = Reallocate(totalspace+512);
83 if (offset == nullptr)
84 {
85 G4Exception("G4GeomSPlitter::CreateSubInstance()",
86 "OutOfMemory", FatalException, "Cannot malloc space!");
87 }
88 sharedOffset = offset;
89 }
90 return (totalobj - 1);
91 }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
T * Reallocate(G4int size)

Referenced by G4PolyconeSide::G4PolyconeSide(), and G4PolyhedraSide::G4PolyhedraSide().

◆ FreeSlave()

template<class T>
void G4GeomSplitter< T >::FreeSlave ( )
inline

Invoked by all threads to free the subinstance array.

Definition at line 164 of file G4GeomSplitter.hh.

165 {
166 if (offset == nullptr) { return; }
167 std::free( offset );
168 offset = nullptr;
169 }

◆ FreeWorkArea()

template<class T>
T * G4GeomSplitter< T >::FreeWorkArea ( )
inline

Detaches the current thread from this location. The object which calls this method is responsible for it.

Definition at line 196 of file G4GeomSplitter.hh.

197 {
198 T* offsetRet = offset;
199 offset = nullptr;
200 return offsetRet;
201 }

◆ GetOffset()

template<class T>
T * G4GeomSplitter< T >::GetOffset ( )
inline

Returns a pointer to the split data.

Definition at line 176 of file G4GeomSplitter.hh.

176{ return offset; }

◆ Reallocate()

template<class T>
T * G4GeomSplitter< T >::Reallocate ( G4int size)
inline

Reallocates data for a given 'size'.

Definition at line 66 of file G4GeomSplitter.hh.

67 {
68 totalspace = size;
69 return (T *) std::realloc(offset, totalspace * sizeof(T));
70 }

Referenced by G4GeomSplitter< G4LVData >::CreateSubInstance(), G4GeomSplitter< G4LVData >::SlaveCopySubInstanceArray(), and G4GeomSplitter< G4LVData >::SlaveInitializeSubInstance().

◆ SlaveCopySubInstanceArray()

template<class T>
void G4GeomSplitter< T >::SlaveCopySubInstanceArray ( )
inline

Invoked by each worker thread to copy all the subinstance array from the master thread.

Definition at line 106 of file G4GeomSplitter.hh.

107 {
108 G4AutoLock l(&mutex);
109 if (offset != nullptr) { return; }
110 offset = Reallocate(totalspace);
111 if (offset == nullptr)
112 {
113 G4Exception("G4GeomSplitter::SlaveCopySubInstanceArray()",
114 "OutOfMemory", FatalException, "Cannot malloc space!");
115 }
116 l.unlock();
118 }
void CopyMasterContents()

◆ SlaveInitializeSubInstance()

template<class T>
void G4GeomSplitter< T >::SlaveInitializeSubInstance ( )
inline

Invoked by each worker thread to create the subinstance array and initialize each subinstance using a particular method defined by the subclass.

Definition at line 125 of file G4GeomSplitter.hh.

126 {
127 G4AutoLock l(&mutex);
128 if (offset != nullptr) { return; }
129 offset = Reallocate(totalspace);
130
131 if (offset == nullptr)
132 {
133 G4Exception("G4GeomSplitter::SlaveInitializeSubInstance()",
134 "OutOfMemory", FatalException, "Cannot malloc space!");
135 }
136
137 for (G4int i=0 ; i<totalspace; ++i)
138 {
139 offset[i].initialize();
140 }
141 }

Referenced by G4GeomSplitter< G4LVData >::SlaveReCopySubInstanceArray().

◆ SlaveReCopySubInstanceArray()

template<class T>
void G4GeomSplitter< T >::SlaveReCopySubInstanceArray ( )
inline

Invoked by each worker thread at start of a run (2nd or later) to copy again all the subinstance array from the master thread. To cope with user's changes in Geometry - e.g. change of material in a volume.

Definition at line 149 of file G4GeomSplitter.hh.

150 {
151 if (offset == nullptr)
152 {
154 G4Exception("G4GeomSPlitter::SlaveReCopySubInstance()",
155 "MissingInitialisation", JustWarning,
156 "Must be called after Initialisation or first Copy.");
157 }
159 }
void SlaveInitializeSubInstance()

◆ UseWorkArea()

template<class T>
void G4GeomSplitter< T >::UseWorkArea ( T * newOffset)
inline

Uses recycled work area - which was created previously.

Definition at line 181 of file G4GeomSplitter.hh.

182 {
183 if( (offset!=nullptr) && (offset!=newOffset) )
184 {
185 G4Exception("G4GeomSplitter::UseWorkspace()",
186 "TwoWorkspaces", FatalException,
187 "Thread already has workspace - cannot use another.");
188 }
190 }

Member Data Documentation

◆ offset

template<class T>
G4GEOM_DLL G4ThreadLocal T* G4GeomSplitter< T >::offset
static

Definition at line 205 of file G4GeomSplitter.hh.


The documentation for this class was generated from the following file: