Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

CS

6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

S.
No. Na
meoft
heTopi
c Re
fer
enc
es

UNI
T4-DI
STRI
BUTEDMEMORYPROGRAMMI
NGWI
THMPI

1. MPIpr
ogr
ame
xec
uti
on T1

2. MPIc
ons
truc
ts T1

3. MPIl
ibr
ari
es T1

4. MPIs
enda
ndr
ece
ive T1

5.
Poi
nt-
to-
poi
nta
ndCol
le
cti
vec
ommu
nic
ati
on T1
6.
7. MPIde
rive
dda
tat
ype
s T1

8.
Pe
rfor
manc
eev
alu
ati
on T1
9.
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

MPI
Me
ssa
gePa
ssi
ngI
nte
rfa
ce(
MPI
)isame
ssa
gep
ass
ingl
ibr
aryi
nte
rfa
ces
pec
ifi
cat
ion.MPIa
ddr
ess
es
pr
ima
ril
ytheme
ssa
ge-
pas
singpa
ral
le
lpr
ogr
ammi
ngmo
del
.

MPIPr
ogr
amExe
cut
ion

#i
ncl
ude<st
dio.
h>
#i
ncl
ude<mpi
.h>

i
ntmai
n(i
ntar
gc,
char*
angv
[]){i
ntr
ank,
size;
MPI
_I
nit(
&ar
gc,
&ar
gv)
;/*st
art
sMPI*
/
/
*getcur
rentpr
ocessi
d*/
MPI
_Comm_
rank(
MPI
_COMM_
WORLD,
&rank)
;
/
*getnumberofpr
ocesses*
/
MPI
_Comm_
siz
e(MPI
_COMM_
WORLD,
&si
ze)
;
pr
int
f("
Hel
l
owor
ldf
rom pr
ocess%dof%d\
n",
rank,
size)
;MPI
_Fi
nal
i
ze(
);/
*exi
t
MPI*
/ret
urn0;
}
Pr
ogr
am:He
lloWor
ldPr
ogr
ammpi
_he
llo.
c

• Compi
lat
ion
$mpi
cc-
g-Wal
l-ompi
_hel
l
ompi
_hel
l
o.c
mpi
cci
sas
cri
ptt
hat
’sawr
appe
rfort
heCc
ompi
le
r.Awr
app
ers
cri
pti
sas
cri
ptwhos
ema
inpur
pos
eist
orun
s
omepr
ogr
am.
Int
hisc
ase
,th
epr
ogr
ami
stheCc
ompi
le
r.Howe
ver
,th
ewr
appe
rsi
mpl
if
iest
her
unni
ngoft
he
c
ompi
le
rbyt e
ll
ingi
twhe
ret
ofi
ndt
hene
ces
sar
yhe
ade
rfi
le
sandwh
ichl
ibr
ari
est
oli
nkwi
tht
heobj
ectf
il
e.
• Execut
ion
mpi
exe
cisus
edt
ost
arto
rla
unc
hMPIa
ppl
ic
ati
ons
.

$mpiexec- ocesses〉 .
n<numberofpr /mpi
_hel
l
o
Tor
un1Proc
ess
$mpi
exec-
n1.
/mpi
_hel
l
o

He
ll
owor
ldf
rompr
oce
ss0of1

Tor
un4pr
oce
ss
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

$ mpi
exec -
n4.
/mpi
_hel
l
o He
ll
o

wor
ldf
rom pr
oce
ss0of4He
ll
owor
ld

f
rom pr
oce
ss1of4He
ll
owor
ldf
rom

pr
oce
ss2of4He
ll
owor
ldf
rompr
oce
ss3

of4

• i
ntMPI
_Ini
t(i
nt*ar
gc,
char
***ar
gv)
I
tini
ti
al
iz
etheMPIs
yst
ema
ndi
tmu
stbet
hef
ir
sts
tat
eme
nti
nanMPIpr
ogr
am.Th
ear
gume
nts
,ar
gca
nd
a
rgv,a
repoi
nte
rst
othea
rgume
ntst
oma
in,a
rgc
,an
dar
gv.Ho
wev
er,whe
nourpr
ogr
amdoe
sn’
tus
ethe
se
a
rgume
nts
,wec
anj
ustpa
ssNULLf
orbot
h.
• i
ntMPI
_Fi
nal
ize(
voi
d)
I
tte
rmi
nat
est
heMPIs
yste
manda
nyre
sour
cesa
ll
oca
tedf
orMPIcanbef
ree
d.
• intMPI_Comm_ si
ze(
MPI_Comm communi cator,
int*si
ze)
I
tre
tur
nst
hes
izeofac
ommuni
cat
or.

• i
ntMPI
_Comm_
rank(
MPI
_Comm communi
cat
or,
int
*rank)
I
tre
tur
nst
her
ankofapr
oce
ssi
nac
ommun
ica
tor
.

• MPI
_COMM_
WORLD
I
tthed
efa
ultMPIc
ommuni
cat
orc
ons
truc
tedf
orusbyMPI
.Itc
ons
ist
sofa
llMPIpr
oce
sse
stha
tthepr
ogr
am
i
sus
ing.

I
nMPIac
ommuni
cat
ori
sac
oll
ect
iono
fpr
oce
sse
stha
tca
nse
ndme
ssa
gest
oea
cho
the
r.Ea
chpr
oce
ssi
nsi
de
ofac
ommuni
cat
ori
sas
signe
dani
ncr
eme
nta
lra
nks
tar
ti
ngf
rom z
ero.Th
era
nksoft
hepr
oce
sse
sar
e
pr
ima
ril
yus
edf
ori
dent
if
ica
ti
onpur
pos
eswhe
nse
ndi
nga
ndr
ece
ivi
ngme
ssa
ges
.
Poi
ntt
oPoi
ntCommuni
cat
ion-MPISe
nda
ndRe
cei
ve

