Simulation with PsimJ2 and Java - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Simulation with PsimJ2 and Java

Description:

Title: Inter-Process Cooperation Author: ITS Last modified by: Dr. Jose Garrido Created Date: 2/21/2000 10:48:14 PM Document presentation format – PowerPoint PPT presentation

Number of Views:159
Avg rating:3.0/5.0
Slides: 20
Provided by: its95
Category:

less

Transcript and Presenter's Notes

Title: Simulation with PsimJ2 and Java


1
Simulation with PsimJ2 and Java
  • Synchronous Cooperation

2
Synchronous Cooperation
  • Is carried out by two or more processes that
    execute a joint activity for a finite time
    interval.
  • This involves the simultaneous participation of
    the processes
  • One example is the modeling of direct
    communication among processes (inter-process
    communication).

3
Master-Slave Synchronization
  • In PsimJ2, one process is chosen as the master.
    This is the dominant process during the
    cooperation interval.
  • The other processes are the slaves. These are
    modeled as passive participants during the
    interval of cooperation.
  • When the cooperation ends, all processes continue
    with their own independent activities.

4
Joint Activity
  • For two processes to cooperate
  • The master process requests a cooperation with a
    slave process to execute a joint activity.
  • The slave process requests a cooperation with a
    master process in order to execute a joint
    activity

5
Joint Activity Between Master and Slave
6
Synchronized Wait in the Cooperation
  • When the master process requests cooperation, and
    there is no slave process available, the master
    process has to wait
  • If the master process has to wait, it is
    suspended and placed on the master queue
  • When a slave process requests cooperation, and
    the master is not available, the slave process
    has to wait (suspended and placed on the slave
    queue)

7
Synchronization Object
  • The mechanism that implements this type of
    synchronization is defined in class Waitq.
  • An object of this class is used as the passive
    object necessary for the synchronization of the
    processes (active objects) involved

8
Master-Slave Cooperation
9
Waitq Class in PsimJ2
  • The cooperation mechanism is implemented in
    class Waitq
  • The synchronization mechanism is controlled by an
    object of class Waitq.
  • The relevant public members of class Waitq
  • length(), for length of the slave queue
  • lengthm(), for length of the master queue
  • qwait(), called by slave processes
  • coopt(), called by master processes

10
Defining an Object of Class Waitq
  • Declare and create an object of class Waitq
  • Waitq coop_obj
  • coop_obj new Waitq(Coop)

11
Cooperation Requests
  • Method coopt() is invoked by the master process.
    For example,
  • sl_obj (Slave ) coop_obj.coopt() // get ref
    to slave
  • The call is invoked on object coop_obj.

12
Cooperation Requests
  • Method qwait() is invoked by the slave process.
    For example,
  • coop_obj.qwait() // request cooperation

13
Deciding to Cooperate
  • As with other classes in PsimJ2, a process may
    decide not to cooperate if there are no slave
    processes in the slave queue
  • if(coop_obj.length() gt 0) // slaves available?
  • sl_obj (Slave) waitq_obj.coopt()
  • // joint activity with slave process
  • else
  • // perform some other activity

14
Model with Synchronous Communication
  • There are several sender processes
  • There are several receiver processes
  • A channel connects a receiver process to a sender
    process.
  • A sender process directly communicates to with a
    receiver process in order to transfer a message.

15
Model Implementation
  • The sender processes are objects of class Sender
  • The receiver processes are objects of class
    Receiver
  • The channels are passive objects of class Comchan
    that include a reference to class Waitq
  • The model is stored in file scomm.jar.

16
Results of a Simulation Run
  • Trace that shows sequence of events the times
    that a pair of processes communicate
  • Total wait period for each receiver process
  • Total wait period for each sender process
  • Channel utilization

17
Synchronous Communication Between Two Processes
18
Multiple Slave Processes
  • A single master process may need to cooperate
    with several slave processes simultaneously
    during cooperation interval
  • A simple solution is for the master process to
    place every slave process in a queue until the
    end of the cooperation interval

19
Java Implementation for Several Slave Processes
int slave 1 // current number of slave
processes Squeue s_queue new Squeue(Slaves)
while ( slave lt NUM_SLAVES ) slave_ref
(Slave) waitq_obj.coopt() s_queue.into(slave_r
ef) // place slave process in s_queue
slave // perform the joint activity //
dequeue and reactivate the slave processes
Write a Comment
User Comments (0)
About PowerShow.com