Domain Decomposition: Computational Fluid Dynamics

Similar documents
Domain Decomposition: Computational Fluid Dynamics

Domain Decomposition: Computational Fluid Dynamics

CFD exercise. Regular domain decomposition

Parallel Programming with Fortran Coarrays: Exercises

MPI Casestudy: Parallel Image Processing

Sharpen Exercise: Using HPC resources and running parallel applications

Image Sharpening. Practical Introduction to HPC Exercise. Instructions for Cirrus Tier-2 System

Sharpen Exercise: Using HPC resources and running parallel applications

Driven Cavity Example

PROGRAMMING MODEL EXAMPLES

Backward facing step Homework. Department of Fluid Mechanics. For Personal Use. Budapest University of Technology and Economics. Budapest, 2010 autumn

OO Fortran Exercises

Batch Systems. Running calculations on HPC resources

Distributed Memory Programming With MPI Computer Lab Exercises

Numerical Modelling in Fortran: day 6. Paul Tackley, 2017

Advanced Fortran Programming

Shared Memory Programming With OpenMP Computer Lab Exercises

Xeon Phi Native Mode - Sharpen Exercise

Sequence Alignment. Practical Introduction to HPC Exercise

Xeon Phi Native Mode - Sharpen Exercise

FLUENT Secondary flow in a teacup Author: John M. Cimbala, Penn State University Latest revision: 26 January 2016

Shared Memory Programming With OpenMP Exercise Instructions

Appendix: To be performed during the lab session

computational Fluid Dynamics - Prof. V. Esfahanian

Simulation of Turbulent Flow around an Airfoil

Homework # 2 Due: October 6. Programming Multiprocessors: Parallelism, Communication, and Synchronization

Batch Systems & Parallel Application Launchers Running your jobs on an HPC machine

Performance Engineering: Lab Session

HPC Fall 2007 Project 3 2D Steady-State Heat Distribution Problem with MPI

1.2 Numerical Solutions of Flow Problems

Introduction to Molecular Dynamics on ARCHER: Instructions for running parallel jobs on ARCHER

Flow and Heat Transfer in a Mixing Elbow

First steps on using an HPC service ARCHER

Practical: a sample code

Introduction to CFX. Workshop 2. Transonic Flow Over a NACA 0012 Airfoil. WS2-1. ANSYS, Inc. Proprietary 2009 ANSYS, Inc. All rights reserved.

MPI Case Study. Fabio Affinito. April 24, 2012

VIRTUAL INSTITUTE HIGH PRODUCTIVITY SUPERCOMPUTING. BSC Tools Hands-On. Germán Llort, Judit Giménez. Barcelona Supercomputing Center

Computational Study of Laminar Flowfield around a Square Cylinder using Ansys Fluent

Pressure Correction Scheme for Incompressible Fluid Flow

The Vibrating String

Module D: Laminar Flow over a Flat Plate

CSC Summer School in HIGH-PERFORMANCE COMPUTING

Numerical Modelling in Fortran: day 7. Paul Tackley, 2017

Stream Function-Vorticity CFD Solver MAE 6263

MIC Lab Parallel Computing on Stampede

CMSC 714 Lecture 6 MPI vs. OpenMP and OpenACC. Guest Lecturer: Sukhyun Song (original slides by Alan Sussman)

High Performance Computing

Compiling applications for the Cray XC

Supercomputing in Plain English Exercise #6: MPI Point to Point

Tutorial 1. Introduction to Using FLUENT: Fluid Flow and Heat Transfer in a Mixing Elbow

Introduction to OpenMP. Lecture 2: OpenMP fundamentals

Parallel Programming Patterns. Overview and Concepts

Our Workshop Environment

ARCHER ecse Technical Report. Algorithmic Enhancements to the Solvaware Package for the Analysis of Hydration. 4 Technical Report (publishable)

CSCS Proposal writing webinar Technical review. 12th April 2015 CSCS

CSC Summer School in HIGH-PERFORMANCE COMPUTING

MPI Lab. How to split a problem across multiple processors Broadcasting input to other nodes Using MPI_Reduce to accumulate partial sums

Homework # 1 Due: Feb 23. Multicore Programming: An Introduction

Foster s Methodology: Application Examples

Optimising the Mantevo benchmark suite for multi- and many-core architectures

Exercises: Message-Passing Programming

Advanced Parallel Programming

Molecular Dynamics Simulations with Julia

Migrating A Scientific Application from MPI to Coarrays. John Ashby and John Reid HPCx Consortium Rutherford Appleton Laboratory STFC UK

Fractals exercise. Investigating task farms and load imbalance

