#include <PsMultiThreadedPvmController.h>
Inheritance diagram for PsMultiThreadedPvmController:


Public Methods | |
| PsMultiThreadedPvmController (PsObjectDescriptor &initialObjects, const PsDate &initialDate, int argc, char *argv[]) | |
| constructor | |
| virtual | ~PsMultiThreadedPvmController () |
| destructor | |
| virtual PsnScheduler * | createScheduler () |
| redefine to create a multihtreaded scheduler | |
| virtual void | run () |
| redefine run to install a local memory manager | |
| virtual PsSimulatedObject * | getPointerToSimulatedObjectNamed (const PsName &objectName) |
| get a pointer to a simulation object. | |
| virtual void | computeNextSimulationStep () |
| redefine to update the _pointerToObjectCache with the values of the _addToCache | |
Protected Attributes | |
| unsigned int | _numberOfThreads |
| the number of threads created | |
| PsnMutexLock | _dataLock |
| the lock to access _creatingObject and _creatingThread | |
| PsnCondition | _accessCondition |
| the boolean used to avoid recursive creation : should be accessed only protected | |
| pthread_t | _accessingThread |
| the thread id of the access lock | |
| map< PsName, PsSimulatedObject * > | _pointerToObjectCache |
| a cache that can be accessed lock free for getPointerToSimulatedObjectNamed | |
| map< PsName, PsSimulatedObject * > | _addToCache |
| a cache of objects that need to be added to the cache | |
The number of threads used by this controller is controlled by the NumberOfThreads scheduling parameter.
Definition at line 37 of file PsMultiThreadedPvmController.h.
|
||||||||||||||||||||
|
constructor
Definition at line 30 of file PsMultiThreadedPvmController.cxx. References _accessingThread, _numberOfThreads, PsConfigurationParameterDescriptor::getAssociatedString(), PsSimulatedObject::getObjectDescriptor(), PsObjectDescriptor::getSchedulingParameters(), PsMultipleConfigurationParameter::getSubDescriptorByName(), and PsDate.
00033 : 00034 PsPvmController(initialObjects, 00035 initialDate, 00036 argc, 00037 argv), 00038 _numberOfThreads (2), 00039 _accessingThread ( 0 ) 00040 { 00041 assert ( _accessingThread != pthread_self() ) ; 00042 00043 if ( getObjectDescriptor().getSchedulingParameters() != NULL ) 00044 { 00045 const PsConfigurationParameterDescriptor * param = getObjectDescriptor().getSchedulingParameters()->getSubDescriptorByName("NumberOfThreads") ; 00046 if (param != NULL ) 00047 { 00048 // if the sheduling parameter named NumberOfThreads if a uniqueConfigurationParameter, then all processes should be spawned with the same number of threads, 00049 //otherwise read the number of threads from the appriate subdescriptor (the one with the name of the process, or default 00050 const PsMultipleConfigurationParameter * complexParam ; 00051 complexParam = dynamic_cast< const PsMultipleConfigurationParameter *> (param) ; 00052 if ( complexParam != NULL ) 00053 { 00054 // a multithreading value could by defined for each process 00055 00056 //find the value for this process 00057 param = complexParam->getSubDescriptorByName (getObjectDescriptor().getProcess().getCString() ) ; 00058 00059 if (param == NULL) 00060 { //no value has been defined for this process 00061 param = complexParam->getSubDescriptorByName ("default") ; 00062 00063 if (param == NULL) 00064 {//no default value has been defined 00065 _numberOfThreads = 2 ; 00066 } 00067 else 00068 {// a default value has been defined 00069 _numberOfThreads = atoi (param->getAssociatedString().c_str() ) ; 00070 } 00071 } 00072 else 00073 {// a value has been defined for this process 00074 _numberOfThreads = atoi (param->getAssociatedString().c_str() ) ; 00075 } 00076 } 00077 else 00078 {// all processes use the same number of threads 00079 _numberOfThreads = atoi (param->getAssociatedString().c_str() ) ; 00080 } 00081 } 00082 } 00083 00084 } |
|
|
destructor
Definition at line 86 of file PsMultiThreadedPvmController.cxx.
00086 {
00087
00088 }
|
|
|
redefine to update the _pointerToObjectCache with the values of the _addToCache
Reimplemented from PsPvmController. Definition at line 180 of file PsMultiThreadedPvmController.cxx. References _addToCache, _pointerToObjectCache, map< PsName, PsSimulatedObject * >::begin(), map< PsName, PsSimulatedObject * >::clear(), PsPvmController::computeNextSimulationStep(), map< PsName, PsSimulatedObject * >::end(), and map< PsName, PsSimulatedObject * >::insert().
00181 {
00182 _pointerToObjectCache.insert (_addToCache.begin() , _addToCache.end() ) ;
00183 _addToCache.clear() ;
00184 PsPvmController::computeNextSimulationStep () ;
00185 }
|
|
|
redefine to create a multihtreaded scheduler
Reimplemented from PsController. Definition at line 90 of file PsMultiThreadedPvmController.cxx. References PsController::_nbStepsByCycle, and _numberOfThreads.
00091 {
00092 return new PsnMultiThreadedScheduler( _nbStepsByCycle , _numberOfThreads, true ) ;
00093 }
|
|
|
get a pointer to a simulation object. Redefined from PsPvmController, to protect sahred data structures
Reimplemented from PsDistributedController. Definition at line 125 of file PsMultiThreadedPvmController.cxx. References _accessCondition, _accessingThread, _addToCache, _dataLock, _pointerToObjectCache, map< PsName, PsSimulatedObject * >::end(), map< PsName, PsSimulatedObject * >::find(), PsDistributedController::getPointerToSimulatedObjectNamed(), map< PsName, PsSimulatedObject * >::insert(), make_pair(), PsnMutexLock::protect(), PsnCondition::signalChange(), PsnMutexLock::unprotect(), and PsnCondition::waitForChange().
00126 {
00127
00128 PsSimulatedObject * result ;
00129
00130 map<PsName, PsSimulatedObject * >::iterator i = _pointerToObjectCache.find ( objectName ) ;
00131 if ( i != _pointerToObjectCache.end() )
00132 {
00133 result = i->second ;
00134 }
00135 else
00136 {
00137 _dataLock.protect() ;
00138 i = _addToCache.find (objectName) ;
00139 if ( i != _addToCache.end() )
00140 {
00141 result = i->second ;
00142 _dataLock.unprotect() ;
00143 }
00144 else
00145 {
00146 if ( _accessingThread == pthread_self() )
00147 {
00148 _dataLock.unprotect() ;
00149 result = PsPvmController::getPointerToSimulatedObjectNamed ( objectName ) ;
00150 }
00151 else if ( _accessingThread == 0 )
00152 {
00153 _accessingThread = pthread_self() ;
00154 _dataLock.unprotect() ;
00155
00156 result = PsPvmController::getPointerToSimulatedObjectNamed ( objectName ) ;
00157
00158 _dataLock.protect() ;
00159 _accessingThread = 0 ;
00160 _dataLock.unprotect() ;
00161 _accessCondition.signalChange() ;
00162 }
00163 else
00164 { //other thread is accessing: wait
00165 _accessCondition.waitForChange ( _dataLock ) ;
00166
00167 _dataLock.unprotect() ;
00168
00169 result = getPointerToSimulatedObjectNamed ( objectName ) ;
00170 }
00171 _dataLock.protect() ;
00172 _addToCache.insert ( make_pair(objectName,result) ) ;
00173 _dataLock.unprotect() ;
00174 }
00175 }
00176 return result ;
00177 }
|
|
|
redefine run to install a local memory manager
Reimplemented from PsPvmController. Definition at line 95 of file PsMultiThreadedPvmController.cxx. References HeapStackTop::getSystemMemoryManager(), and PsPvmController::run().
00096 {
00097 PsnMemoryManager * currentMemoryManager = HeapStackTop::getSystemMemoryManager() ;
00098
00099 assert ( currentMemoryManager != 0 ) ;
00100
00101 // commented out because a thread memory manager doesn't seem performant : confirmed : our implementation performs very poorly compared to the malloc implementation on the demarshalling phase
00102
00103 //size_t initialAllocatatedMemory = 1024 * 1024 ;
00104
00105 //void * startMemory = currentMemoryManager->allocateSizeRemembered ( initialAllocatatedMemory ) ;
00106
00107 //PsnDescriptorMemoryManager * descriptorMemoryManager = new PsnDescriptorMemoryManager ( *currentMemoryManager ) ;
00108
00109 //descriptorMemoryManager->init() ;
00110
00111 //PsnThreadMemoryManager * memoryManagerForThisThread ;
00112
00113 //memoryManagerForThisThread = new PsnThreadMemoryManager ( startMemory,
00114 // initialAllocatatedMemory,
00115 // *currentMemoryManager,
00116 // *descriptorMemoryManager ) ;
00117 //memoryManagerForThisThread -> init() ;
00118
00119 //HeapStackTop allocationContextForThisThread ( memoryManagerForThisThread ) ;
00120
00121 PsPvmController::run() ;
00122 }
|
|
|
the boolean used to avoid recursive creation : should be accessed only protected
Definition at line 75 of file PsMultiThreadedPvmController.h. Referenced by getPointerToSimulatedObjectNamed(). |
|
|
the thread id of the access lock
Definition at line 78 of file PsMultiThreadedPvmController.h. Referenced by getPointerToSimulatedObjectNamed(), and PsMultiThreadedPvmController(). |
|
|
a cache of objects that need to be added to the cache
Definition at line 84 of file PsMultiThreadedPvmController.h. Referenced by computeNextSimulationStep(), and getPointerToSimulatedObjectNamed(). |
|
|
the lock to access _creatingObject and _creatingThread
Definition at line 72 of file PsMultiThreadedPvmController.h. Referenced by getPointerToSimulatedObjectNamed(). |
|
|
the number of threads created
Definition at line 69 of file PsMultiThreadedPvmController.h. Referenced by createScheduler(), and PsMultiThreadedPvmController(). |
|
|
a cache that can be accessed lock free for getPointerToSimulatedObjectNamed
Definition at line 81 of file PsMultiThreadedPvmController.h. Referenced by computeNextSimulationStep(), and getPointerToSimulatedObjectNamed(). |
| Documentation generated on Mon Nov 25 15:26:14 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |