Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Attributes
G4VUPLSplitter< T > Class Template Reference

#include <G4VUPLSplitter.hh>

Public Member Functions

 G4VUPLSplitter ()
 
G4int CreateSubInstance ()
 
void NewSubInstances ()
 
void FreeSlave ()
 
void SlaveCopySubInstanceArray ()
 

Static Public Attributes

static G4RUN_DLL G4ThreadLocal
G4int 
slavetotalspace = 0
 
static G4RUN_DLL G4ThreadLocal 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) {}

Member Function Documentation

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

Definition at line 78 of file G4VUPLSplitter.hh.

References G4VUPLSplitter< T >::NewSubInstances(), G4VUPLSplitter< T >::offset, and G4VUPLSplitter< T >::slavetotalspace.

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

83  {
84  //One more instance
85  totalobj++;
86  //If the number of objects is larger than the available spaces,
87  //a re-allocation is needed
88  if (totalobj > slavetotalspace) { NewSubInstances(); }
89  //Since this is called by Master thread, we can remember this
90  totalspace = slavetotalspace;
91  sharedOffset = offset;
92  return (totalobj - 1);
93  }
void NewSubInstances()
static G4RUN_DLL G4ThreadLocal T * offset
static G4RUN_DLL G4ThreadLocal G4int slavetotalspace
template<class T >
void G4VUPLSplitter< T >::FreeSlave ( )
inline

Definition at line 120 of file G4VUPLSplitter.hh.

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

122  {
123  if (!offset) { return; }
124  free( offset);
125  offset = 0;
126  }
void free(void *__ptr)
Definition: hjmalloc.cc:140
static G4RUN_DLL G4ThreadLocal T * offset
template<class T >
void G4VUPLSplitter< T >::NewSubInstances ( )
inline

Definition at line 95 of file G4VUPLSplitter.hh.

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

Referenced by G4VUPLSplitter< T >::CreateSubInstance().

99  {
100  if (slavetotalspace >= totalobj) { return; }
101  //Remember current large size
102  G4int originaltotalspace = slavetotalspace;
103  //Increase its size by some value (purely arbitrary)
104  slavetotalspace = totalobj + 512;
105  //Now re-allocate new space
106  offset = (T *) realloc(offset, slavetotalspace * sizeof(T));
107  if (offset == 0)
108  {
109  G4Exception("G4VUPLSplitter::NewSubInstances()",
110  "OutOfMemory", FatalException, "Cannot malloc space!");
111  return;
112  }
113  //The newly created objects need to be initialized
114  for (G4int i = originaltotalspace; i < slavetotalspace; i++)
115  {
116  offset[i].initialize();
117  }
118  }
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4RUN_DLL G4ThreadLocal T * offset
void * realloc(void *__ptr, size_t __size)
Definition: hjmalloc.cc:103
static G4RUN_DLL G4ThreadLocal G4int slavetotalspace
template<class T >
void G4VUPLSplitter< T >::SlaveCopySubInstanceArray ( )
inline

Definition at line 128 of file G4VUPLSplitter.hh.

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

131  {
132  if ( offset ) return;
133  //Since this is called by worker threds, totalspace is some valid number > 0
134  //Remember totalspace is the number of availabel slots from master.
135  //We are sure that it has valid data
136  offset = (T *)realloc(offset,totalspace * sizeof(T));
137  if (offset == 0)
138  {
139  G4Exception("G4VUPLSplitter::SlaveCopySubInstanceArray()",
140  "OutOfMemory", FatalException, "Cannot malloc space!");
141  return;
142  }
143  //Now just copy from master thread (sharedOffset)
144  memcpy(offset,sharedOffset,totalspace*sizeof(T));
145  }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4RUN_DLL G4ThreadLocal T * offset
void * realloc(void *__ptr, size_t __size)
Definition: hjmalloc.cc:103

Field Documentation

template<class T >
G4ThreadLocal G4VUPLData * G4VUPLSplitter< G4VUPLData >::offset = 0
static
template<class T >
G4ThreadLocal G4int G4VUPLSplitter< G4VUPLData >::slavetotalspace = 0
static

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