Bl
ocki
ngc
ommuni
cat
ioni
sdo
neus
ingMPI
_Se
nd(
)andMPI
_Re
cv(
).Th
esef
unc
ti
onsdonotr
etur
n(i
.e
.,
t
heybl
ock
)unt
ilt
hec
ommuni
cat
ioni
sfi
nis
hed.Thi
sme
anst
hatt
hebuf
ferpa
sse
dtoMPI
_Se
nd(
)ca
nbe
r
eus
ed,
eit
herbe
caus
eMPIs
ave
dits
ome
whe
re,
orbe
caus
eitha
sbe
enr
ece
ive
dbyt
hede
sti
nat
ion
.Si
mil
arl
y,
MPI
_Re
cv(
)re
tur
nswhe
nther
ece
ivebu
ffe
rha
sbe
enf
il
le
dwi
thva
li
dda
ta

iMPI
_Se
nd
I
tpe
rfor
msabl
ock
ings
end.
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

i
nt
MPI
_Send(v
oi
d*dat
a,i
nt
count
,
MPI
_Dat
aty
pedat
aty
pe,
i
ntdest
inat
ion,
intt
ag,
MPI
_Comm communi
cat
or)
• Thef
ir
stt
hre
ear
gume
nt,d
s a
ta,c
ount
,andda
tat
ype
,de
ter
minet
hec
ont
ent
soft
heme
ssa
ge.The
r
ema
ini
nga
rgume
nts
,de
sti
nat
ion,t
ag,a
ndc
ommuni
cat
or,de
ter
min
ethed
est
ina
ti
onoft
heme
ssa
ge.
• Thef
ir
sta
rgume
nt,da
ta,i
sap
oint
ert
othebl
ocko
fme
mor
ycont
ai
ningt
hec
ont
ent
soft
heme
ssa
ge.
• Thes
econda
ndt
hir
dar
gume
nt,c
s ounta
ndda
tat
ype
,de
ter
minet
hea
mou
ntofda
tat
obes
ent
.
• Thef
our
tha
rgume
nt,de
sti
nat
ion,s
pec
ifi
est
her
ankoft
hepr
oce
sst
hats
houl
dre
cei
vet
heme
ssa
ge.
• Thef
if
tha
rgume
nt,t
ag,i
sano
nne
gat
ivei
nt.I
tca
nbeus
edt
odi
st
ingu
ishme
ssa
gest
hata
reot
her
wis
e
ide
nti
cal.
• Thefi
nalargume
ntt
oMPI
_Se
ndi
sac
ommuni
cat
or.
Exa
mpl
e:
MPI
_Send(
&number
,1,
MPI
_I
NT,
1,0,
MPI
_COMM_
WORLD)
;
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

MPI
dat
aty
pe
MPI_CHAR Cda
tat
ype
MPI-SHORT signedc hs
irs igned
MPIJNT shortinisi
gne di ni
MPLLONG signedlongi nis i
g ned
MPI丄 ONGJ LONG longlongi niuns igned
dniruns i
gne df i
hor l
iniunsignedi ni
unsignedlongi ni
flosi
ldoubl elong
double

MPI_UNSI
GNED_CHAR
MPI_UNSI
GNED_SHOIRT
MPLUNSIGNEID
MPLUNSIGNEIDJLONG
MPI_FI
LOAT
MPLDOUBLE
MPI丄 DNGJJOUBLE
MPI_BYTE
MPLPACKED
Ta
ble
:SomePr
ede
fine
dMPIDa
tat
ype
s
i
-MPI
_Re
cv
I
tpe
rfor
msbl
ocki
ngr
ece
ivef
orame
ssa
ge.

i
ntMPI
_Recv
(voi
d*dat
a,i
ntcount
,
MPI
_Dat
aty
pedat
aty
pe,
i
ntsour
ce,
intt
ag,
MPI
_Comm communi
cat
or,
MPI
_St
atus*st
atus)

• Thef
ir
sta
rgume
nt,da
ta,i
sap
oint
ert
othebl
ockofme
mor
ycont
ai
ningt
hec
ont
ent
soft
heme
ssa
ge.
• Thes
econda
ndthi
rda
rgument,c
s ountanddat
atype
,de
ter
minethea
mountofda
tatober
ece
ive
d.
• Thes
ourcea
rgume
ntspe
cif
iest
heproce
s sf
romwhicht
hemessa
geshoul
dberec
eiv
ed.
• Thet
aga
rgume
nts
houl
dma
tcht
het
aga
rgume
ntoft
heme
ssa
gebe
ings
ent
.

• Thec
ommuni
cat
ora
rgume
ntmus
tma
tcht
hec
ommuni
cat
orus
edbyt
hes
endi
ngpr
oce
ss.

• Thes
tat
usa
rgume
ntc
anbei
gnor
edwi
thMPI
_STATUS_I
GNOREc
ons
tant
.

Exa
mpl
e:
MPI
_Recv
(&number
,1,
MPI
_I
NT,
0,0,
MPI
_COMM_
WORLD,
MPI
_STATUS_
IGNORE)

CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

