The Queen's University of Belfast

Parallel Computer Centre
[Next] [Previous] [Top]
Example Programs
Example Programs
world.f
program world
include `/totem/pvm3/include/fpvm3.h'
c Example program illustrating the use of PVM 3
integer mytid, who, numt, info, msgtype
integer hellotid
c Enroll this program in PVM
call pvmfmytid( mytid )
c Start another task ie spawn hello
call pvmfspawn(`hello', PVMDEFAULT, `*', 1,
hellotid, numt)
c Send a message to other task to begin processing,
c ie intialise the send buffer, pack the message, and
c send the message
call pvmfinitsend(PVMDEFAULT,info)
call pvmfpack(INTEGER4, mytid, 1,1,info)
msgtype = 1
call pvmfsend(hellotid,msgtype, info)
c Receive message back from task ie a blocking
c receive waiting for a message of type 2
msgtype = 2
call pvmfrecv(-1,msgtype, info)
c Unpack the message and test its contents.
call pvmfunpack(INTEGER4, who, 1, 1, info)
if (who .ne. hellotid) then
print * , 'World: incorrect TID received.'
endif
c Continue with processing and exit pvm
print*, 'World'
print*, `end of processing'
call pvmfexit()
stop
end
Example Programs
hello.f
program hello
include `/totem/pvm3/include/fpvm3.h'
c Example program illustrating the use of PVM 3
integer mytid, parenttid, info, msgtype
c Enroll program in PVM and find the tid of the parent
call pvmfmytid(mytid)
call pvmfparent(parenttid)
c A blocking receive waiting for a message of type 1,
c unpacks it and carries out processing
msgtype = 1
call pvmfrecv(-1, msgtype, info)
call pvmfunpack(INTEGER4, who, 1, 1, info)
if (who .ne. parenttid)
& print *, 'Hello: incorrect TID received.'
print*, `Hello'
c Sends a message back to the parent and exits pvm
call pvmfinitsend(PVMDEFAULT,info)
call pvmfpack(INTEGER4, mytid, 1,1,info)
msgtype = 2
call pvmfsend(parenttid, msgtype, info)
call pvmfexit()
stop
end
PVMFINITSEND()
Clears default send buffer and specifies message encoding
CALL PVMFINITSEND (ENCODING, BUFID)
- encoding - specifies the next message's encoding scheme where the options are:
- PvmDataDefault ie XDR encoding used by default as PVM cannot know if a user is going to add a heterogeneous machine before this message
- PvmDataRaw ie no encoding used when it is known that the receiving machine understands the native format
- PvmDataInPlace ie specifies that data be left in place during packing
- bufid - integer returned containing the message buffer identifier. Values less than zero indicate an error.
PVMFPACK()
Packs the active message buffer
CALL PVMFPACK(WHAT, XP, NITEM, STRIDE,
INFO)
- what - specifies the type of data being packed

- xp - pointer to the start of a block of bytes, can be of any data type but must match the corresponding unpack data type
- nitem - total number of items to be packed (not the number of bytes)
- stride - the stride to be used when packing the items
- info - integer status code returned by the routine, values less than zero indicate an error.
Eg
CALL PVMFPACK(INTEGER4, NSIZE, 1, 1, INFO)
PVMFSEND()
Sends the data in the active message buffer
CALL PVMFSEND(TID, MSGTAG, INFO)
- tid - integer task identifier of destination process
- msgtag - integer message tag supplied by the user, should be >= 0
- info - integer status code returned by the routine, values less than zero indicate an
error.
Eg
CALL PVMFSEND(TID, MSGTAG, INFO)
PVMFRECV()
Receives a message
CALL PVMFRECV(TID, MSGTAG, BUFID)
- tid - integer identifier of sending process supplied by the user, a -1 in this argument matches any tid ie. a wildcard.
- msgtag - integer message tag supplied by the user, should be >= 0, allows the user's program to distinguish between different kinds of messages. A -1 in this argument matches any msgtag ie. a wildcard.
- bufid - integer returns the value of the new active receive buffer identifier. Values less than zero indicate an error.
Eg.
CALL PVMFRECV(-1, 4, BUFID)
PVMFSPAWN()
Starts new PVM processes
CALL PVMFSPAWN(TASK, FLAG, WHERE,
NTASK, TIDS, NUMT)
- task - character string containing the executable file name of the PVM process to be started
- flag - integer specifying spawn options eg PvmTaskDefault which means PVM can choose any machine to start task
- where - character string specifying where to start the PVM process
- ntask - integer specifying the number of copies of the executable to start up
- tids - array of length at least ntask which contains the tids of the PVM process started by this pvmfspawn call
- numt - integer returning the actual number of tasks started, values less than 0 indicate a system error. A positive value less than ntask also indicates a partial failure
Eg
CALL PVMFSPAWN(`nodeprog', FLAG, `SGI', 1,
TIDS(3), NUMT)
PVMFMCAST()
Multicasts the data in the active message buffer to a set of tasks
CALL PVMFMCAST(NTASK, TIDS, MSGTAG, INFO)
- ntask - specifies the number of tasks to be sent a message
- tids - array of length at least ntask which contains the tids of the tasks to be sent the message
- msgtag - integer message tag supplied by the user, should be >= 0
- info - integer status code returned by the routine, values less than zero indicate an error.
[Next] [Previous] [Top]
All documents are the responsibility of, and copyright, © their authors and do not represent the views of The Parallel Computer Centre, nor of The Queen's University of Belfast.
Maintained by Alan Rea, email A.Rea@qub.ac.uk
Generated with CERN WebMaker