Geant4 11.1.1
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 = nullptr
 

Detailed Description

template<class T>
class G4VUPLSplitter< T >

Definition at line 62 of file G4VUPLSplitter.hh.

Constructor & Destructor Documentation

◆ G4VUPLSplitter()

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

Definition at line 66 of file G4VUPLSplitter.hh.

67 {
69 }
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:87

Member Function Documentation

◆ CreateSubInstance()

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

Definition at line 71 of file G4VUPLSplitter.hh.

76 {
77 G4AutoLock l(&mutex);
78 // One more instance
79 ++totalobj;
80 // If the number of objects is larger than the available spaces,
81 // a re-allocation is needed
82 if(totalobj > workertotalspace)
83 {
84 l.unlock();
86 l.lock();
87 }
88 // Since this is called by Master thread, we can remember this
89 totalspace = workertotalspace;
90 sharedOffset = offset;
91 return (totalobj - 1);
92 }
void NewSubInstances()
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 150 of file G4VUPLSplitter.hh.

151 {
152 // Detach this thread from this Location
153 // The object which calls this method is responsible for it.
154 //
155 T* offsetRet = offset;
156 offset = nullptr;
157
158 return offsetRet;
159 }

◆ FreeWorker()

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

Definition at line 123 of file G4VUPLSplitter.hh.

125 {
126 if(offset == nullptr)
127 {
128 return;
129 }
130 free(offset);
131 offset = nullptr;
132 }

Referenced by G4PhysicsListWorkspace::DestroyWorkspace().

◆ GetOffset()

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

Definition at line 134 of file G4VUPLSplitter.hh.

134{ return offset; }

Referenced by G4PhysicsListWorkspace::G4PhysicsListWorkspace().

◆ NewSubInstances()

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

Definition at line 94 of file G4VUPLSplitter.hh.

98 {
99 G4AutoLock l(&mutex);
100 if(workertotalspace >= totalobj)
101 {
102 return;
103 }
104 // Remember current large size
105 G4int originaltotalspace = workertotalspace;
106 // Increase its size by some value (purely arbitrary)
107 workertotalspace = totalobj + 512;
108 // Now re-allocate new space
109 offset = (T*) realloc(offset, workertotalspace * sizeof(T));
110 if(offset == nullptr)
111 {
112 G4Exception("G4VUPLSplitter::NewSubInstances()", "OutOfMemory",
113 FatalException, "Cannot malloc space!");
114 return;
115 }
116 // The newly created objects need to be initialized
117 for(G4int i = originaltotalspace; i < workertotalspace; ++i)
118 {
119 offset[i].initialize();
120 }
121 }
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
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 136 of file G4VUPLSplitter.hh.

137 {
138 // Use recycled work area - which was created previously
139 if(offset != nullptr && offset != newOffset)
140 {
141 G4Exception("G4VUPLSplitter::UseWorkspace()", "TwoWorkspaces",
143 "Thread already has workspace - cannot use another.");
144 }
145 offset = newOffset;
146 // totalobj= numObjects;
147 // totalspace= numSpace;
148 }

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

◆ WorkerCopySubInstanceArray()

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

Definition at line 161 of file G4VUPLSplitter.hh.

164 {
165 if(offset != nullptr)
166 return;
167
168 // Since this is called by worker threds, totalspace is some valid
169 // number > 0. Remember totalspace is the number of available slots
170 // from master. We are sure that it has valid data
171 G4AutoLock l(&mutex);
172 offset = (T*) realloc(offset, totalspace * sizeof(T));
173 if(offset == nullptr)
174 {
175 G4Exception("G4VUPLSplitter::WorkerCopySubInstanceArray()",
176 "OutOfMemory", FatalException, "Cannot malloc space!");
177 return;
178 }
179 // Now just copy from master thread (sharedOffset)
180 std::memcpy(offset, sharedOffset, totalspace * sizeof(T));
181 }

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: