A Prototype Finite Difference Model Presented by Timothy H. Kaiser, Ph.D. San Diego Supercomputer Center Presented by Timothy H. Kaiser, Ph.D. San Diego.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
NPACI Parallel Computing Institute August 19-23, 2002 San Diego Supercomputing Center S an D IEGO S UPERCOMPUTER C ENTER N ATIONAL P ARTNERSHIP FOR A DVANCED.
MPI version of the Serial Code With One-Dimensional Decomposition Presented by Timothy H. Kaiser, Ph.D. San Diego Supercomputer Center Presented by Timothy.
879 CISC Parallel Computation High Performance Fortran (HPF) Ibrahim Halil Saruhan Although the [Fortran] group broke new ground …
Programming Languages and Paradigms
Fortran Jordan Martin Steven Devine. Background Developed by IBM in the 1950s Designed for use in scientific and engineering fields Originally written.
S an D IEGO S UPERCOMPUTER C ENTER N ATIONAL P ARTNERSHIP FOR A DVANCED C OMPUTATIONAL I NFRASTRUCTURE NPACI Parallel Computing Seminars San Diego Supercomputing.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
A Discrete Adjoint-Based Approach for Optimization Problems on 3D Unstructured Meshes Dimitri J. Mavriplis Department of Mechanical Engineering University.
Chapter 7: User-Defined Functions II
Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Kernighan/Ritchie: Kelley/Pohl:
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
CS 584. Review n Systems of equations and finite element methods are related.
CIS 101: Computer Programming and Problem Solving Lecture 9 Usman Roshan Department of Computer Science NJIT.
Pointers and dynamic objects COMP171 Fall Pointers and dynamic objects/ Slide 2 Topics * Pointers n Memory addresses n Declaration n Dereferencing.
Introduction to Fortran Fortran Evolution Drawbacks of FORTRAN 77 Fortran 90 New features Advantages of Additions.
1 CS 201 Passing Function as Parameter & Array Debzani Deb.
Fortran 9x HTML version. New F90 features Free source form Modules User-defined data types and operators Generic user-defined procedures Interface blocks.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software.
C++ for Engineers and Scientists Third Edition
Pointers Applications
ME 595M J.Murthy1 ME 595M: Computational Methods for Nanoscale Thermal Transport Lecture 9: Boundary Conditions, BTE Code J. Murthy Purdue University.
Chapter 13 Finite Difference Methods: Outline Solving ordinary and partial differential equations Finite difference methods (FDM) vs Finite Element Methods.
Finite element method 1 Finite Elements  Basic formulation  Basis functions  Stiffness matrix  Poisson‘s equation  Regular grid  Boundary conditions.
Language Evaluation Criteria
Guidelines for the CMM coding project 5 October 2006 (or, “How to make your life easier in the long run”)
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Multi-Dimensional Arrays
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Simple Procedural Languages: FORTRAN and C Lecture 9: Dolores Zage.
Runtime Environments Compiler Construction Chapter 7.
Scientific Computing Partial Differential Equations Poisson Equation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Parallel Programming in C with MPI and OpenMP Michael J. Quinn.
Scientific Computing Division A tutorial Introduction to Fortran Siddhartha Ghosh Consulting Services Group.
FORTRAN FORmula TRANslator -Anand Trivedi. HISTORY  Designed and written from scratch in by an IBM team lead by John W. Backus as the first.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
Sept COMP60611 Fundamentals of Concurrency Lab Exercise 2 Notes Notes on the finite difference performance model example – for the lab… Graham Riley,
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Model Task 0A: Programming the 1D upstream scheme ATM 562 Fall 2015 Fovell 1.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
Manno, , © by Supercomputing Systems 1 1 COSMO - Dynamical Core Rewrite Approach, Rewrite and Status Tobias Gysi POMPA Workshop, Manno,
CS 261 – Data Structures Introduction to C Programming.
NCEP ESMF GFS Global Spectral Forecast Model Weiyu Yang, Mike Young and Joe Sela ESMF Community Meeting MIT, Cambridge, MA July 21, 2005.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
Darryl Michael/GE CRD Fields and Waves Lesson 3.6 ELECTROSTATICS - Numerical Simulation.
Discretization Methods Chapter 2. Training Manual May 15, 2001 Inventory # Discretization Methods Topics Equations and The Goal Brief overview.
Assembly - Arrays תרגול 7 מערכים.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 Data Structures and Algorithms Outline This topic will describe: –The concrete data structures that can be used to store information –The basic forms.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
Programming assignment # 3 Numerical Methods for PDEs Spring 2007 Jim E. Jones.
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
User-Written Functions
Laplace Transforms Chapter 3 Standard notation in dynamics and control
High Altitude Low Opening?
Programming assignment #1. Solutions and Discussion
Code-Based Sensitivities for Verification and Validation
C Passing arrays to a Function
Two Dimensional Arrays
Finite Elements Basic formulation Basis functions Stiffness matrix
Binding Times Binding is an association between two things Examples:
Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.
Finite Element Modelling in Geosciences FEM in 2D for viscous materials Introduction to Finite Element Modelling in Geosciences Summer 2018.
Presentation transcript:

A Prototype Finite Difference Model Presented by Timothy H. Kaiser, Ph.D. San Diego Supercomputer Center Presented by Timothy H. Kaiser, Ph.D. San Diego Supercomputer Center

2 A Prototype Model We will introduce a finite difference model that will serve to demonstrate what a computational scientist needs to do to take advantage of Distributed Memory computers using MPI The model we are using is a two dimensional solution to a model problem for Ocean Circulation, the Stommel Model Examples –peloton.sdsc.edu/~tkaiser/mpi_stuff/workshop/stommel

3 The Stommel Problem Wind-driven circulation in a homogeneous rectangular ocean under the influence of surface winds, linearized bottom friction, flat bottom and Coriolis force. Solution: intense crowding of streamlines towards the western boundary caused by the variation of the Coriolis parameter with latitude

4 )9( 10 )11( )6( )sin( ) (                           Km y L x L 2L y f f x yx y Governing Equations Model Constants

5 The steady state solution

6 )1( )1(, ,1,0,, ,1,0, bygiven),(pointsofconsistinggridaDefine     nyLy nxLx ny+1jyjy nx+1ixix yx y x j i ji Domain Discretization

7 ),(, :),(pointsat)y,( j j y i x ji yxx jii         Seek to find an approximate solution

8 Centered Finite Difference Scheme for the Derivative Operators

9 Governing Equation Finite Difference Form

10         i, j i, j-1 i+1, ji-1, j i, j+1 interior grid points: i=1,nx; j=1,ny boundary points: (i,0) & (i,ny+1) ; i=1,nx (0,j) & (nx+1,j) ; j=1,ny Five-point Stencil Approximation for the Discrete Stommel Model

11 Start with an initial guess for do i = 1, nx; j = 1, ny end do Copy Repeat the process Jacobi Iteration

12 A Prototype Finite Difference Model (Philosophy)

13 Overview Model written in Fortran 90 Uses many new features of F90 –Free format –Modules instead of commons –Module with kind precision facility –Interfaces –Allocatable arrays –Array syntax

14 Free Format Statements can begin in any column ! Starts a comment To continue a line use a “&” on the line to be continued

15 module constants real dx,dy,a1,a2,a3,a4,a5,a6 end module … program stommel use constants … end program subroutine jacobi use constants … end subroutine jacobi Modules instead of commons Modules have a name and can be used in place of named commons Modules are defined outside of other subroutines To “include” the variables from a module in a routine you “use” it The main routine stommel and subroutine jacobi share the variables in module “constants”

16 module numz integer,parameter::b8=selected_real_kind(14) end module program stommel use numz real(b8) x,y x=1.0_b8... Instead of declaring variables real*8 x,y We use real(b8) x,y Where b8 is a constant defined within a module Kind precision facility

17 Kind precision facility Why? Legality Portability Reproducibility Modifiability real*8 x,y is not legal syntax in Fortran 90 Declaring variables “double precision” will give us 16 byte reals on some machines integer,parameter::b8=selected_real_kind(14) real(b8) x,y x=1.0_b8

18 real(b8),allocatable::psi(:,:) ! our calculation grid real(b8),allocatable::new_psi(:,:) ! temp storage for the grid ! allocate the grid to size nx * ny plus the boundary cells allocate(psi(0:nx+1,0:ny+1)) allocate(new_psi(0:nx+1,0:ny+1)) Allocatable arrays We can declare arrays to be allocatable Allows dynamic memory allocation Define the size of arrays at run time

19 module face interface bc subroutine bc (psi,i1,i2,j1,j2) use numz real(b8),dimension(i1:i2,j1:j2):: psi integer,intent(in):: i1,i2,j1,j2 end subroutine end interface end module program stommel use face... Interfaces Similar to C prototypes Can be part of the routines or put in a module Provides information to the compiler for optimization Allows type checking

20 Allows assignments of arrays without do loops ! allocate the grid to size nx * ny plus the boundary cells allocate(psi(0:nx+1,0:ny+1)) allocate(new_psi(0:nx+1,0:ny+1)) ! set initial guess for the value of the grid psi=1.0_b8 ! copy from temp to main grid psi(i1:i2,j1:j2)=new_psi(i1:i2,j1:j2) Array Syntax

21 Program Outline (1) Module NUMZ - defines the basic real type as 8 bytes Module INPUT - contains the inputs –nx,ny (Number of cells in the grid) –lx,ly (Physical size of the grid) –alpha,beta,gamma (Input calculation constants) –steps (Number of Jacobi iterations) Module Constants - contains the invariants of the calculation

22 Program Outline (2) Module face - contains the interfaces for the subroutines –bc - boundary conditions –do_jacobi - Jacobi iterations –force - right hand side of the differential equation –Write_grid - writes the grid

23 Program Outline (3) Main Program –Get the input –Allocate the grid to size nx * ny plus the boundary cells –Calculate the constants for the calculations –Set initial guess for the value of the grid –Set boundary conditions using –Do the jacobi iterations –Write out the final grid

24 C version considerations To simulate the F90 numerical precision facility we: –#define FLT double –And use FLT as our real data type throughout the rest of the program We desire flexibility in defining our arrays and matrices –Arbitrary starting indices –Contiguous blocks of memory for 2d arrays –Use routines based on Numerical Recipes in C

25 Vector allocation routine FLT *vector(INT nl, INT nh) { /* creates a vector with bounds vector[nl:nh]] */ FLT *v; /* allocate the space */ v=(FLT *)malloc((unsigned) (nh-nl+1)*sizeof(FLT)); if (!v) { printf("allocation failure in vector()\n"); exit(1); } /* return a value offset by nl */ return v-nl; }

26 Matrix allocation routine FLT **matrix(INT nrl,INT nrh,INT ncl,INT nch) /* creates a matrix with bounds matrix[nrl:nrh][ncl:nch] */ /* modified from the book version to return contiguous space */ { INT i; FLT **m; /* allocate an array of pointers */ m=(FLT **) malloc((unsigned) (nrh-nrl+1)*sizeof(FLT*)); if (!m){ printf("allocation failure 1 in matrix()\n"); exit(1);} m -= nrl; /* offset the array of pointers by nrl */ for(i=nrl;i<=nrh;i++) { if(i == nrl){ /* allocate a contiguous block of memroy*/ m[i]=(FLT *) malloc((unsigned) (nrh-nrl+1)*(nch-ncl+1)*sizeof(FLT)); if (!m[i]){ printf("allocation failure 2 in matrix()\n");exit(1); } m[i] -= ncl; /* first pointer points to beginning of the block */ } else { m[i]=m[i-1]+(nch-ncl+1); /* rest of pointers are offset by stride */ } return m; }