Thes
tat
usa
rgume
nt
TheMPIt
ypeMPI
_St
at
usi
sas
tru
ctwi
tha
tle
astt
het
hre
eme
mbe
rsMPI
_SOURCE,MPI
_TAG,a
nd
MPI
_ERROR.
I
fwepa
ssa
nMPI
_St
at
uss
truc
tur
etot
heMPI
_Re
cvf
unc
ti
on,
itwi
llbepo
pul
at
edwi
tha
ddi
ti
ona
linf
orma
ti
on
a
boutt
her
ece
iveoper
ati
onaft
eritc
omple
tes
.Thet
hre
epr
ima
ryp
iec
esofi
nfor
mat
ioni
ncl
ude
:
• Theamountofdat
ainthemes
sage

• Thes
end
eroft
heme
ssa
ge

• Thet
ago
ftheme
ssa
ge
Supp
oseourpr
ogr
amc
ont
ai
nst
hede
fin
iti
on
MPI
_St
atusst
atus;
The
n,a
fte
rac
allt
oMPI
_Re
cvi
nwh
ich&s
tat
usi
spa
sse
dast
hel
asta
rgume
nt,
wec
and
ete
rmi
net
hes
end
er
a
ndt
agbye
xami
ningt
het
wome
mbe
rsst
atus.
MPISOURCEst
atus.
MPITAG
Thea
mount
ofda
tado
esnot
haveapr
ede
fine
del
eme
nti
nthes
tat
uss
truc
tur
e.I
nst
ead,
weha
vet
ofi
ndou
tthe
l
engt
hoft
heme
ssa
gewi
thMPIGe
tc
一 ount
一.
i
ntMPI
_Get
_count
(
MPI
_St
atus*st
atus,
MPI
_Dat
aty
pedat
aty
pe,
i
nt*count
)
I
nMPI
_Ge
t_c
ount
,theus
erpa
sse
stheMPI
_St
at
uss
truc
tur
e,t
hed
ata
typeoft
heme
ssa
ge,a
ndc
ounti
s
r
etur
ned.Thec
ountva
ria
blei
sthet
ota
lnumbe
rofda
tat
ypee
leme
ntst
hatwe
rer
ece
ive
d.
Whywoul
danyo
fthi
sinf
orma
ti
onbene
ces
sar
y?I
ttur
nsoutt
hatMPI
_Re
cvc
ant
akeMPI
_ANY_SOURCE
f
ort
her
ankoft
hes
ende
randMPI
_ANY_TAGf
ort
het
ago
ftheme
ssa
ge.Fort
hisc
ase
,theMPI
_St
at
us
s
truc
tur
eist
heon
lywa
ytof
indo
utt
hea
ctua
lse
nde
randt
agoft
heme
ssa
ge.Fur
the
rmo
re,MPI
_Re
cvi
snot
gua
rant
eedt
ore
cei
vet
hee
nti
rea
moun
tofe
leme
ntspa
sse
dast
hea
rgume
ntt
oth
efun
cti
onc
all
.Ins
tea
d,i
t
r
ece
ive
sthea
mountofe
leme
ntst
hatwe
res
entt
oit(
andr
etur
nsa
ner
rori
fmor
eel
eme
ntswe
res
entt
hant
he
de
sir
edr
ece
ivea
mount
).TheMPI
_Ge
t_c
ountf
unc
ti
oni
sus
edt
ode
ter
minet
hea
ctua
lre
cei
vea
mount
.
COLLECTI
VECOMMUNI
CATI
ON

Tr
eeSt
ruc
tur
edCommuni
cat
ion
TheCol
le
cti
vec
ommuni
cat
ionf
unc
ti
onsma
keus
eoft
rees
tru
ctur
etoc
alc
ula
tea
ndc
ommuni
cat
ether
esul
t.
Thepa
tt
ernbywhi
chpr
oce
sse
sjo
int
hec
omput
at
ioni
str
ee-
bas
ed.Th
ede
ptho
fba
lanc
edbi
nar
ytr
eewi
thN
node
sis[
log2N]
.Tr
ee-
bas
edc
ommu
nic
ati
oni
sve
ryc
ommo
nwh
enva
lue
sar
ebe
ingdi
st
ri
but
edorc
oll
ect
ed
a
sitma
kesopt
ima
lus
eofc
ommuni
cat
ionr
esour
ces
.
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

I
nthea
bovedi
agr
am,
ini
ti
al
lys
tude
ntsorp
roc
ess
es1,
3,5,
and7s
endt
hei
rva
lue
stopr
oce
sse
s0,
2,4,
and6
,
r
espe
cti
vel
y.The
npr
oce
sse
s0,2,4,
and6a
ddt
her
ece
ive
dva
lue
stot
hei
ror
igi
nalva
lue
s,a
ndt
hepr
oce
ssi
s
r
epe
ate
dtwi
ce:
1. a
.Pr
oce
sse
s2a
nd6s
endt
hei
rne
wva
lue
stopr
oce
sse
s0a
nd4,
res
pec
ti
vel
y.b
.Pr
oce
sse
s
0a
nd4a
ddt
her
ece
ive
dva
lue
sin
tot
hei
rne
wva
lue
s.
2. a
.Pr
oce
ss4s
endsi
tsne
wes
tva
luet
opr
oce
ss0.
b.Pr
oce
ss0a
ddst
her
ece
ive
dva
luet
oit
sne
wes
tva
lue
.

Fi
g:Ana
lte
rna
tivet
ree
-st
ruc
tur
edgl
oba
lsum
MPI
_Bc
ast
Dur
ingabr
oadc
ast
,onepr
oce
sss
endst
hes
ameda
tat
oal
lpr
oce
sse
sinac
ommuni
cat
or.
Oneoft
hema
inus
es
ofbr
oadc
ast
ingi
stos
endoutus
eri
npu
ttoapa
ral
le
lpr
ogr
am,ors
endoutc
onf
igur
ati
onp
ara
met
erst
oal
l
pr
oce
sse
s.
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

i
nt
MPI
_Bcast
(v
oi
d*dat
a,i
nt
count
,
MPI
_Dat
aty
pedat
aty
pe,
intr
oot
,
MPI
_Comm communi
cat
or)

MPI
_Sc
att
er
MPI
_Sc
att
eri
sac
oll
ect
iver
out
inet
hati
sve
rys
imi
la
rtoMPI
—Bc
ast
.Th
epr
ima
rydi
ff
ere
ncebe
twe
en
MPI
—Bc
asta
ndMPI
_Sc
att
eri
ssma
llbuti
mpor
tan
t.MPI
—Bc
asts
end
sth
esa
mepi
eceofda
tat
oal
l
pr
oce
sse
swhi
leMPI
_Sc
att
ers
endsc
hunk
sofa
nar
rayt
odi
ff
ere
ntpr
oce
sse
s.
i
ntMPI
_Scat
ter
(
v
oid*send_
dat
a,i
ntsend_
count
,
MPI
_Dat
aty
pesend_
dat
aty
pe,
v
oid*r
ecv
_dat
a,i
ntr
ecv
_count
,
MPI
_Dat
aty
per
ecv
_dat
aty
pe,
int
r
oot
,
MPI
_Comm communi
cat
or)
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

Be
ast

MPI
_Ga
the
r
MPI
_Ga
the
rist
hei
nve
rseofMPI
_Sc
att
er.
Ins
tea
dofs
pre
adi
nge
leme
ntsf
romonepr
oce
sst
oma
nypr
oce
sse
s,
MPI
_Ga
the
rta
kese
leme
ntsf
romma
nypr
oce
sse
sandga
the
rst
hemt
oones
ingl
epr
oce
ss.
i
ntMPI
_Gat
her
(
v
oid*send_
dat
a,i
nt
send_
count
,
MPI
_Dat
aty
pesend_
dat
aty
pe,
v
oid*r
ecv
_dat
a,i
ntr
ecv
_count
,
MPI
_Dat
aty
per
ecv
_dat
aty
pe,
int
r
oot
,

MPI
_Comm communi
cat
or)
MPI
_Al
lga
the
r
Gi
venas
etofe
leme
ntsd
ist
ri
but
eda
cros
sal
lpr
oce
sse
s,MPI
_Al
lga
the
rwi
llg
athe
ral
loft
hee
leme
ntst
oal
l
t
hep
roc
ess
es.I
nthemo
stba
sics
ens
e,MPI
_Al
lga
the
risa
nMPI
_Ga
the
rfol
lowe
dbya
nMPI
_Bc
ast
.
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

i
ntMPI
_Al
lgat
her
(voi
d*
send_
dat
a,i
nt
send_
count
,
MPI
_Dat
aty
pesend_
dat
aty
pe,
v
oid*r
ecv
_dat
a,i
ntr
ecv
_count
,
MPI
_Dat
aty
per
ecv
_dat
aty
pe,
MPI
_Comm communi
cat
or)

MPI
_Re
duc
e
Si
mil
art
oMPI
_Ga
the
r,MPI
_Re
duc
eta
kesa
nar
rayofi
npute
leme
ntsone
achpr
oce
ssa
ndr
etur
nsa
nar
rayof
out
pute
leme
ntst
other
ootpr
oce
ss.Theout
pute
leme
ntsc
ont
ai
nther
edu
cedr
esul
t.
i
ntMPI
_Reduce(
v
oid* send_
dat
a,
v
oid*r
ecv
_dat
a,i
nt
count
,
MPI
_Dat
aty
pedat
aty
pe,
MPI
_Opop,
intr
oot
,
MPI
_Comm communi
cat
or)
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

Tabl
Ope
e
r
:
a
t
P
i
re
de
onVa
f
i
l
ne
dRe
ue Me
a
duc
ni
t
i
ng
onOpe
rat
orsi
nMPI

MPI_MAX Ma xi
mum
MPIJMIN Mi ni
mum
MPI_SUM Sum
MIPI_PROI
D Product
MPI.LAND Logicaland
MPIJBAND Bit
wi s
ea nd
MIPI-LOR Logicalor
MPIJBOR Bit
wi s
eor
MPI_LX0R Logicalexc
lusi
veor
MPIJBXOR Bit
wi s
ee xc
lusi
veor
MPI.MAXLOC Ma xi
muma ndloc
ati
onof
MPI_MI NLOC ma
Mix
n i
mu
i
m um ndl
ma ocat
ionof
minimum

MPI
_Al
lr
educ
e
Ma
nypa
ral
le
lappl
ic
ati
onswi
llr
equi
rea
cce
ssi
ngt
her
educ
edr
esul
tsa
cros
sal
lpr
oce
sse
sra
the
rtha
nther
oot
pr
oce
ss.I
nas
imi
la
rcompl
eme
nta
rys
tyl
eofMPI
_Al
lga
the
rtoMPI
_Ga
the
r,MPI
_Al
lr
educ
ewi
llr
educ
eth
e
va
lue
san
ddi
st
ri
but
ether
esul
tst
oal
lpr
oce
sse
s.
i
ntMPI
_Al
lr
educe(v
oid*
send_
dat
a,v
oid*
r
ecv
_dat
a,i
nt
count
,
MPI
_Dat
aty
pedat
aty
pe,
MPI
_Opop,
MPI
_Comm communi
cat
or)

MPIDe
rive
dDa
taType
s

