Lecture 5: Parallel Virtual Machine (PVM) - PowerPoint PPT Presentation

Loading...

PPT – Lecture 5: Parallel Virtual Machine (PVM) PowerPoint presentation | free to download - id: 80dbb5-NGNkZ



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Lecture 5: Parallel Virtual Machine (PVM)

Description:

Parallel Virtual Machine (PVM) ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 17
Provided by: ICSF5
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Lecture 5: Parallel Virtual Machine (PVM)


1
Lecture 5Parallel Virtual Machine (PVM)
2
Parallel Programming Models
  • Message Passing Model
  • Used on Distributed memory MIMD architectures
  • Multiple processes execute in parallel
    asynchronously
  • Process creation may be static or dynamic
  • Processes communicate by using send and receive
    primitives

3
Parallel Programming Models
  • Example Pi calculation
  • P f01 f(x) dx f01 4/(1x2) dx w ? f(xi)
  • f(x) 4/(1x2)
  • n 10
  • w 1/n
  • xi w(i-0.5)

f(x)
x
0 0.1 0.2 xi
1
4
Parallel Programming Models
  • Sequential Code
  • define f(x) 4.0/(1.0xx)
  • main()
  • int n,i
  • float w,x,sum,pi
  • printf(n?\n)
  • scanf(d, n)
  • w1.0/n
  • sum0.0
  • for (i1 iltn i)
  • xw(i-0.5)
  • sum f(x)
  • piwsum
  • printf(f\n, pi)

f(x)
x
0 0.1 0.2 xi
1
P w ? f(xi) f(x) 4/(1x2) n 10 w
1/n xi w(i-0.5)
5
Parallel Virtual Machine (PVM)
  • www.netlib.org/pvm3

6
  • Parallel PVM Code
  • / master /
  • include ltstdio.hgt
  • include ltpvm3gt
  • define WORKER /home/esin/worker
  • main()
  • int mytid, nproc, nt, msgtype, tids10
  • int n,i
  • float w,sum,pi
  • mytid pvm_mytid()
  • nproc 4
  • nt pvm_spawn(WORKER, NULL, PvmTaskDefault, ,
    nproc, tids)
  • printf(d - spawned d tasks\n, mytid, nt)
  • n 10
  • msgtype1
  • for (i0 iltnproc i)
  • pvm_initsend(PvmTaskDefault)

/ worker / include ltstdio.hgt include
ltpvm3gt define f(x) 4.0/(1.0xx)
main() int mytid, nproc, nt, msgtype,
tids10 int n,I, start, end float
w,x,sum msgtype1 pvm_recv(pvm_parent(),
msgtype) pvm_upkint(myid, 1,
1) pvm_upkint(nproc, 1, 1) pvm_upkint(tids,
nproc, 1) pvm_upkint(n, 1, 1) w1.0/n sum
0.0 start myid(n/nproc) end
(myid1)(n/nproc) for (istart iltend
i) x w(i-0.5) sum
f(x) msgtype2 pvm_initsend(PvmTaskDefault
) pvm_pkfloat(sum, 1, 1) pvm_send(pvm_parent
(), msgtype) pvm_exit()
7
Parallel Programming Models
  • Parallel PVM program
  • Master
  • Creates workers
  • Sends initial values to workers
  • Receives local sums from workers
  • Calculates and prints pi
  • Workers
  • Receive initial values from master
  • Calculate local sums
  • Send local sums to Master

Master
W0
W1
W2
W3
Master
8
Parallel Virtual Machine (PVM)
  • Data Distribution

f(x)
f(x)
x
x
0 0.1 0.2 xi
1
0 0.1 0.2 xi
1
9
/ worker / include ltstdio.hgt include
ltpvm3gt define f(x) 4.0/(1.0xx)
main() int mytid,nproc, nt,
msgtype,tids10 int n,i, start, end float
w,x,sum, result msgtype1 pvm_recv(pvm_parent
(), msgtype) pvm_upkint(myid, 1,
1) pvm_upkint(nproc, 1, 1) pvm_upkint(tids,
nproc, 1) pvm_upkint(n, 1, 1) w1.0/n sum
0.0 start myid(n/nproc) end
(myid1)(n/nproc) for (istart iltend
i) x w(i-0.5) sum f(x) if
(myid0) msgtype2 for (i1
iltnproc i) pvm_recv(tidsi,
msgtype) pvm_upkfloat(result, 1, 1) sum
result piwsum
msgtype3 pvm_initsend(PvmTaskDefault)
pvm_pkfloat(sum, 1, 1)
pvm_send(pvm_parent(), msgtype) else
msgtype2 pvm_initsend(PvmTaskDefault)
pvm_pkfloat(sum, 1, 1) pvm_send(tids0,
msgtype) pvm_exit()
  • SPMD Parallel PVM Code
  • / master /
  • include ltstdio.hgt
  • include ltpvm3gt
  • define WORKER /home/esin/worker
  • main()
  • int mytid, nproc, nt, msgtype, tids10
  • int n,i
  • float w,sum,pi
  • mytid pvm_mytid()
  • nproc 4
  • nt pvm_spawn(WORKER, NULL, PvmTaskDefault, ,
    nproc, tids)
  • printf(d - spawned d tasks\n, mytid, nt)
  • n 10

10
Parallel Programming Models
  • SPMD Parallel PVM program
  • Master
  • Creates workers
  • Sends initial values to workers
  • Receives pi from W0 and prints
  • Workers
  • Receive initial values from master
  • Calculate local sums
  • Workers other than W0
  • Send local sums to W0
  • W0
  • Receives local sums from other workers
  • Calculates pi
  • Sends pi to Master

Master
W0
W1
W2
W3
Master
11
Parallel Virtual Machine (PVM)
12
Parallel Virtual Machine (PVM)
  • C Interface
  • include pvm3.h
  • Process Control
  • int tid pvm_mytid(void)
  • int info pvm_exit(void)
  • int info pvm_kill(int tid)
  • int info pvm_addhosts(char hosts, int nhost,
    int infos)
  • int info pvm_delhosts(char hosts, int nhost,
    int infos)
  • int numt pvm_spawn(char task, char argv, int
    flag, char where, int ntask, int tids)
  • Information
  • int tid pvm_parent(void)
  • int dtid pvm_tidtohost(int tid)
  • int info pvm_perror(char msg)
  • int info pvm_config(int nhost, int narch,
    struct hostinfo hostp)
  • int info pvm_tasks(int which, int ntask,
    struct taskinfo taskp)

13
Parallel Virtual Machine (PVM)
  • C Interface
  • Signalling
  • int info pvm_sendsig(int tid, int signum)
  • int info pvm_notify(int about, int msgtag, int
    ntask, int tids)
  • Message Buffers
  • int bufid pvm_mkbuf(int encoding)
  • int info pvm_freebuf(int bufid)
  • int bufid pvm_getsbuf(void)
  • int bufid pvm_getrbuf(void)
  • int oldbuf pvm_setsbuf(int bufid)
  • int oldbuf pvm_setrbuf(int bufid)
  • int bufid pvm_initsend(int encoding)
  • int info pvm_upklong(long np, int cnt, int std
    )

14
Parallel Virtual Machine (PVM)
  • C Interface
  • Sending
  • int info pvm_packf( printflike format... )
  • int info pvm_pkbyte( char cp, int cnt, int std
    )
  • int info pvm_pkcplx( float xp, int cnt, int
    std )
  • int info pvm_pkdcplx( double zp, int cnt, int
    std )
  • int info pvm_pkdouble(double dp, int cnt, int
    std )
  • int info pvm_pkfloat( float fp, int cnt, int
    std )
  • int info pvm_pkint( int np, int cnt, int std )
  • int info pvm_pklong( long np, int cnt, int std
    )
  • int info pvm_pkshort( short np, int cnt, int
    std )
  • int info pvm_pkstr( char cp )
  • int info pvm_send( int tid, int msgtag )
  • int info pvm_mcast( int tids, int ntask, int
    msgtag )
  • int info pvm_psend( int tid, int msgtag, void
    vp, int cnt, int type )
  • Receiving
  • int bufid pvm_recv( int tid, int msgtag )
  • int bufid pvm_probe( int tid, int msgtag )

15
Parallel Virtual Machine (PVM)
  • C Interface
  • Group Operations
  • int inum pvm_joingroup(char group)
  • int info pvm_lvgroup(char group)
  • int size pvm_gsize(char group)
  • int tid pvm_gettid(char group, int inum)
  • int inum pvm_getinst(char group, int tid)
  • int info pvm_barrier(char group, int count)
  • int info pvm_bcast(char group, int msgtag)
  • int info pvm_reduce(void op, void vp, int
    cnt, int type, int msgtag, char group, int root)
  • op options vp type options
  • PvmMax PVMBYTE PVMFLOAT
  • PvmMin PVMSHORT PVMDOUBLE
  • PvmSum PVMINT PVMCPLX
  • PvmProduct PVMLONG PVMDCPLX

16
Parallel Virtual Machine (PVM)
  • C Interface
  • Starting PVM
  • pvmd nhostname d!debugmask? hostfile
  • pvm hostfile (starts console)
  • Compiling PVM Applications
  • cc o task myprog.c libpvm3.a
  • For groups add libgpvm3.a before libpvm3.a 1

PVM Console Commands help command -- get
information about commands conf -- lists hosts
in virtual machine add host(s) -- add host(s) to
virtual machine delete host(s) -- delete host(s)
spawn opt file -- spawn process !count? --
number of tasks to spawn !host? -- host to spawn
on ? -- redirect task output to console ?file
-- redirect task output to file ??file -- append
task output to file ps a -- lists processes on
virtual machine alias -- define/list command
aliases unalias -- undefine command alias
setenv -- set/show environment variables echo
-- echo arguments version -- print libpvm
version id -- print console tid sig num tid --
send signal num to process kill tid -- terminate
a process reset -- kill all processes and reset
PVM quit -- exit console (PVM continues) halt
-- kill all pvmds and console
About PowerShow.com