Geant4-11
Public Member Functions | Data Fields | Private Attributes
G4VUPLSplitter< T > Class Template Reference

#include <G4VUPLSplitter.hh>

Public Member Functions

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

Data Fields

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

Private Attributes

G4Mutex mutex
 
T * sharedOffset = nullptr
 
G4int totalobj = 0
 
G4int totalspace = 0
 

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

References G4MUTEXINIT.

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
83 {
84 l.unlock();
86 l.lock();
87 }
88 // Since this is called by Master thread, we can remember this
91 return (totalobj - 1);
92 }
void NewSubInstances()
G4RUN_DLL G4ThreadLocalStatic G4int workertotalspace
G4RUN_DLL G4ThreadLocalStatic T * offset

References G4TemplateAutoLock< _Mutex_t >::lock(), G4VUPLSplitter< T >::NewSubInstances(), G4VUPLSplitter< T >::offset, G4VUPLSplitter< T >::sharedOffset, G4VUPLSplitter< T >::totalobj, G4VUPLSplitter< T >::totalspace, G4TemplateAutoLock< _Mutex_t >::unlock(), and G4VUPLSplitter< T >::workertotalspace.

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 }

References G4VUPLSplitter< T >::offset.

◆ 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 }

References free, and G4VUPLSplitter< T >::offset.

Referenced by G4PhysicsListWorkspace::DestroyWorkspace().

◆ GetOffset()

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

Definition at line 134 of file G4VUPLSplitter.hh.

134{ return offset; }

References G4VUPLSplitter< T >::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);
101 {
102 return;
103 }
104 // Remember current large size
105 G4int originaltotalspace = workertotalspace;
106 // Increase its size by some value (purely arbitrary)
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:35
int G4int
Definition: G4Types.hh:85

References FatalException, G4Exception(), G4VUPLSplitter< T >::offset, G4VUPLSplitter< T >::totalobj, and G4VUPLSplitter< T >::workertotalspace.

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 }

References FatalException, G4Exception(), and G4VUPLSplitter< T >::offset.

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 }

References FatalException, G4Exception(), G4VUPLSplitter< T >::offset, G4VUPLSplitter< T >::sharedOffset, and G4VUPLSplitter< T >::totalspace.

Referenced by G4PhysicsListWorkspace::InitialiseWorkspace().

Field Documentation

◆ mutex

template<class T >
G4Mutex G4VUPLSplitter< T >::mutex
private

Definition at line 195 of file G4VUPLSplitter.hh.

◆ offset

template<typename T >
G4ThreadLocal T * G4VUPLSplitter< T >::offset = nullptr

◆ sharedOffset

template<class T >
T* G4VUPLSplitter< T >::sharedOffset = nullptr
private

◆ totalobj

template<class T >
G4int G4VUPLSplitter< T >::totalobj = 0
private

◆ totalspace

template<class T >
G4int G4VUPLSplitter< T >::totalspace = 0
private

◆ workertotalspace

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

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