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

#include <G4VUPLSplitter.hh>

Public Member Functions

 G4VUPLSplitter ()
 
G4int CreateSubInstance ()
 
void NewSubInstances ()
 
void FreeWorker ()
 
T * GetOffset ()
 
void UseWorkArea (T *newOffset)
 
T * FreeWorkArea ()
 
void WorkerCopySubInstanceArray ()
 

Public Attributes

G4RUN_DLL G4ThreadLocalStatic G4int workertotalspace = 0
 
G4RUN_DLL G4ThreadLocalStatic T * offset = 0
 

Detailed Description

template<class T>
class G4VUPLSplitter< T >

Definition at line 71 of file G4VUPLSplitter.hh.

Constructor & Destructor Documentation

◆ G4VUPLSplitter()

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

Definition at line 74 of file G4VUPLSplitter.hh.

75 : totalobj(0)
76 , totalspace(0)
77 , sharedOffset(0)
78 {
80 }
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:87

Member Function Documentation

◆ CreateSubInstance()

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

Definition at line 82 of file G4VUPLSplitter.hh.

87 {
88 G4AutoLock l(&mutex);
89 // One more instance
90 totalobj++;
91 // If the number of objects is larger than the available spaces,
92 // a re-allocation is needed
93 if(totalobj > workertotalspace)
94 {
95 l.unlock();
97 l.lock();
98 }
99 // Since this is called by Master thread, we can remember this
100 totalspace = workertotalspace;
101 sharedOffset = offset;
102 return (totalobj - 1);
103 }
G4RUN_DLL G4ThreadLocalStatic G4int workertotalspace
G4RUN_DLL G4ThreadLocalStatic T * offset

Referenced by G4VModularPhysicsList::G4VModularPhysicsList(), G4VPhysicsConstructor::G4VPhysicsConstructor(), G4VUserPhysicsList::G4VUserPhysicsList(), and G4VModularPhysicsList::operator=().

◆ FreeWorkArea()

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

Definition at line 161 of file G4VUPLSplitter.hh.

162 {
163 // Detach this thread from this Location
164 // The object which calls this method is responsible for it.
165 //
166 T* offsetRet = offset;
167
168 offset = 0;
169
170 return offsetRet;
171 }

◆ FreeWorker()

template<class T >
void G4VUPLSplitter< T >::FreeWorker ( )
inline

Definition at line 134 of file G4VUPLSplitter.hh.

136 {
137 if(!offset)
138 {
139 return;
140 }
141 free(offset);
142 offset = 0;
143 }

Referenced by G4PhysicsListWorkspace::DestroyWorkspace().

◆ GetOffset()

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

Definition at line 145 of file G4VUPLSplitter.hh.

145{ return offset; }

Referenced by G4PhysicsListWorkspace::G4PhysicsListWorkspace().

◆ NewSubInstances()

template<class T >
void G4VUPLSplitter< T >::NewSubInstances ( )
inline

Definition at line 105 of file G4VUPLSplitter.hh.

109 {
110 G4AutoLock l(&mutex);
111 if(workertotalspace >= totalobj)
112 {
113 return;
114 }
115 // Remember current large size
116 G4int originaltotalspace = workertotalspace;
117 // Increase its size by some value (purely arbitrary)
118 workertotalspace = totalobj + 512;
119 // Now re-allocate new space
120 offset = (T*) realloc(offset, workertotalspace * sizeof(T));
121 if(offset == 0)
122 {
123 G4Exception("G4VUPLSplitter::NewSubInstances()", "OutOfMemory",
124 FatalException, "Cannot malloc space!");
125 return;
126 }
127 // The newly created objects need to be initialized
128 for(G4int i = originaltotalspace; i < workertotalspace; i++)
129 {
130 offset[i].initialize();
131 }
132 }
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
int G4int
Definition: G4Types.hh:85

Referenced by G4VUPLSplitter< T >::CreateSubInstance(), and G4PhysicsListWorkspace::InitialiseWorkspace().

◆ UseWorkArea()

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

Definition at line 147 of file G4VUPLSplitter.hh.

148 {
149 // Use recycled work area - which was created previously
150 if(offset && offset != newOffset)
151 {
152 G4Exception("G4VUPLSplitter::UseWorkspace()", "TwoWorkspaces",
154 "Thread already has workspace - cannot use another.");
155 }
156 offset = newOffset;
157 // totalobj= numObjects;
158 // totalspace= numSpace;
159 }

Referenced by G4PhysicsListWorkspace::ReleaseWorkspace(), and G4PhysicsListWorkspace::UseWorkspace().

◆ WorkerCopySubInstanceArray()

template<class T >
void G4VUPLSplitter< T >::WorkerCopySubInstanceArray ( )
inline

Definition at line 173 of file G4VUPLSplitter.hh.

176 {
177 if(offset)
178 return;
179 // Since this is called by worker threds, totalspace is some valid number >
180 // 0 Remember totalspace is the number of availabel slots from master. We
181 // are sure that it has valid data
182 G4AutoLock l(&mutex);
183 offset = (T*) realloc(offset, totalspace * sizeof(T));
184 if(offset == 0)
185 {
186 G4Exception("G4VUPLSplitter::WorkerCopySubInstanceArray()", "OutOfMemory",
187 FatalException, "Cannot malloc space!");
188 return;
189 }
190 // Now just copy from master thread (sharedOffset)
191 memcpy(offset, sharedOffset, totalspace * sizeof(T));
192 }

Referenced by G4PhysicsListWorkspace::InitialiseWorkspace().

Member Data Documentation

◆ offset

◆ workertotalspace

template<typename T >
G4ThreadLocal G4int G4VUPLSplitter< T >::workertotalspace = 0

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