MPIpr
ovi
dest
hre
eba
sica
ppr
oac
hest
oco
nsol
ida
ti
ngda
tat
hatmi
ghtot
her
wis
ere
qui
remu
lti
pleme
ssa
ges
:
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

t
hec
ounta
rgume
ntt
othev
ari
ousc
ommun
ica
ti
onf
unc
ti
ons
,de
rive
dda
tat
ype
s,a
ndMPI
_Pa
ck/
Unpa
ck.
I
nMPI
,ade
rive
dda
tat
ypec
anbeus
edt
ore
pre
sent
anyc
oll
ect
ionofda
tai
te
msi
nme
mor
ybys
tor
ingbot
hthe
t
ype
soft
hei
te
msa
ndt
hei
rre
lat
ivel
oca
ti
onsi
nme
mor
y.
Thei
deahe
rei
stha
tifaf
unc
ti
ont
hats
end
sda
takn
owst
het
ype
sandt
her
ela
ti
vel
oca
ti
onsi
nme
mor
yofa
c
oll
ect
ionofda
tai
te
ms,i
tca
nco
lle
ctt
hei
te
msf
romme
mor
ybe
for
eth
eya
res
ent
.Si
mil
arl
y,af
unc
ti
ont
hat
r
ece
ive
sda
tac
andi
st
ri
but
ethei
te
msi
ntot
hei
rcor
rec
tde
sti
nat
ionsi
nme
mor
ywhe
nthe
y’r
ere
cei
ved.
For
mal
ly,ad
eri
vedd
ata
typec
ons
ist
sofas
eque
nceofba
sicMPIda
tat
ype
stoge
the
rwi
thadi
spl
ace
mentf
or
e
achoft
heda
tat
ype
s.
Fore
xampl
e,s
uppos
etha
tonpr
oce
ss0t
heva
ria
ble
sa,b,a
ndna
res
tor
edi
nme
mor
ylo
cat
ionswi
tht
he
f
oll
owi
nga
ddr
ess
es:
Vari
abl Addn&
e ea
a 24
b 40
Hi 48

The
nthef
oll
owi
ngde
riv
edda
tat
ypec
oul
dre
pre
sentt
hes
eda
tai
te
ms:
{
(MPI
_DOUBLE,
0),
(MPI
_DOUBLE,
16)
,(MPI
_I
NT,
24)
}
Thef
ir
ste
leme
ntofe
achpa
irc
orr
espo
ndst
othet
ypeoft
hed
ata
,andt
hes
eco
nde
leme
ntofe
achpa
iri
sthe
di
spl
ace
mentoft
hed
atae
leme
ntf
romt
hebe
ginn
ingoft
het
ype
.We
’vea
ssu
medt
hatt
het
ypebe
ginswi
tha
,
s
oit
hasdi
spl
ace
ment
0,a
ndt
heot
here
leme
ntsha
vedi
spl
ace
ment
sme
asur
ed,
inbyt
es,
froma
:bi
s40-
24=16
byt
esbe
yondt
hes
tar
tofa
,an
dni
s48-
24=2
4byt
esbe
yondt
hes
tar
tofa
.
Wec
a eMPITy
nus 一pec
rea
tes
t
一ruc
ttobui
一ldade
rive
dda
tat
ypet
hat
cons
ist
sofi
ndi
vidua
lel
eme
ntst
hat
have
di
ff
ere
ntba
sict
ype
s:
i
ntMPI
_Ty
pe_
creat
e_st
ruct
(int
count
,
consti
ntar
ray
_of
_bl
ockl
engt
hs[
],const
MPI
_Ai
ntar
ray
_of
_di
spl
acement
s[]
,const
MPI
_Dat
aty
pear
ray
_of
_ty
pes[
],
MPI
_Dat
aty
pe*
newt
ype)
I
nputPa
rame
ter
s
• count
:numberofbl
ocks(
int
ege
r)-
--a
lsonumbe
rofe
ntr
iesi
nar
raysa
rra
y—of
—type
s,
a
rra
y—of
—di
spl
ace
ment
sanda
rra
y—of
—bl
ockl
engt
hs

• ar
ray
_of
_bLockLengt
hs:numberofel
eme
ntsi
nea
chb
loc
k(a
rra
yofi
nte
ger
)
• ar
ray
_of
_di
spLacement
s:byt
edi
spl
ace
mentofe
achbl
ock(
arr
ayofa
ddr
essi
nte
ger
)

• ar
ray
_of
_ty
pes:t
ypeofe
leme
ntsi
nea
chbl
ock(
arr
ayofha
ndl
est
oda
tat
ypeobj
ect
s)Out
put
Pa
rame
ter
s
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

• newt
ype:newdat
at
ype(
handl
e)

Tof
indt
hedi
spl
ace
mentva
lue
swec
anus
eteMPI
h _Get
_addr
ess
i
ntMPI
_Get
_addr
ess(
constv
oid^
locat
ion,
MPI
_Ai
nt*addr
ess)
• l
oca
ti
on:l
oca
ti
oni
nca
ll
erme
mor
y /
*InputPa
rame
ter
*/
• a
ddr
ess
:addr
esso
floc
ati
on(
addr
essi
nte
ger
)/*Out
putPa
rame
ter
*/
Thes
pec
ialt
ypeMPI
—Ai
nti
sani
nte
gert
ypet
hati
sbi
geno
ught
ost
orea
naddr
essont
hes
yst
em.
,i
Thus nor
dert
oge
ttheva
lue
sina
rra
yofdi
spl
ace
ment
s, wec
anus
ethef
oll
owi
ngc
ode
:
MPI
_Ai
nta_
addr
,b_
addr
,n_
addr
;