HPC Fall 2010 Final Project 3 2D Steady-State Heat Distribution with MPI

Vectorization Lab Parallel Computing at TACC: Ranger to Stampede Transition

NUMERICAL 3D TRANSONIC FLOW SIMULATION OVER A WING

Fractals. Investigating task farms and load imbalance

Transactions on Information and Communications Technologies vol 3, 1993 WIT Press, ISSN

Shifter on Blue Waters

ENERGY-224 Reservoir Simulation Project Report. Ala Alzayer

Acknowledgements. Prof. Dan Negrut Prof. Darryl Thelen Prof. Michael Zinn. SBEL Colleagues: Hammad Mazar, Toby Heyn, Manoj Kumar

Problem description. The FCBI-C element is used in the fluid part of the model.

TUTORIAL#3. Marek Jaszczur. Boundary Layer on a Flat Plate W1-1 AGH 2018/2019

Introduction to ANSYS DesignXplorer

Message Passing Programming. Designing MPI Applications

Radial Basis Function-Generated Finite Differences (RBF-FD): New Opportunities for Applications in Scientific Computing

PPCES 2016: MPI Lab March 2016 Hristo Iliev, Portions thanks to: Christian Iwainsky, Sandra Wienke

Simulation and Validation of Turbulent Pipe Flows

Development of a Maxwell Equation Solver for Application to Two Fluid Plasma Models. C. Aberle, A. Hakim, and U. Shumlak

µ = Pa s m 3 The Reynolds number based on hydraulic diameter, D h = 2W h/(w + h) = 3.2 mm for the main inlet duct is = 359

Programming II (CS300)

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3

In this problem, we will demonstrate the following topics:

Introduction to ANSYS CFX

Point-to-Point Synchronisation on Shared Memory Architectures

Verification of Laminar and Validation of Turbulent Pipe Flows

An Introduction to SolidWorks Flow Simulation 2010

Domain Decomposition for Colloid Clusters. Pedro Fernando Gómez Fernández

Parallel DelPhi95 v5.1 User Guide

DDT: A visual, parallel debugger on Ra

2 T. x + 2 T. , T( x, y = 0) = T 1

Numerical Methods for (Time-Dependent) HJ PDEs

CCD Report Cross Platform Design Simulation and Automation

ParaTools ThreadSpotter Analysis of HELIOS

Possibility of Implicit LES for Two-Dimensional Incompressible Lid-Driven Cavity Flow Based on COMSOL Multiphysics

Wired and Wireless Parallel Simulation of Fluid Flow Problem on Heterogeneous Network Cluster

Practical Introduction to Message-Passing Interface (MPI)

lslogin3$ cd lslogin3$ tar -xvf ~train00/mpibasic_lab.tar cd mpibasic_lab/pi cd mpibasic_lab/decomp1d

Transcription:

Domain Decomposition: Computational Fluid Dynamics July 11, 2016 1 Introduction and Aims This exercise takes an example from one of the most common applications of HPC resources: Fluid Dynamics. We will look at how a simple fluid dynamics problem can be run on a system like ARCHER and how varying the number of processes it runs on and the problem size affect the performance of the code. This will require a set of simulations to be run and performance metrics to be recorded and plotted on a graph. The CFD program differs from the more straightforward task farm in that the problem requires more than source-worker-sink communications. Here the workers are in regular communication throughout the calculation. This exercise aims to introduce: Grids Communications Halos Performance metrics 2 Fluid Dynamics Fluid Dynamics is the study of the mechanics of fluid flow, liquids and gases in motion. This encompasses aero- and hydrodynamics. It has wide ranging applications, from theoretical studies of flow to engineering problems such as vessel and structure design, and plays an important role in weather modelling. Simulating and solving fluid dynamic problems requires large computational resources. Fluid dynamics is an example of continuous system which can be described by Partial Differential Equations. For a computer to simulate these systems, the equations must be discretised onto a grid. If this grid is regular, then a finite difference approach can be used. Using this method means that the value at any point in the grid is updated using some combination of the neighbouring points. Discretisation is the process of approximating a continuous (i.e. infinite-dimensional) problem by a finite-dimensional problem suitable for a computer. This is often accomplished by putting the calculations into a grid or similar construct. 2.1 The Problem In this exercise the finite difference approach is used to determine the flow pattern of a fluid in a cavity. For simplicity, the liquid is assumed to have zero viscosity which implies that there can be no vortices (i.e. no whirlpools) in the flow. The cavity is a square box with an inlet on one side and an outlet on another as shown below. 1

