编程代写 CS402 Coursework 2

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.
Getting Started
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 a Makefile.

Copyright By PowCoder代写 加微信 powcoder

To compile karman type:
module load cs402-mpi
make CC=mpicc
at the command line, and the executable will be generated.
Output of the program in the normal way, and karman will generate a default problem and solve it, writing the final solution out to the file karman.bin.
Karman options
The complete set of options that karman supports can be printed out using the following command.
./karman –help
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 direction
-y, –jmax=JMAX direction
-t, –t-end=TEND
-d, –del-t=DELT
-i, –infile=FILE
Set the number of interior cells in the X
Set the number of interior cells in the Y
Set the simulation end time
Set the simulation timestep size
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 you prefer.
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 parallel solution:

./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 using:
make clean all
When you run the program it will generate profiling information to gmon.out, this can be viewed using the command:
gprof ./karman
this generates a sorted list of the execution time spent in each function.
another way to profile the code:
gcc -pg filename.c -c
gcc filename.o -pg -o filename
./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/ OR 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.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com