MPI
_Get
_addr
ess(
&a,
&a_
addr
);ar
ray
_of
_di
spl
acement
s[0]=0;
MPI
_Get
_addr
ess(
&b,
&b_
addr
);ar
ray
_of
_di
spl
acement
s[1]=b_
addr-a_
addr
;
MPI
_Get
_addr
ess(
&n,
&n_
addr
);ar
ray
_of
_di
spl
acement
s[2]=n_
addr-a_
addr
;

Thea
rra
yofda
tat
ype
sshoul
dst
oret
heMPIda
tat
ype
soft
hee
leme
nts
,sowec
anj
ustde
fine
MPI
_Dat
aty
pear
ray
_of
_ty
pes[
3]={
MPI
_DOUBLE,
MPI
_DOUBLE,
MPI
_I
NT}
;

Wi
tht
hes
eini
ti
al
iz
ati
ons
,wec
anbui
ldt
hene
wda
tat
ypewi
tht
hec
all
MPI
_Dat
aty
penewI
nput
;

MPITy
pecr
eat
est
ruct
(3,
arr
ay_
of_
blockl
engt
hs,
arr
ay_
of_
displ
acement
s,ar
ray
_of
_ty
pes,
&newI
nput
);
Be
for
ewec
a enewI
nus nputi
nac
ommuni
cat
ionf
unc
ti
on,wemus
tfi
rstc
ommi
titwi
thac
allt
o
i
ntMPI
_Ty
pe_
commi
t(
MPIDat
aty
pe*newI
nput
Dat
aTy
pe/
*in/
out*
/);
Thi
sal
lowst
heMPIi
mpl
eme
nta
ti
ont
oopt
imi
zei
tsi
nte
rna
lre
pre
sent
at
ionoft
heda
tat
ypef
orus
ein
c
ommuni
cat
ionf
unc
ti
ons
.
Now,i
nor
dert ene
ous wI
nput
Dat
aTy
pe,wemaket
hef
oll
owi
ngc
allt
oMPI
_Bc
astone
achpr
oce
ss:
MPI
_Bcast
( 1,
&a, newI
nput
,0,
comm)
;
Sowec
a enewI
nus nputj
usta
swewo
uldus
eoneoft
heba
sicMPIda
tat
ype
s.
Onc
ewe
’ret
hroughus
ingt
hen
ewt
ype
,wec
anf
reea
nya
ddi
ti
ona
lst
ora
geus
edwi
thac
allt
o
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

i
ntMPI
_Ty
pe_
free(
MPIDat
aty
pe*ol
dInput
Dat
aTy
pe/
*in/
out*
/);

PERFORMANCEEVALUATI
ON

X-Ta
kingt
imi
ngs
MPIpr
ovi
desaf
unc
ti
on,
MPI
_Wt
ime
,tha
tre
tur
nst
henumbe
rofs
econdst
hatha
vee
laps
eds
inc
eso
met
ime
i
nthepa
st:doubl
eMPI
_IWt
ime(
voi
d);
Thus
,wec
ant
imeabl
ockofMPIc
odea
sfo
ll :doubl
ows est
art
,fi
nish;
star
t=MPI
_Wt
ime(
);
/
*Codet
obet
imed*
/

f
ini
sh=MPI
_Wt
ime(
);
pr
int
f("
Proc%d>El
apsedt
ime=%eseconds\
n"my
_rank,
fini
sh-
star
t);

Ti
mingt
hes
eri
alc
ode
:
The
re’
saCma
croGET_TI
MEd
efi
nedi
nthehe
ade
rfi
let
ime
r.h.
Thi
sma
cros
houl
dbec
all
edwi
thadoubl
e
ar
gument
:
#i
nclude"t
imer
.h"

doubl
est
art
,fi
nish;
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

GET_
TIME(
star
t);
/
*Codet
obet
imed*
/

GET_
TIME(
fi
nish)
;

pr
int
f("
Elapsedt
ime=%eseconds\
n",
fini
sh-
star
t);

Bot
hMPI
—Wt
imea
ndGET_TI
MEr
etu
rnwa
llc
loc
kti
me.Re
cal
ltha
tat
ime
rli
ket
heCc
loc
kfunc
ti
on
r
etur
nsCPU t
ime
—thet
imes
penti
nus
erc
ode
,li
bra
ryf
unc
ti
ons
,andope
rat
ings
yst
emc
ode
.Itdoe
sn’
t
i
ncl
udei
dleti
me,wh
vi
oc
h
i c
anb
dMa te
_a
vs
ei
cg
t
.ni
f
mui
ca
l
tnt
( par
tofp
ara
ll
el r
unti
me.
Wal
lcl
ockt
ime
,ont
heot
herha
nd,
give
s
double l ocal.A[
]
t
ota
lel
aps
e dt
ime,s
oitin
dcl
u
od
ue
bs
l
eidl
eti
l
ome
c.
al
-x[
]
double l ocal«y[
]
1nt l
ocalj
1nt n
2 1nt l
ocal』 /% 1n
3 MPI -
Co comm /♦f n/•
4 doub mml
e*x: out
拿拿
Y».
nnn/

5 1nt1ocal .1# J:
1ntlocal-
ok =1:
T

6


7 拿

3
T

9
01

3 x=mal 1oc(n*s1zeof(double))

4 MPI_A11gat her(l
ocal-X.l
ocal.
n#MPI.
D0UBLE.
5 x.local_n.MPI_ D0UBLE.comm): 16
17 for(l
ocalj=0: l ocal j<localj
n: l
ocal.
1-H-)|
18 l
ocal.y[local .
1]=0. 0;
19 f
or ( j =0: j<n:j ++)
20 localj [
local-1]+=1ocal _A[
local
.1*n+j]
*x[
j]:
21 |
22 f
ree(
x):
23 ) *Ma
/ t^vect
jnul
t♦/
Pr
ogr
am:AnMPIma
tri
x-ve
ctormul
ti
pli
cat
ionf
unc
tion

