Geant4 11.2.2
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 65 of file G4VUPLSplitter.hh.

#define G4MUTEXINIT(mutex)

Member Function Documentation

◆ CreateSubInstance()

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

Definition at line 71 of file G4VUPLSplitter.hh.

72 {
73 G4AutoLock l(&mutex);
74 // One more instance
75 ++totalobj;
76 // If the number of objects is larger than the available spaces,
77 // a re-allocation is needed
78 if (totalobj > workertotalspace) {
79 l.unlock();
81 l.lock();
82 }
83 // Since this is called by Master thread, we can remember this
84 totalspace = workertotalspace;
85 sharedOffset = offset;
86 return (totalobj - 1);
87 }
G4RUN_DLL G4ThreadLocalStatic G4int workertotalspace
G4RUN_DLL G4ThreadLocalStatic T * offset

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

◆ FreeWorkArea()

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

Definition at line 137 of file G4VUPLSplitter.hh.

138 {
139 // Detach this thread from this Location
140 // The object which calls this method is responsible for it.
141 //
142 T* offsetRet = offset;
143 offset = nullptr;
144
145 return offsetRet;
146 }

◆ FreeWorker()

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

Definition at line 116 of file G4VUPLSplitter.hh.

117 {
118 if (offset == nullptr) {
119 return;
120 }
121 free(offset);
122 offset = nullptr;
123 }

Referenced by G4PhysicsListWorkspace::DestroyWorkspace().

◆ GetOffset()

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

Definition at line 125 of file G4VUPLSplitter.hh.

125{ return offset; }

Referenced by G4PhysicsListWorkspace::G4PhysicsListWorkspace().

◆ NewSubInstances()

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

Definition at line 92 of file G4VUPLSplitter.hh.

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

128 {
129 // Use recycled work area - which was created previously
130 if (offset != nullptr && offset != newOffset) {
131 G4Exception("G4VUPLSplitter::UseWorkspace()", "TwoWorkspaces", FatalException,
132 "Thread already has workspace - cannot use another.");
133 }
134 offset = newOffset;
135 }

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

◆ WorkerCopySubInstanceArray()

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

Definition at line 150 of file G4VUPLSplitter.hh.

151 {
152 if (offset != nullptr) return;
153
154 // Since this is called by worker threds, totalspace is some valid
155 // number > 0. Remember totalspace is the number of available slots
156 // from master. We are sure that it has valid data
157 G4AutoLock l(&mutex);
158 offset = (T*)realloc(offset, totalspace * sizeof(T));
159 if (offset == nullptr) {
160 G4Exception("G4VUPLSplitter::WorkerCopySubInstanceArray()", "OutOfMemory", FatalException,
161 "Cannot malloc space!");
162 return;
163 }
164 // Now just copy from master thread (sharedOffset)
165 std::memcpy(offset, sharedOffset, totalspace * sizeof(T));
166 }

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: