communication among tasks in advanced system architecture
1. ADVANCED SYSTEM ARCHITECTURE
Parallel Programming In The Parallel Virtual
Machine
--Communication Among Tasks
Presented By
J.Roslin vimala
Msc(cs) II year
2. COMMUNICATION AMONG TASKS:
Communication among PVM tasks is performed
using the message passing approach,which is
achieved using a library of routines and a daemon.
During program execution, the user program
communicates with the PVM daemon through the
library routines.
The daemon, which runs on each machine in the
PVM environment, determines the destination of
each machine.
3. If the message is for a task on the local
machine,
Message send
daemon routes
message
If the message for a task on a remote host,
Message Send
remote daemon routes
Message
Sender Local Machine Task
Daemon
Daemon
Receiving Task
4. OPERATIONS:
Send
Receive
These two operations are heart of this
communication scheme.
Generally Asynchronous.
A message can be sent to one or more
destinations by calling one of the PVM send
functions.
A message can be received by calling either
a blocking or nonblocking receive function.
6. DESCRIPTION OF ABOVE DIAGRAM
The arrow from the user applications to the daemons
represent communication calls.
The arrows from the daemons to the user applications
represent the return from the API.
Point-1: A sending process issues a send command.
Point-2: The message is transferred to the daemon.
Point-3: daemon will transmit the message on the
physical link some time after returning control to the
user application.
7. Continued…
Point-4: The control is return to the user application.
Point-5: At some other time, either before or after send
command, the receiving task issues a receive command.
Point-6: In the case of a blocking receive, the receiving
task blocks on the daemon waiting for a message.
Point-7,8:
i) After the message arrives, control is returned to the
user application.
ii) In the case of nonblocking receive , control is
returned to the user application immediately (points7&8)
Even if the message has not yet arrived.
8. A sender task can send the message to one or more receivers
in three steps as follows:
*A send buffer must be initialized.(Message Buffer)
*The message is packed into this buffer.(Data Packing)
*The completed message is sent to its destination(s ).
(Sending a Message)
Receiving a message is done in two steps as follows:
*The message is received.(Receiving a Message)
*The message items are unpacked from the receive
buffer.(Data Unpacking)
9. 1)MESSAGE BUFFERS:
Before packing a message for transmission, a send buffer
must be created and prepared for data to be assembled
into it.
PVM provide two functions for buffer creation:
# pvm_initsend().
# pvm_mkbuf().
These two functions agree on the i/p & o/p parameters.
They take as input an integer value specify the next
message’s encoding scheme, and they return an integer
value specifying the message buffer identifier.
10. The two functions are listed below,
Three encoding types:
bufid=pvm_initsend(encoding_option)
bufid=pvm_mkbuf(encoding_option)
• XDR
• Default option0
• No encoding
• Skip the encoding type1
• Leave data in place
• Make send operation copy items directly from the
user’s memory
2
11. If user is
using only
one buffer
pvm_initsend()
Only a required
function
It clears send buffer &
prepares it for packing
a new message
Pvm_mkbuf()
It is useful when
multiple message
buffers are required
It creates a new empty
send buffer every time
it is called
12. 2)Data Packing:
PVM provides a variety of packing functions pvm_pk*()
to pack an array of a given data type into the active send
buffer.
Three arguments as inputs:
1st argument is a pointer to where the first item is,
2nd argument specifies the no of packed in an array.
3rd argument is the stride to use when packing.
There are several packing functions for all kinds of
data types such as,
Byte , Double , String , And so on.
13. All the functions have the same no of arguments
except the string packing function pvm_pkstr(),
which takes only one argument.
Packing functions for the different data types
include:
# pvm_pkbyte(), pvm_pkcplx(),
pvm_pkdcplx(), pvm_pkdouble(), pvm_pkfloat(),
pvm_pkint(), pvm_pklong(), pvm_pkshort(),
pvm_pkuint(), pvm_pkushort(), pvm_pkulong().
14. 3)Sending a Message:
*Sending messages in PVM is done in an
asynchronous fashion.
*The sending task will resume its execution once the
message is sent.
*It will not wait for the receiving task to execute the
matching receive operation as in synchronous
communication.
15. Sending to one Receiver:
The function pvm_send() performs a
point-to-point send operation.
Two Arguments:
TID of the destination task.
An integer message identifier(tag).
Ex,
The function call info=pvm_send(tid, tag)
16. Sending to multiple receiver:
To send the message to multiple destinations, the
function pvm_mcast() should be used.
pvm_mcast()=>Multiple receivers.(multicast)
Ex,
info= pvm_mcast(tid, n, tag) (n=tasks)
Sending to a group:
A message can be broadcast to all members of a group
using the function pvm_bcast().
Ex,
info=pvm_bcast(group_name, tag) (bcast=>broadcast)
17. Packing and sending in one step:
PVM also provides another function to send
messages without the need to prepare and pack the
buffer manually.
The operation pvm_psend() does the packing
automatically for then programmer.
Ex,
info=pvm_psend(tid, tag, my_array, n, int)
Packs an array of n integers called my_array into
a message labeled tag, and sends it to the task
whose TID is tid.
18. 4)Receiving a message:
Three types of message receiving functions are,
Blocking Nonblocking Timeout
The receiving task must
wait until the expected
message arrives in the
receive buffer.
A nonblocking receive
immediately returns with
either the expected data or a
flag that the data have not
arrived.
Timeout receive allows the
programmer to specify a
period of time for which the
receive function should wait
before it returns.
19.
20. BLOCKING RECEIVE:
bufid =pvm_recv(tid, tag)
This function will wait until a message with label
tag is received from a task with
TID = tid.
A value of -1 can be used as a wild card to match
anything in either one of the arguments:
tid or tag.
A successful receive will create a receive buffer
and return the buffer identifier to be used in unpacking
the message.
21. Nonblocking receive
bufid = pvm_nrecv(tid, tag)
If the message has arrived successfully when this
function is called, it will return a buffer identifier similar
to the case of blocking receive.
However, if the expected message has not arrived, the
function will return immediately with bufid = 0.
Timeout Receive:
bufid = pvm_trecv(tid, tag, timeout)
This function blocks the execution of its caller task until a message with a
label tag has arrived from tid within a specified waiting period of time.
If there is no matching message arriving within the specified waiting time,
this function will return with
bufid = 0, which indicates that no message was received.
22. Receive and Unpack in One Step:
Similar to the pvm_psend() function, PVM
provides the function pvm_precv(), which combines the
functions of blocking receive and unpacking in one
routine.
It does not return a buffer
Identifier; instead it returns the actual values.
Ex,
info = pvm_precv(tid, tag, my_array, len, datatype,
&src, &atag, &alen)
23. 5)Data Unpacking:
• When messages are received, they need to be
unpacked in the same way they were
packed in the sending task.
• Unpacking functions must match their
Corresponding packing functions in type, number of
items, and stride.
• PVM provides many unpacking functions
pvm_upk(), each of which corresponds to a
particular packing function.
• PVM also provides the two functions
pvm_upkstr() and pvm_unpackf() to unpack the
messages packed bypvm_pkstr() and pvm_packf(),
respectively.
24. Other unpacking functions for the different data
types include:
pvm_upkbyte(), pvm_upkcplx(), pvm_upkdcplx(),
pvm_upkdouble(),
pvm_upkfloat(), pvm_upkint(), pvm_upklong(),
pvm_upkshort(),
pvm_upkuint(), pvm_upkushort(), pvm_upkulong().
All packing,sending,receiving & unpacking functions affect only the active buffer. PVM provides the some functions to set the active send or receive buffers to bufid.They save the state of the previous buffer and return its identifier in oldbuf.
oldbuf=pvm_setsbuf (bufid)
oldbuf=pvm_setrbuf (bufid)