本 Re
sul
ts
Ther
esul
tsoft
imi
ngt
hema
tri
x-v
ect
ormul
ti
pli
cat
ionpr
ogr
ama
res
howni
nthef
oll
owi
ngTa
ble
.The
i
nputma
tri
ceswe
res
qua
re.
Thet
ime
ssh
owna
rei
nmi
ll
is
econ
ds.
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

Or
derofMat
ri
x
c
omiri
- 409 319 16, 38
s
z 10242048 6 2 4
41 1 64. 0 270 1100
1 6.
2 2. 8
0. 33.0 140 560
4 3
2. 5, 18.0 7 280
8 0
17 1
3. 9. 0
3 140
16 17 3.
2 8.
5 6
1 71
6 9 9
c
omm—s
zist
henumbe
rofproce
ss.Thet
ime orc
sf omm—s z=1a
retherun-
ti
meso
fth
ese
ria
lpr
ogr
am
r
unni
ngo
nas
ingl
ecor
eoft
hedi
st
ri
but
edme
mor
ysys
tem.Nots
urpr
isi
ngl
y,i
fwef
ixc
omm s
z,a
nd
i
ncr
eas
en,t
heor
deroft
hema
tri
x,t
her
un-
ti
mesi
ncr
eas
e.Forr
ela
ti
vel
ysma
llnumbe
rsofp
roc
ess
es,
doubl
ingnr
esul
tsi
nroug
hlyaf
our
¬fol
dinc
rea
sei
nther
un-
ti
me.Howe
ver
,fo
rla
rgenumb
ersof
pr
oce
sse
s,t
hisf
ormul
abr
eaksdo
wn.
I
fwef
ixna
ndi
ncr
eaec
s omm—s
z,t
her
un-
ti
mesus
ual
lyde
cre
ase
.Inf
act
,fo
rla
rgev
alue
sofn
,doubl
ing
t
henumbe
rofpr
oce
sse
sroughl
yha
lve
stheove
ral
lrun-
ti
me.Howe
ver
,fors
mal
ln,t
her
eisve
ryl
it
tl
e
be
nef
iti
ninc
rea
singc
omm—s
z.I
nfa
ct,i
ngoi
ngf
rom8t
o16pr
oce
sse
swhe
nn=1024,t
heove
ral
lrun
t
imei
sunc
hange
d.
Aswei
ncr
eas
ethenumbe
rofp
roc
ess
es,t
her
un-
ti
mest
ypi
cal
lyde
cre
asef
orawhi
le
.Howe
ver
,ats
ome
poi
nt,t
her
un-
ti
mesc
ans
tar
ttoge
twor
se.Thee
xpl
ana
ti
onf
ort
hisi
stha
tthe
rei
sac
ommonr
ela
ti
on
be
twe
ent
her
un-
ti
mesofs
eri
alpr
ogr
amsa
ndt
her
un¬t
ime
sofc
orr
espondi
ngpa
ral
le
lpr
ogr
ams
.The
numb
erofpr
oce
sse
s,c
omm_s z=p.
Tparal
l
el(
n,p) =Tseri
al(
n) /p+Toverhead

I
nMPIpr
ogr
ams
,thepa
ral
le
lov
erh
eadt
ypi
cal
lyc
ome
sfr
omc
ommuni
cat
ion,a
ndi
tca
nde
pendonbot
h
t
hepr
obl
ems
izea
ndt
henumb erofpr
oce
sse
s.
Tparal
l
el(
n,p)= Tseri
al(
n)/p+Tal
l
gat
her

Fo
rsma
ll
erva
lue
sofpa
ndl
arge
rva
lue
sofn,
thedomi
nantt
ermi
nourf
ormul
ais

Tseri
al(
n)/
p.
Fo
rsma
llna
ndl
argep,t
hedomi
nantt
ermi
nourf
ormul
aforTparal
l
elsTal
i l
gat .
her

