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)

PVMFPACK()

Packs the active message buffer

CALL PVMFPACK(WHAT, XP, NITEM, STRIDE,

INFO)

Eg

CALL PVMFPACK(INTEGER4, NSIZE, 1, 1, INFO)

C Packing Functions

int info = pvm_pkint(int *np, int item, int stride)

also

pkbyte, pkcplx, pkdcplx, pkdouble, pkfloat,

pklong, pkshort, pkstr

PVMFSEND()

Sends the data in the active message buffer

CALL PVMFSEND(TID, MSGTAG, INFO)

Eg

CALL PVMFSEND(TID, MSGTAG, INFO)

PVMFRECV()

Receives a message

CALL PVMFRECV(TID, MSGTAG, BUFID)

Eg.

CALL PVMFRECV(-1, 4, BUFID)

PVMFBUFINFO()

CALL PVMFBUFINFO (BUFID, BYTES,

MSGTAG, TID, INFO)

PVMFSPAWN()

Starts new PVM processes

CALL PVMFSPAWN(TASK, FLAG, WHERE,

NTASK, TIDS, NUMT)

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)

Compilation

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

Execution

Practical


[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