0% found this document useful (0 votes)
6 views

MPI-Programming-Lab

Uploaded by

sridevi10mas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

MPI-Programming-Lab

Uploaded by

sridevi10mas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MPI Progr(mming L(b

About job submission

Jobscript templ.te: jobscript.sh


Use your n.me .s jobn-me
Set -n in -prun st.tement .s .ppropri.te
All output to stdout .nd stderr from .prun will be in screen.out
Submit job (specify queue n.me for tod.y):
$ qsub -q QUEUENAME jobscript.sh

MPI Exercises

MPI function synt.x .v.il.ble on mpich.org - se.rch MPI_function_n.me on the


web

01-1-hello-world.c
Insert . print st.tement (ex. hello world) .nd m.ke it . Hello World C/Fortr.n
progr.m
Compile
$ cc 01-1-hello-world.c
Submit . job using jobscript.sh, with ONE process
$ qsub jobscript.sh
Check output in screen.out

01-2-hello-world.c
Turn your Hello World progr.m, or this one, into .n MPI Hello World progr.m
Look for comments .nd insert .ppropri.te st.tements
MPI_Init(&argc, &argv);
MPI_Finalize();
Compile
Submit . job using jobscript.sh, with n processes (n <=24. Your choice)
Check output in screen.out

02-hello-world-myr(nk-size.c
Develop your Hello World MPI progr.m to print MPI R.nk .nd MPI size v.lues
Compile
Submit . job using jobscript.sh, with n processes (n <=24. Your choice)
Check output in screen.out
Bro(dc(st
Develop your hello world progr.m to set
sendv.l = 10 only on R.nk 0
Bro.dc.st sendv.l to .ll r.nks
Print sendv.l from .ll r.nks, .long with myr.nk.

Run the code with n = 4 processes.

03-prime-seri(l.c
This code checks if . given number is prime number.
Underst.nd the seri.l code.
P.r.llelize with MPI.
Obt.in .n un.mbiguous output from p.r.llel code. (Hint: Use some
communic.tion).
How is the lo.d b.l.nce for .n .rbitr.ry test number? Discuss w.ys to improve.

MPI_Reduce
Write . progr.m to initi.lize . v.ri.ble v-r to different integers in different
r.nks.
Obt.in the sum of .ll such v.lues in R-nk 0 using MPI_Reduce .nd print.
Run the code for n < 24 .nd verify the output.

Obt(in size of MPI_COMM_WORLD.


Use your hello-world-myr.nk-size progr.m to obt.in the size of
MPI_COMM_WORLD, without using the MPI function MPI_Comm_size
Run the code for n < 24 .nd verify the output.

mpi_hello world two r(nks


Write .n MPI Hello world progr.m for two r.nks.
Print different strings from different r.nks.
For ex.mple,
“Hello world from R.nk 0” from R.nk 0
“A sep.r.te Hello from R.nk 1” from R.nk 1
Run the code for n =2 .nd verify the output.

MPI_Send (nd MPI_recv


Use the code from .bove exercise .nd set sendv-l = 10, recvv-l = 30
Send the v.lue sendv-l from R.nk 1 .nd receive it in R.nk 0 to recvv-l
Print recvv-l before .nd .fter the MPI function c.lls.
Run the code for n = 2 .nd n > 2.
Discuss the output
MPI_Sendrecv - circul(r
Write . progr.m to implement MPI_Sendrecv
..
set sendv.l = 1, recvv.l = 10.
From R.nk 0, send sendv.l to R.nk 1 v.ri.ble recvv.l
From R.nk 1, send sendv.l to R.nk 2 v.ri.ble recvv.l .nd so on.
R.nk 9 should send to R.nk 0.

b.
Modify the progr.m so th.t R.nk 1 sends “the v-lue it received” to R.nk 2 .nd
so on
Is it possible to .chieve it using Sendrecv?

C(lcul(te the v(lue of Pi


pi_mpi.c is . seri.l code to c.lcul.te the v.lue of pi.
P.r.llelize the code with MPI. Look for comments .nd commented lines .nd
upd.te .s .ppropri.te.
Comp.re the p.r.llel result with seri.l result.

AlltoAll
Ex.mples of MPI_AlltoAll .nd AlltoAllv .re provided in /mnt/lustre/serc3/
secguest*/2020J(n-MPI/D(y-2

You might also like