Figure 1: The Cavity 2.2 Mathematical formulation and the Jacobi algorithm solution In two dimensions it is easiest to work with the stream function Ψ (see below for how this relates to the fluid velocity). For zero viscosity Ψ satisfies the following equation: The finite difference version of this equation is: 2 Ψ = 2 Ψ x 2 + 2 Ψ y 2 = 0 Ψ i 1,j + Ψ i+1,j + Ψ i,j 1 + Ψ i,j+1 4Ψ i,j = 0 With the boundary values fixed, the stream function can be calculated for each point in the grid by averaging the value at that point with its four nearest neighbours. The process continues until the algorithm converges on a solution which stays unchanged by the averaging process. This simple approach to solving a PDE is called the Jacobi Algorithm. In order to obtain the flow pattern of the fluid in the cavity we want to compute the velocity field ũ. The x and y components of ũ are related to the stream function by u x = Ψ y = 1 2 (Ψ i,j+1 Ψ i,j 1 ) u y = Ψ x = 1 2 (Ψ i+1,j Ψ i 1,j ) This means that the velocity of the fluid at each grid point can also be calculated from the surrounding grid points. 2

2.3 Pseudocode for the Jacobi algorithm The outline of the algorithm for calculating the velocities is as follows: Set the boundary values for Ψ and ũ while (convergence= FALSE) do for each interior grid point do update value of Ψ by averaging with its 4 nearest neighbours end do check for convergence end do for each interior grid point do calculate u x calculate u y end do For simplicity, here we simply run the calculation for a fixed number of iterations; a real simulation would continue until some chosen accuracy was achieved. 2.4 Breaking up the problem to solve it in parallel The calculation of the velocity of the fluid as it flows through the cavity proceeds in two stages: Calculate the stream function Ψ. Use this to calculate the x and y components of the velocity. Both of these stages involve calculating the value at each grid point by combining it with the value of its four nearest neighbours. Thus the same amount of work is involved in calculating each grid point, making it ideal for the regular domain decomposition approach. Figure 2 shows how a two-dimensional grid can be broken up into smaller grids to be handled by individual processes. Figure 2: Breaking up the problem through domain decomposition This approach can be generalised to include cases where slices or irregular subsections of grids are sent to individual processes and the results are collated at the end of a calculation cycle. 3

2.5 Communicating through Halo swaps Figure 3: Halo: Process A and Process B Splitting the grid into smaller grids introduces a problem computating values at points on the edges of subgrids, as this requires the values of neighbouring points, which are part of a neighbouring subgrid whose values are being computed by a different process. This means that some form of communication between processes is needed. One way to tackle this problem is to add a boundary layer to each edge of each subgrid that adjoins another subgrid. These boundary layers are not updated by the local process updating the interior points of the subgrid, but instead by the process working on the neighbouring subgrid. The boundary layer in the neighbouring subgrid is in turn updated by the local process. These boundary layers are generally known as halos. An example of this is show in Figure 3. In order to keep the halos up to date, a halo swap must be carried out. When an element in process B which adjoins the boundary layer with process A is updated and process A has been updating, the halo must be swapped to ensure process B uses accurate data. This means that a communication between processes must take place in order to swap the boundary data. This halo swap introduces communications which, if the grid is split into too many processes or the size of data transfers is very large, can begin to dominate the runtime instead of actual processing work. Part of this exercise is to look at how the number of processes affects the runtime for given problem sizes, and evaluate what this means for speed up and efficiency. 2.6 One-dimensional Domain decomposition for CFD example In the parallel version of the code provided for this exercise (F-MPI) we have only decomposed the problem in one dimension, namely the y-dimension. This means that the problem is sliced up into a series of rectangular strips. Although for a real problem the domain would probably be split up in both dimensions as in Figure 2, splitting across a single dimension makes programming and understanding the code significantly easier. Each process only needs to communicate with a maximum of two neighbours, swapping halo data up and down. 4