木 Spe
edupa
nde
ffi
cie
ncy
Sp
eedu
pisj
ustt
her
ati
ooft
hese
rialr
un-
ti
met othepa
rallelr
u n-t
ime
:
S(
n,p)=Tseri
al门)
( /Tparal
l
el(n,p)
Thei
dea
lva
luef
orS(
n,p)i
sp.I
fS(
n,p)=p,t
henourpa
ral
le
lpr
ogr
amwi
thc
omm_s
z=pp
roc
ess
esi
s
r
unni
ngpt
ime
sfa
ste
rtha
nth
ese
ria
lpr
ogr
am.
Inpr
act
ic
e,t
hiss
pee
dup,
some
ti
mesc
all
edl
ine
ars
pee
dup,
i
sra
rel
yac
hie
ved.
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

Or
derofMa
tri
x
c
omm_
sz1024 40968192 16,
384

1 1
.0 1 1. 1.0 1.
0
2 1
.8 0
1 0. 1.
1 9 2.
0
4 2
,1 9
3, 9
3. 3.9 3‘
9
8 2
,4 1
4, 6
6. 7.5 7.
9
16 2
,4 8 5
6. 10.
8 142 15.
5
2
Ta
ble
:Spe
edupsofPa
ral
lelMa
tri
x-Ve
ctorMul
ti
pli
cat
ion
Fo
rsma
llpa
ndl
argen,ourpr
ogr
amo
bta
ine
dne
arl
yli
nea
rspe
edup
.Ont
heot
herha
nd,f
orl
argepa
nd
s
mal
ln,t
hes
pee
dupwa
scons
ide
rabl
yle
sst
hanp
.Thewor
stc
asewa
sn=1
024a
ndp
=16,whe
nweon
ly
ma
nage
das
pee
dupof2.
4.
Pa
ral
le
lef
fi
ci
enc
y(pe
rpr
oce
sss
pee
dup)i
sgi
venby:

E(
n,p)=S(
n,p)/p=Tser
ial
(n)/(
pxTpar
all
el(
n,p)
)Li
nea
rspe
edupc
orr
esponds

t
oapa
ral
le
lef
fi
ci
enc
yofp/
p=1
.0,
and
,inge
ner
al,
wee
xpe
ctt
hat
oure
ffi
ci
enc
ieswi
llbel
esst
han

1.
Or
derofMa
tri
x
commi 10 20 40 819 16r38
_sz 24 48 96 2 4
1.
0 1. 1.
0 10
1 0 00 0 0 1.
00
2 0.
8 0.
9 0.
9 0.
96 0.
98
4 9
0.
5 4
07 7
0.
8 0.
96 0.
98
e 1.
03 8.
06 9.
08 0.
94 0.
98
16 0
0.
1 1
0.
3 2
0.
6 0. 0.
97
5 9 8 69
Ta
ble
:Ef
fi
cie
nci
esofPa
ral
lelMa
tri
x-Ve
ctorMul
ti
pli
cat
ion
Onc
eaga
in,f
ors
mal
lpa
ndl
argenou
rpa
ral
le
lef
fi
ci
enc
iesa
rene
arl
ine
ar,a
ndf
orl
argepa
nds
mal
ln,
t
heya
reve
ryf
arf
roml
ine
ar.

木 Sc
ala
bil
it
y
Apr
ogr
ami
ssc
ala
blei
fthepr
obl
ems
izec
anbei
ncr
eas
eda
tar
ates
otha
tthee
ffi
ci
enc
ydoe
sn’
tde
cre
ase
a
sthenumbe
rofpr
oce
sse
sinc
rea
se.
Cons
ide
rtwopa
ral
le
lpr
ogr
ams
:pr
ogr
am Aa
ndpr
ogr
am B.Suppos
etha
tifp>2,t
hee
ffi
ci
enc
yof
pr
ogr
amAi
s0.
75,
rega
rdl
esso
fpr
obl
ems
ize
.Al
sos
uppo
set
hatt
hee
ffi
ci
enc
yofpr
ogr
amBi
sn/
(625p)
,
pr
ovi
dedp>2a
nd1000<n<6
25p.
The
nac
cor
dingt
oou
r“d
efi
nit
ion,,,b
othpr
ogr
amsa
res
cal
abl
e.
Fo
rpr
ogr
amA,
ther
ateofi
ncr
eas
ene
ede
dtoma
int
ai
ncons
tan
tef
fi
ci
enc
yis0,
whi
lef
orpr
ogr
amBi
fwe
i
ncr
eas
ena
tthes
amer
atea
swei
ncr
eas
ep,
we’
llma
int
ai
nac
ons
tant
eff
ici
enc
y.Fore
xampl
e,i
fn=1000
a
ndp=2,
thee
ffi
ci
enc
yofBi
s0.
80.
Ifwet
hendoubl
ept
o4a
ndwel
eavet
hep
rob
lems
izea
tn=1000,
t
hee
ffi
ci
enc
ywi
lldr
opt
o0.
40,bu
tifwea
lsodo
ubl
eth
epr
obl
ems
izet
on=2000,t
hee
ffi
ci
enc
ywi
ll
CS
6801-Mul
ti
cor
eAr
chi
tec
tur
eandPr
ogr
ammi
ng

r
ema
inc
ons
tanta
t0.
80.Pr
ogr
am Ai
sthusmor
esc
ala
blet
hanB,butbo
ths
ati
sfyourde
fini
ti
onof
s
cal
abi
li
ty.
Thepr
ogr
amst
hatc
anma
int
ai
nac
ons
tante
ffi
ci
enc
ywi
thouti
ncr
eas
ingt
hep
rob
lems
izea
res
ome
ti
mes
s
aidt
obes
tr
ongl
ysc
ala
ble
.Pr
ogr
amst
hat
canma
int
ai
nac
ons
tan
tef
fi
ci
enc
yift
hepr
obl
ems
izei
ncr
eas
es
a
tthes
amer
atea
sthen
umbe
rofp
roc
ess
esa
res
ome
ti
mess
aidt
obewe
akl
ysc
ala
ble
.Pr
ogr
am Ai
s
s
trongl
ysc
ala
ble
,andpr
ogr
am Bi
swe
akl
ysc
ala
ble
.Fur
the
rmor
e,ourma
tri
x-ve
ctormul
ti
pli
cat
ion
pr
ogr
ami
sal
soa
ppa
rent
lywe
akl
ysc
ala
ble
.

Re
fer
enc
es:
1. Pe
terS.
Pac
hec
o,“
AnI
ntr
odu
cti
ont
oPa
ral
le
lPr
ogr
a ng”
mmi , Mor
gan-Ka
uff
man
/El
sevie
r,20
11.
2. MPITut
ori
al
.Re
tri
eve
dfr
omh
ttp:
//
mpi
tut
ori
al
.c
om/
tut
ori
al
s/

You might also like