Guide of CS402 Coursework 2
This coursework will be based on a different program, karman, which
solves the Navier-Stokes equations on a structured grid.
Download a copy of karman zip file from the CS402 web page. Copy the
zip file to Kudu and unzip it. Inside the downloaded folder there is
To compile karman type:
module load cs402-mpi
at the command line, and the executable will be generated.
Output of Karman
Run the program in the normal way, and karman will generate a default
problem and solve it, writing the final solution out to the file
The complete set of options that karman supports can be printed out
using the following command.
karman. A simple computational fluid dynamics tutorial.
Usage: ./karman [OPTIONS]...
-h, --help Print a summary of the options
-V, --version Print the version number
-v, --verbose=LEVEL Set the verbosity level. 0 is silent
-x, --imax=IMAX Set the number of interior cells in the X
-y, --jmax=JMAX Set the number of interior cells in the Y
-t, --t-end=TEND Set the simulation end time
-d, --del-t=DELT Set the simulation timestep size
-i, --infile=FILE Read the initial simulation state from this
(default is 'karman.bin')
-o, --outfile=FILE Write the final simulation state to this file
(default is 'karman.bin')
View the karman solution
You can take a look at the solution by using the bin2pmm program
built as part of the karman build process. The program works using
standard input and output streams, so you need to run it like this:
./bin2ppm < karman.bin > karman.ppm
The ppm file should be viewable in any standard Unix image viewer,
but you can use the program ppm2jpeg to convert it to a JPEG file if
Check the correctness of your parallel program
Once you start adding some code to karman, it's important that you
check your results. You can do this with the diffbin program, that
compares the final solution from the vanilla karman to your new
./diffbin karman.vanilla.bin karman.bin
Note: Remember to rename the karman.bin file when you are doing
multiple runs, otherwise it will be overwritten.
Change the problem size
You may want to check whether a larger problem size will give you
better performance improvements. To create a bigger problem in
karman, use the -x and -y flags to increase the number of cells in
the X and Y dimensions.
Profiling the code
To profile the code you will need to modify the makefile so that
CFLAGS has a -pg at the end of it. This will instruct the profiler
gprof to record timing behaviour for the main routines in the code.
Once you have changed the makefile then you need to rebuild the code
make clean all
When you run the program it will generate profiling information to
gmon.out, this can be viewed using the command:
this generates a sorted list of the execution time spent in each
another way to profile the code:
gcc -pg filename.c -c
gcc filename.o -pg -o filename
gprof filename > filename.gprof
This should give you a good idea as to where the majority of the
runtime is spent. This is where you should focus your attention when
thinking about parallelizing the code. We suggest you start your
parallelisation of the program from the main computational part.
The Main Loop
The timestep loop proceeds as follows:
- Calculate an appropriate time-step size.
- For each cell, compute a tentative new velocity based on the
previous velocity and the stencil velocity values.
- For each cell, calculate the RHS of the pressure equation.
- For the entire pressure matrix, use Red/Black SOR to solve the
Poisson equation. This takes a large number of iterations of
the Red/Black process.
- For each cell, update the real velocity values based on the
pressure matrix and the tentative velocity values.
- Update the boundary velocities. 学霸联盟