首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
辅导 COMP528、讲解 c/c++,Python程序语言
University of Liverpool Assignment 2 Resit COMP528
In this assignment, you are asked to implement a numerical method for solving a partial
differential equation. This document explains the operation in detail, so you do not have to
have studied calculus. You are encouraged to begin work on this as soon as possible to avoid
the queue times on Barkla closer to the deadline. We would be happy to clarify anything
you do not understand in this report.
1 Laplace solver
Modelling heat transfer in a room can be done by using the Laplace equation, a second-order
partial differential equation. This can be approximated using a iterative stencil method.
Consider this two-dimensional array which represents a 25m2
room.
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 100
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
Figure 1: An example of the room
This two-dimensional array represents the space in the room, where the dimensions are NxN.
Each element in this array represents the temperature of that point within the room. The
boundaries of the array represent the walls. The points equal to 100, represent a radiator
within the room. The radiator always occupies 60% of the right wall and is centred. That is
the radiator starts at t [N−1][ffoor((N−1)∗0.3)], and ends at t [N−1][ceil((N−1)∗0.7)]
assuming 0 based indexing. Note that the room will always be 25m2
. That means the number
of the points only changes the resolution of the points in the room, not the actual size of the
room.
To model how the heat from the radiator moves throughout the room, we use the following
calculation for each point.
curr t[ i ][ j]=AVERAGE(prev t[i][j+1]+prev t[i][j−1]+prev t[i+1][j]+prev t[i−1][j])
Figure 2: The iterative calculation to ffnd the temperature moving through the room
2023-2024 1University of Liverpool Assignment 2 Resit COMP528
That is, each point is equal to the average of the surrounding points. When applying this to
Figure 1, we have these new temperatures. Figure 3 is after the ffrst iteration, and Figure
4 is after the second iteration.
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 32.5 100
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
Figure 3: An example of the room after one iteration
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 15.625 10
10 10 10 10 10 10 10 15.625 38.125 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 43.75 100
10 10 10 10 10 10 10 15.625 38.125 100
10 10 10 10 10 10 10 10 15.625 10
10 10 10 10 10 10 10 10 10 10
Figure 4: An example of the room after two iterations
We can observe that we do not update the boundary elements, in order to avoid any access
to memory that does not exist. To update the array, only the elements within the range of
indices from the second row to the second-to-last row (rows 1 to N-2) and from the second
column to the second-to-last column (columns 1 to N-2) should be modiffed.
2023-2024 2University of Liverpool Assignment 2 Resit COMP528
1.1 OpenMP laplace solver
You are asked to implement this operation in a C function with the following signature. This
function should be saved in a ffle called heat.c
double g e t fi n a l t e m p e r a t u r e s ( int N, int maxIter , double radTemp){
// . . . your code here
int pointx = f l o o r ((N−1 ) ∗ 0 . 5 );
int pointy = f l o o r ((N−1 ) ∗ 0 . 5 );
double r e s u lt = c u rr t [ pointx ] [ pointy ] ;
return r e s u lt ;
}
N is the number of points along one axis of the room matrix and maxIter is the number of
iterations to be performed in one run. Both pointX and pointY are the coordinates for the
centre of the room and therefore curr t[pointx][pointy] is the temperature at the centre of
the room. radTemp is the value for the radiator to be set to. Therefore the function returns
the temperature of the centre of the room for a given radiator temperature after maxIter
iterations have been performed.
1.2 Serial Implementation
You are asked to implement a sequential main C ffle which can do the following.
• Read a string of radiator temperatures from an input ffle and store them in a onedimensional
array.
• Call the ‘get ffnal temperature()‘ function for each temperature.
• Store the results in a one-dimensional array.
• Write the results to an output ffle.
Once compiled, the sequential program should be called like so:
$ ./
Where
is the executable,
is the size of N (deffnes the number of points
in the room),
is the number of iterations to be performed for each radiator
temperature, and
is the name of the output ffle.
2023-2024 3University of Liverpool Assignment 2 Resit COMP528
1.3 Distributed implementation
This time, you are asked to implement a distributed main c ffle which can perform the same
functionality of the serial implementation, but distribute the radiator temperatures that are
read from the input ffle between MPI ranks.
Once compiled, the distributed program should be called like so:
$ mpirun −np
./
Where
is the number of MPI processes. The other arguments given here
are the same as those explained for the serial version.
1.4 Data ffle format
The ffrst line of the input ffle has an integer. This integer deffnes the number of temperatures
in the ffle. The second line of the data ffle is a space-separated list of all the radiator temperature
values. The output ffle will follow the same format. The input ffles’ names follows:
input K.dat where K is the number of values.
The output ffles’ names provided follow: output K N maxIter where K is number of values,
and N and maxIter are the arguments explained above.
1.5 Provided code
You are provided with the code ffle-reader.c which contains the following functions.
• read num of temps: Which takes an input ffle’s name as an argument, and returns
the ffrst line of ffle (the number of radiator temperatures)
• read temps: Which takes the input ffle’s name and the numOfTemps as arguments,
and returns a one-dimensional array of temperatures.
• write to output ffle: Which takes the output ffle’s name, the array of room
temperatures found and the numOfTemps as arguments, and writes to an output
ffle.
2023-2024 4University of Liverpool Assignment 2 Resit COMP528
2 Instructions
• Implement a multi-threaded laplace solver using OpenMP. Save it in a ffle called heat.c.
• Modify the main-serial.c ffle so that it reads from the input data ffle, calls your OpenMP
stencil function, and writes to the output data ffle. Use the output to make sure your
implementation is correct. Ensure your code is saved as main-serial.c.
• Modify the main-mpi.c ffle so that it performs the same functionality as main-serial.c
but distributes the radiator temperatures over multiple MPI processes. Ensure it is
saved as main-mpi.c.
• Write a Makeffle that includes instructions to compile your programs. Your MakeFile
should work like so:
– make gccserial - compiles ‘main-serial.c‘, ‘heat.c‘ and ‘ffle-reader.c‘ into
‘heat-omp-gcc‘ with the GNU compiler (gcc)
– make gcccomplete - compiles ‘main-mpi.c‘, ‘heat.c‘ and ‘ffle-reader.c‘ into
‘heat-complete-gcc‘ with the GNU mpi compiler (mpicc)
– make iccserial - compiles ‘main-serial.c‘, ‘heat.c‘ and ‘ffle-reader.c‘ into
‘heat-omp-icc‘ with the Intel compiler (icc)
– make icccomplete - compiles ‘main-mpi.c‘, ‘heat.c‘ and ‘ffle-reader.c‘ into
‘heat-complete-icc‘ with the Intel mpi compiler (mpiicc)
• Try running your program for 1, 2, 4, 8, 16 and 32 OpenMP threads, measuring the
time taken in each instance. Use this to plot a speedup plot with speedup on the y-axis
and the number of threads on the x-axis.
• Test the fastest running instance (up to 8 threads) over 1, 2, 4, 8, 16 and 32 ranks i.e.
if you found that 4 OpenMP threads was the fastest, test this with 1, 2, 4, 8, 16, 32
ranks. Use this to draw a strong-scaling plot with time on the y-axis and the number
of ranks on the x-axis.
– The maximum number of nodes you will need for 8 OpenMP threads and 32 MPI
ranks is 8 nodes.
– You will potentially have to wait hours/potentially a few days if you submit to
multiple nodes. If there is little time until the deadline, test with 1 OpenMP
thread up to 32 ranks on the course node.
• When testing your program on Barkla to get your results for the speedup
and strong-scaling plot, ensure you test with N = 256 maxIter = 4096 with
the large input ffle input 1024.dat
2023-2024 5University of Liverpool Assignment 2 Resit COMP528
• Using up to one page for each code you produced (not including images), write a report
that describes:
– your implementation and parallel strategy for heat.c, and its speedup plot
– your implementation for main-serial.c
– your implementation and parallel strategy for main-mpi.c, and its strong-scaling
plot
– for each plot, how you measured and calculated it, including a table with your
times and why your program achieved a linear speedup/reduction in time or not
Include a screenshot of compiling and running your program, making sure your username
is visible.
• Your final submission should include:
1. heat.c - the parallel implementation using OpenMP.
2. main-serial.c - a main function that calls the function defined in heat.c to perform
the operations described above
3. main-mpi.c - the complete implementation using OpenMP and MPI.
4. Makefile - a MakeFile that can compile 4 different programs. The instructions
for this are given above.
5. Report.pdf - a pdf file containing the plots, descriptions, and screenshots.
6. The slurm script you used to run your code on Barkla.
• This assignment should be uploaded on Codegrade, following the instructions
present there.
• Failure to follow any of the above instructions is likely to lead to reduction in scores.
2023-2024 6University of Liverpool Assignment 2 Resit COMP528
3 Hints
If you get any segmentation faults when running your program, use a tool called gdb to help
debug. Read its manual to understand how to use it.
Make sure to test your code with small as well as big matrices.
Ensure that you are not printing the room temperatures when doing the large test. This will
greatly affect your runtime, especially for the large files.
The memory movement of copying curr t into prev t at the end of every iteration can have
big consequences on the time it takes for the program to run. It would be more efficient if
you had a 3-D array t[2][N][N]. You could switch between t[0][N][N] and t[1][N][N] depending
which is the current or previous iteration.
If your sequential run for N = 256 maxIter = 4096 with input 1024.dat is taking longer than
10 minutes, reconsider your strategy.
3.1 MakeFile
You are instructed to use a MakeFile to compile the code in any way you like. An example
of how to use a MakeFile can be used here:
{make command } : { t a r g e t f i l e s }
{compile command}
g c c s e r i a l : hea t . c main−s e r i a l . c f i l e −r e a d e r . c
gcc −fopenmp hea t . c main−s e r i a l . c f i l e −r e a d e r . c −o
heat−omp−gcc −lm
Now, on the command line, if you type ‘make gccserial‘, the compile command is automatically
executed. It is worth noting, the compile command must be indented. The target files
are the files that must be present for the make command to execute.
This command may work for you and it may not. The point is to allow you to compile
however you like. If you want to declare the iterator in a for loop, you would have to add the
compiler flag −std=c99. −fopenmp is for the GNU compiler and −qopenmp is for the
Intel Compiler. If you find that the MakeFile is not working, please get in contact as soon
as possible.
Contact: h.j.forbes@liverpool.ac.uk
2023-2024 7University of Liverpool Assignment 2 Resit COMP528
4 Marking scheme
1 Code that compiles without errors or warnings 5%
2 Same numerical results for test cases (tested on CodeGrade) 30%
3 Speedup plot (clean plot, correct axes and explained) 10%
4 Strong scaling plot (clean plot, correct axes and explained) 10%
5 Scaling efficiency up to 32 threads (tests on Barkla yields good scaling
efficiency for 1 Rank with 1, 2, 4, 8, 16, 32 OMP threads)
10%
6 Scaling efficiency up to 32 ranks (tests on Barkla yields good scaling
efficiency for 1, 2, 4, 8, 16, 32 ranks with 1 OMP thread)
10%
7 Clean code and comments (clean, well structured readable cde) 10%
8 Report (explained parallel strategy and implementation for each code
produced, i.e. why certain decisions were made to gain performance such
as why certain OMP directives/MPI calls used)
15%
Table 1: Marking scheme
The purpose of this assessment is to develop your skills in analysing numerical programs
and developing parallel programs using OpenMP and MPI. This assessment accounts for
35% of your final mark, however as it is a resit you will be capped at 50% unless otherwise
stated by the Student Experience Team. Your work will be submitted to automatic
plagiarism/collusion detection systems, and those exceeding a threshold will be reported to
the Academic Integrity Officer for investigation regarding adhesion to the university’s policy
https://www.liverpool.ac.uk/media/livacuk/tqsd/code-of-practice-on-assessmen
t/appendix_L_cop_assess.pdf.
5 Deadline
The deadline is 23:59 GMT Friday the 2nd of August 2024. https://www.liverp
ool.ac.uk/aqsd/academic-codes-of-practice/code-of-practice-on-assessment/
2023-2024 8
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
辅导 ecos3010、讲解 java/pyt...
2024-09-07
辅导 data编程、讲解 python设...
2024-09-07
辅导 nur5000 theoretical bas...
2024-09-07
辅导 the impact of minimum w...
2024-09-07
讲解 marketing 301 fall 2024...
2024-09-07
讲解 marketing 301 fall 2024...
2024-09-07
辅导 environmental and natur...
2024-09-07
讲解 tcse1icb individual ass...
2024-09-07
讲解 principles of journalis...
2024-09-07
讲解 lngs1002 2024 assignmen...
2024-09-07
讲解 ece 498 ma: cmos ic des...
2024-09-07
讲解 opre 6369/mis 6369.0w1 ...
2024-09-07
辅导 cmn 4148a – communicat...
2024-09-07
讲解 22748 financial reporti...
2024-09-07
辅导 inft6201 – big data as...
2024-09-07
辅导 cse3smt software measur...
2024-09-07
辅导 corporate and internati...
2024-09-07
辅导 assessment 2 – group a...
2024-09-07
讲解 college writing extende...
2024-09-07
辅导 lin328 basic acoustics ...
2024-09-07
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!