Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 72 of file G4VUPLSplitter.hh.

Constructor & Destructor Documentation

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

Definition at line 76 of file G4VUPLSplitter.hh.

76  : totalobj(0),totalspace(0),sharedOffset(0)
77  {
79  }
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:177

Member Function Documentation

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

Definition at line 81 of file G4VUPLSplitter.hh.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 154 of file G4VUPLSplitter.hh.

155  {
156  // Detach this thread from this Location
157  // The object which calls this method is responsible for it.
158  //
159  T* offsetRet= offset;
160 
161  offset= 0;
162 
163  return offsetRet;
164  }
G4RUN_DLL G4ThreadLocalStatic T * offset
template<class T >
void G4VUPLSplitter< T >::FreeWorker ( )
inline

Definition at line 130 of file G4VUPLSplitter.hh.

132  {
133  if (!offset) { return; }
134  free( offset);
135  offset = 0;
136  }
G4RUN_DLL G4ThreadLocalStatic T * offset

Here is the caller graph for this function:

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

Definition at line 138 of file G4VUPLSplitter.hh.

138 { return offset; }
G4RUN_DLL G4ThreadLocalStatic T * offset

Here is the caller graph for this function:

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

Definition at line 104 of file G4VUPLSplitter.hh.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 140 of file G4VUPLSplitter.hh.

141  {
142  // Use recycled work area - which was created previously
143  if( offset && offset!=newOffset )
144  {
145  G4Exception("G4VUPLSplitter::UseWorkspace()",
146  "TwoWorkspaces", FatalException,
147  "Thread already has workspace - cannot use another.");
148  }
149  offset= newOffset;
150  // totalobj= numObjects;
151  // totalspace= numSpace;
152  }
G4RUN_DLL G4ThreadLocalStatic T * offset
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 166 of file G4VUPLSplitter.hh.

169  {
170  if ( offset ) return;
171  //Since this is called by worker threds, totalspace is some valid number > 0
172  //Remember totalspace is the number of availabel slots from master.
173  //We are sure that it has valid data
174  G4AutoLock l(&mutex);
175  offset = (T *)realloc(offset,totalspace * sizeof(T));
176  if (offset == 0)
177  {
178  G4Exception("G4VUPLSplitter::WorkerCopySubInstanceArray()",
179  "OutOfMemory", FatalException, "Cannot malloc space!");
180  return;
181  }
182  //Now just copy from master thread (sharedOffset)
183  memcpy(offset,sharedOffset,totalspace*sizeof(T));
184  }
G4RUN_DLL G4ThreadLocalStatic T * offset
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

template<class T >
G4ThreadLocal T * G4VUPLSplitter< T >::offset =0

Definition at line 188 of file G4VUPLSplitter.hh.

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

Definition at line 187 of file G4VUPLSplitter.hh.


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