3 Exercises 3.1 Compilation Use wget to copy the file cfd.tar.gz from the ARCHER web page for the course to your personal directory on /work/ on ARCHER, as you did for the previous exercises. Now unpack the file and compile the Fortran code provided for the CFD example as described below. We have provided a serial version of the code (directory F-SER) as well as a parallel version of the code using the domain decomposition approach and MPI for halo swap communications as described above (directory F-MPI). After compilation an executable file called cfd will have been created in each case. guestxx@archer :~ > t a r z xvf c f d. t a r. gz c f d / c f d / F MPI / c f d / F SER / c f d / F SER / boundary. f90 c f d / F SER / c f d. f90 c f d / F SER / c f d. pbs c f d / F SER / c f d i o. f90 c f d / F SER / j a c o b i. f90 c f d / F SER / M a k e f i l e c f d / F MPI / boundary. f90 c f d / F MPI / c f d. f90 c f d / F MPI / c f d. pbs c f d / F MPI / c f d i o. f90 c f d / F MPI / j a c o b i. f90 c f d / F MPI / M a k e f i l e guestxx@archer :~ > cd c f d / F SER guestxx@archer : ~ / c f d / F SER> make f t n g c boundary. f90 f t n g c j a c o b i. f90 f t n g c c f d i o. f90 f t n g c c f d. f90 f t n g o c f d boundary. o c f d. o c f d i o. o j a c o b i. o guestxx@archer : ~ / c f d / F SER> cd. /.. / F MPI guestxx@archer : ~ / c f d / F MPI> make f t n g c boundary. f90 f t n g c j a c o b i. f90 f t n g c c f d i o. f90 f t n g c c f d. f90 f t n g o c f d boundary. o c f d. o c f d i o. o j a c o b i. o 3.2 Run the program 3.2.1 Running in serial As long as you do not run for longer than a minute, say, you can execute the serial executable on the login node directly from the command line as follows: guestxx@archer : ~ / c f d / F SER>. / c f d < s c a l e > < numiter > where you should replace <scale> and <numiter> by integers that have the following meaning: <scale>: a scale factor that is used to set the size of the grid (see below) 5

<numiter>: how many iterations to run the Jacobi algorithm for. The mimimum problem size (scale factor = 1) is taken as a 32 32 grid. The actual problem size can be chosen by scaling this basic size, for example with a scale factor of 4 then it will use a 128 128 grid. After the executable has finished running the output on screen should look something like this (depending on the exact parameters):. / c f d 4 5000 S c a l e f a c t o r = 4, i t e r a t i o n s = 5000 I r r o t a t i o n a l flow Running CFD on 128 x 128 g r i d i n s e r i a l S t a r t i n g main l oop... completed i t e r a t i o n 1000 completed i t e r a t i o n 2000 completed i t e r a t i o n 3000 completed i t e r a t i o n 4000 completed i t e r a t i o n 5000... f i n i s h e d A f t e r 5000 i t e r a t i o n s, e r r o r i s 0.1872E 03 Time f o r 5000 i t e r a t i o n s was 0.3136 s e c o n d s Each i n d i v i d u a l i t e r a t i o n took 0.6273E 04 s e c o n d s W r i t i n g o u t p u t f i l e...... f i n i s h e d CFD completed The code also produces some graphical output in the form of a gnuplot file cfd.plt. Provided you have logged in to ARCHER with X11 forwarding turned on (ssh -X from the command line) you can view this as follows: guestxx@archer :~ > g n u p l o t p e r s i s t c f d. p l t which should produce a picture similar to Figure 4. 6

Figure 4: Output Image If the fluid is flowing down the right-hand edge then along the bottom, rather than through the middle of the cavity, then this is an indication that the Jacobi algorithm has not yet converged. Convergence requires more iterations on larger problem sizes. 3.2.2 Running in parallel Use emacs or your preferred editor to look at the cfd.pbs batch script inside the F-MPI directory: #! / b i n / bash l o g i n #PBS l s e l e c t =1 #PBS l w a l l t i m e = 0 0 : 0 5 : 0 0 #PBS A y14 #PBS N c f d # Change t o d i r e c t o r y t h a t t h e j o b was s u b m i t t e d from cd $PBS_O_WORKDIR aprun n 4. / c f d 4 5000 The argument to aprun has the following meaning: -n 4: run the code on 4 processes; The arguments to cfd are the same as in the serial case, with the scale factor now setting the size of the overall grid (which will be decomposed into smaller subgrids). Varying the number of processes and scale factor allows us to investigate Amdahl s and Gustafson s laws. The number of iterations is not particularly important as we are interested in the time per iteration. You can increase the number of iterations to ensure that the code does not run too fast on large numbers of processes, or decrease it so it is not too slow for large problem sizes. Two things to note: The code assumes the problem size decomposes exactly onto the process grid. If this is not the case (e.g. scale factor = 2 with 7 processes, since 7 is not a divisor of 64) it will complain and exit. 7

