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
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)
C Packing Functions
- Each data type is packed by a different function:
int info = pvm_pkint(int *np, int item, int stride)
also
pkbyte, pkcplx, pkdcplx, pkdouble, pkfloat,
pklong, pkshort, pkstr
- Arguments are:
- a pointer to the first item
- nitem - number of items
- stride - stride/step through the data
- pvm_pkstr - packs a null terminated string (no nitem or stride)
- Can be called multiple times in any combination
- C structures must be packed by element
- Complexity of packed message is unlimited
- Unpacking should occur in the same order (and size) as packing (not strictly necessary but good programming practice)
- Similar functions exist for unpacking
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)
PVMFBUFINFO()
- Returns information about the message in the nominated buffer. Useful when the message was received with wildcards for TID and msgtag
CALL PVMFBUFINFO (BUFID, BYTES,
MSGTAG, TID, INFO)
- BUFID - integer buffer id returned by pvmfrecv
- BYTES - length of the last message
- MSGTAG - integer message tag
- TID - TID of sending process
- INFO - return status
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, `sioux-atm',
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.
Compilation
- During compilation programs need to be linked to the PVM library and the Fortran header file included:
f77 -Ipvm-include-directory -o hello hello.f
-Lpvm-root/lib/pvm-architecture -lfpvm3 -lpvm3
or
cc -Ipvm-include-directory -o hello hello.c
-Lpvm-root/lib/pvm-architecture -lpvm3
- Two environment variables PVM_ROOT and PVM_ARCH are provided to point to the location of PVM on the system. Hence
- f77 -I$PVM_ROOT/include -o hello hello.f -L$PVM_ROOT/lib/$PVM_ARCH -lfpvm3 -lpvm3
Execution
- The PVM console command spawn searches for the executable programs in 2 places
- in the user's directory - ~/pvm3/bin/$PVM_ARCH
- in $PVM_ROOT/bin/$PVM_ARCH
- Therefore compiled programs should be moved to ~/pvm3/bin/$PVM_ARCH
Practical
- Compilation and execution of program hello and world
[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