Appendix E: Parallel simulation notes (PCD++)
DEVS:
Discrete event simulation system. Discrete event system where time advances using a continuous time base.
To Start (PCD++):
./mpirun –np n ./cd++ [-ehlmotdvbfrspqw]
where, n = number of computers used
Running CD++:
1) course website => cell devs visualization applet samples => queue – download it in the same file we unzipped cd++_exes_linux.zip
2) cd++/sample/queue
ð highlight all files and change the read=>write/ Owner=>write
3) delete queue.log & queue.out
4) click demo.bat
ð vi demo.bat
ð always open terminal file add ../../simu at top of file
5) terminal => ./simu –h
Command Line Options:
-efilename: to use external events
-lfilename: all messages received by each DEVS processor will be logged
· -l: all log activities will be sent to standard output
· filename.XXX: one log file will be created for each DEVS processor. XXX is a number
-L[I*@XYDS]: allows to define which messages will be logged
I: initialization messages
*: (*,t) internal messages
@: (@,t) collect messages
X: (q,t) external messages
D: (done,t) Done messages
Y: (y,t) output messages
S: All sent messages
-mfilename: indicates the name of the file that contains the model definition
-pfilename: indicate partition file used to specify the machine where each atomic model will run on. (only for PCD++)
-ofilename: output file name used to store output generated
-o: get results on standard output
-t: set simulation finish set. Otherwise stops when no events. Format: HH:MM:SS:MS
-Dfilename: one file for each file LP will be used. This file lists all identification of DEVS processors running.
-d: defines tolerance
-pfilename: shows addition in for when parsing a cells local transition rules.
-vfilename: enable verbose evaluation. Each rule evaluated, the result will be shown.
-b: when the parameter set, ignore macros
-r: to check for existence of multiple valid rules at runtime
-s: show finish time in stderr
-qvalue: set value for quantum
-w: allows to set the wide & precision of real values of output. E.g. 10 characters, 3 decimal digits=> -w10-3
Atomic models:
Devs –formalism:
· to tell CD++ about new atomic definition, the model must be registered in ParallelMainSimulator.registerNewAtomics() function
· to access current state => ModelState *getCurrentState(), the pointer returned should be casted to proper type
Structure of Model files (.ma)
[myGroup] => name of group
my1: value
my2: value => parameters of group
Atomic Class:
holdIn(state, VTime): ta(s) function of DEVS formalism
passivate: external event is received
sendOutput(VTime, port, BasicMsgValue): sends output message through the port. Time set to current time.
sendOutput(VTime, port, value): for backward compatibility, sends real port
NextChenge(): returns remaining time for next internal transition (sigma)
lastChange(): returns time Model last changed
state(): returns the current model phase
getParameter(modelName, parameterName): returns parameters used defined in .ma file. ModelName is an instance
Inherited Atomic Class Methods;
· virtual Model&initFunction(): invoked at the beginning of the simulation, all initialization takes place here
· virtual Model & externalFunction( const MessageBag & )/ virtual Model & externalFunction( const ExternalMessage & ): these invoked when external events arrive from port (dext).
· virtual Model & internalFunction( const InternalMessage & ): corresponds to dint
· virtual Model & outputFunction( const InternalMessage & ): this called before dint. Sends all the output events
· virtual Model &confluentFunction (const InternalMessage, const MessageBag &): corresponds to dconf function of devs.
*new structure for output => new class that derives BasicMsgValue has to be made
BasicMsgValue Class:
· virtual int ValueSize() const: returns the size of class
· virtual string aString(): returns string, used in log file to log the value sent or received
· virtual BasicMsgValue *clone(): returns the pointer to a new copy of the message value. The function that receives the pointer will own it.
· BasicMsgValue( const BasicMsgValue &): copy constructor
Coupled Models:
Formal Specification:
GEN = < S, X, Y, dint, dext, l, ta >
- Internal couplings: how the models are interconnected internally (defined)
EIC: external input coupling
EOC: external output coupling
IC: internal coupling
· Components: model_name [@abc] [model2] [@abc2Class]….etc.
This component that make the coupled model. For atomic model component, instance and class name specified. For coupled model component, model name specified.
· Out: protname1, portname2 => enumerates mode output ports
· In: potname1, portname2 => enumerates input ports
· Link: source_port[@Model] destination_port[@Model] => define link between components and the coupled model.
Converting CD++ models to PCD++:
A. In the header file:
Add the following lines of code to your header file:
- #include “atomicstate.h”
- class modelNameState: public AtomicState {
public:
modelNameState() { };
virtual ~modelNameState() {};
modelNameState& operator =( modelNameState& thisState);
void copyState(modelNameState *);
};
- In the protected section of the atomic class add:
ModelState *allocateState() {
Return new modelNameState;
}
If any of the private variables are declared in the AtomicState class instead of the Atomic class, getters and setters are required. Example format of a getter:
inline variableType modelName::variableName() const {
return( (modelNameState *) getCurrentState() )-> variableName;
}
B. In the source code file:
Add the following lines of code to your cpp file:
- #include “parsimu.h”
- modelNameState &modelNameState:: operator =( modelNameState &thisState) {
(AtomicState &) *this = (AtmoicState &) thisState;
//copy all private variables example:
this->variable = thisState.variable;
return *this;
}
- void modelNameState::copyState(modelNameState *rhs) {
*this = *(( modelNameState *)rhs);
}
All holdIn functions should have the active state defined through AtomicState
i.e. holdIn(AtomicState::active, preparationTime);