Again if the output picture looks strange then you may not have used a sufficient number of iterations to converge to the solution. This is not a problem in terms of the performance figures, but it is worth running with more iterations just to check that the code is functioning correctly Once you have run the job via the PBS batch system, the output file should look something like this (depending on the exact parameters): S c a l e f a c t o r = 4, i t e r a t i o n s = 5000 I r r o t a t i o n a l flow Running CFD on 128 x 128 g r i d u s i n g 4 p r o c e s s ( es ) S t a r t i n g main l oop... completed i t e r a t i o n 1000 completed i t e r a t i o n 2000 completed i t e r a t i o n 3000 completed i t e r a t i o n 4000 completed i t e r a t i o n 5000... f i n i s h e d A f t e r 5000 i t e r a t i o n s, e r r o r i s 0.1872E 03 Time f o r 5000 i t e r a t i o n s was 0.1763 s e c o n d s Each i n d i v i d u a l i t e r a t i o n took 0.3527E 04 s e c o n d s W r i t i n g o u t p u t f i l e...... f i n i s h e d CFD completed 3.3 Performance Evaluation The next part of this exercise will be to determine what the best configuration for a group of problems sizes in the CFD code would be. This will be worked out using two measures: speed-up and efficiency. 3.3.1 Speedup The speedup of a parallel code is how much faster the parallel version runs compared to a non-parallel version. Taking the time to run the code on 1 process is T 1 and to run the code on P processes is T P, the speed-up S is found by: S = T 1 T P (1) 3.3.2 Efficiency Efficiency is how the well the resources (available processing power in this case) are being used. This can be thought of as the speed-up (or slow-down) per process. Efficiency E can be defined as: where E = 1.0 means 100% efficiency, i.e. perfect scaling. E = S P = T 1 P T P (2) 8

3.3.3 Doing The Work The two main evaluation points: How do the speed-up and efficiency of the program vary as the number of processes is increased? Does this change as the problem size is varied? To investigate the speed-up and parallel efficiency the code should be run using the same problem size but with varying numbers of processes. Calculate the speed-up and efficiency (tables are provided overleaf for this) and plot a graph of the speed-up against the number of processes. Is there any apparent pattern, e.g. does it follow Amdahl s law? Now choose a different problem size and repeat the exercise. To increase the problem size increase the scale factor; to decrease the size, decrease the scale factor. For example, setting scale factor = 2 will give a problem size of 64x64; scale factor = 6 gives a size of 192x192. What is the effect of problem size the parallel scaling of the code? Note that, for large numbers of processes, you may have to increase the number of iterations so that the code runs for a reasonable length of time it is difficult to interpet timings quantitatively if a program runs too quickly, e.g. for much less than a second. The time per iteration, however, should be independent of the number of iterations. 9

1. problem size (scalefactor) = iterations = No of processes Time per iteration Speed-Up Efficiency 1 2 4 8 16 32 64 128 2. problem size (scalefactor) = iterations = No of processes Time per iteration Speed-Up Efficiency 1 2 4 8 16 32 64 128 3. problem size (scalefactor) = iterations = No of processes Time per iteration Speed-up Efficiency 1 2 4 8 16 32 64 128 4. problem size (scalefactor) = iterations = No of processes Time per iteration Speed-up Efficiency 1 2 4 8 16 32 64 128 10

4 Compiler Investigation We will use the CFD example to investigate how different compilers and options affect performance. 4.1 Changing compilers on ARCHER On ARCHER, the Fortran compiler is always called ftn. However, what compiler this actually points to is determined by what module you have loaded. For example, to switch from the default (Cray) compiler to the Intel compiler. guestxx@archer:~> module switch PrgEnv-cray PrgEnv-intel guestxx@archer:~> make clean guestxx@archer:~> make Here. make clean ensures that all compiled code is removed which means that the new code will be built with the new compiler. Note that this also removes output files velocity.dat, colourmap.dat, and cfd.plt, so if you wish to keep these you should rename them. The GNU compiler module is called PrgEnv-gnu. 4.2 Exercises Here are a number of suggestions: By default, the code is built with the -g debugging option. Edit the Makefile to remove this and recompile - what is the effect on performance? What is the difference between the performance of the code using the three different compilers (Cray, Intel and GNU) with no compiler options? It is not really fair to compare compiler performance using default options: one compiler may simply have higher default settings than another. Using the option suggested in Useful compiler options at http://www.archer.ac.uk/documentation/user-guide/development.php, compare the best performance you can get with each compiler. The code can actually simulate fluids with a finite viscosity. You can pass a third parameter to the program, the Reynolds NumberRe, which here is effectively the input velocity of the fluid. For example, aprun -n 4./cfd 4 5000 1.8 sets Re = 1.8 (note that the code becomes unstable for values of Re > 3.7). This increases the computation required so the code will be slower, although the actual amount of computation is independent of the value of Re. Investigate the parallel scaling behaviour of the code for some particular value of Re. Is it any different from the previous (zero viscosity) case? 11

Figure 5: Simulation with Re = 1.8 12