Computational Techniques I
|
|
- Dennis Peters
- 5 years ago
- Views:
Transcription
1 Computational Techniques I Course Zero Madrid Alicia Palacios, alicia.palacios@uam.es Cristina Sanz Sanz, cristina.sanz@uam.es
2 Outline 1. Introduction: how to run, input 2. Data types 3. Declaration statement 4. Arrays and matrices 5. Operators 6. Input/output statements 7. Formatted variables 8. Program control: IF statements and DO loops 9. Indexed variables 10. Subprograms 11. Libraries 12. Makefiles
3 9) Working with indexed variables:
4 Index variables: Reading and writing Element by element: 1) In line: read(15,*) a(1,1),a(1,2),a(1,3),a(2,1),a(2,2),a(2,3) 2) Using a do cycle: do 10 i = 1, n do 20 j = 1, m read(15,*) a(i,j) 20 end do 10 end do
5 Index variables: Reading and writing By rows or columns: 1) Using implicit do-cycles: do i = 1, n read(15,*) (a(i,j), j = 1, m)! implicit do-cycles end do 2) Direct read: do i = 1, n read(15,*) a(i,:)! reads as many as its dimension end do
6 Index variables: Reading and writing By blocks: 1) Using implicit do-cycles: read(15,*) ((a(i,j), j = 1, m), i= 1, n) 2) Direct read: read(15,*) a(:,:) The same can be used for the write directive
7 Index variables: Reading and writing Element by element Input files: input.dat input2.dat Output of program:
8 Index variables: Reading and writing By rows or columns or blocks Input file: input3.dat Output of program:
9 Index variables: Reading and writing Blocks with implicit do s Input file: input3.dat Output of program:
10 Index variables: Reading and writing In classroom practice 1 (10 minutes) 1) Using the input files input1.dat, input2.dat, input5.dat practice the reading and writing directives. 2) Try the different forms of reading/writting to learn the subtle differences between them. 3) Using input3.dat and the direct read by blocks (read(16,*) a(:,:)) answer the next question: Has the direct reading read by rows or columns?
11 Index variables: numerical operations and intrinsic functions With specific elements: a(1,3) = 1.0 exp(z(3)) Operations with elemental intrinsic functions: real(kind=8), dimension(5,5) :: a,b,c b = exp(a) It is equivalent to : do 20 i=1,5 do 10 j=1,5 b(i,j) = exp( a(i,j)! b and a are properly defined 10 enddo 20 enddo
12 Index variables: numerical operations and intrinsic functions With specific elements: a(1,3) = 1.0 exp(z(3)) Operations with elemental intrinsic functions: real(kind=8), dimension(5,5) :: a,b,c b = exp(a) Using sections: real(kind=8), dimension (5,5) ::a real(kind=8), dimension (5) :: z a(1,2:4) = 1.0 exp((z(2:4)) It is equivalent to : do 20 i=1,5 do 10 j=1,5 b(i,j) = exp( a(i,j)! b and a are properly defined 10 enddo 20 enddo It is equivalent to : do k = 2, 4, 1 a(1,k) = exp(z(k)) enddo
13 Miscellaneous statements: ALLOCATABLE arrays Example integer :: natom,i,j, error character(len=4), dimension(:),allocatable :: name_atom real(kind=8), dimension(:,:),allocatable :: coor open (11,file= bf3.xyz,action= read ) read (11,*)natom read (11,*) allocate (name_atom(natom)) allocate (coor(natom,3)) do i=1,natom read (11,*,end=20),name_atoms(i),(coor(i,j),j=1,3) 20 end do... deallocate (name_atoms) deallocate (coor) Very useful avoiding overuse of memory allocating arrays when necessary, in the above example after reading dimension from a file
14 Miscellaneous statements: ALLOCATABLE When the array/string/ dimensions are only known during the execution of the program those can be declare as: Declaration/definition (statement/atribute allocatable): real(kind=8), dimension(:,:), allocatable :: din_mat Allocation of memory (allocate): allocate(din_mat(5,5)) Deallocation of memory (deallocate): deallocate(din_mat) Checking the status, by using the function allocated: if (.not.allocated(din_mat)) allocate(din_mat(5,5))
15 Miscellaneous statements: ALLOCATABLE In classroom practice 2 (10 minutes) Use the input5.dat and write a program that: 1) counts the number of elements in the input file, 2) allocate a matrix/vector to store the elements, 3) writes the square root of each element of the matrix/vector.
16 Intrinsic functions
17 Intrinsic functions: Array function SUM SUM (ARRAY, dim, mask) returns the sum of all the elements in the array ARRAY, of those that obey the relation in the third argument MASK if that one is given, along only the desired dimension if the second argument DIM is given. Output of program:
18 Intrinsic functions: Array function PRODUCT PRODUCT(ARRAY, dim, mask) returns the product of all the elements in the array ARRAY, of those that obey the relation in the third argument MASK if that one is given, along only the desired dimension if the second argument DIM is given. Output of program:
19 Intrinsic functions: Vector and matrix multiplication DOT_PRODUCT(VECTOR_A, VECTOR_B) makes a scalar product of two vectors, which must have the same length (same number of elements). MATMUL(MATRIX_A, MATRIX_B) makes the matrix product of two matrices, which must be consistent, i.e. have the dimensions like (M, K) and (K, N). Output of program:
20 Intrinsic functions: Array manipulation TRANSPOSE (MATRIX) transposes a matrix, which is an array of rank 2. It replaces the rows and columns in the matrix. Output of program:
21 Intrinsic functions: Array inquiry functions SIZE(ARRAY, dim) is a function which returns the number of elements in an array ARRAY, if DIM is not given, and the number of elements in the relevant dimension if DIM is included. SHAPE(SOURCE) is a function which returns the shape of an array SOURCE as an integer vector. Output of program:
22 Intrinsic functions In classroom practice 3 (10 minutes) Write a program that: 1) Reads from a file a vector and a matrix and store them in allocatable arrays. 2) Obtain the dot product of the vector with itself. 3) Obtain the matrix product of the matrix with itself. 4) Write the solution into an output file.
23 10) Subprograms:
24 Subprograms and program units Two types of subprograms: the function and the subroutine. Function: takes arguments, and return a single value. Subroutine: may take arguments, and may return several values. Three types of program units: Main program: each application needs to have exactly one main-program, where execution begins and ends Internal/External subprograms: can be either functions or subroutines. Subprograms correspond to different subtasks of the overall algorithm, and they can be invoked from the main-program, or even from other subprograms. Modules: These are general containers, which can encapsulate data, definitions of derived types, namelist-group, interfaces, or module subprograms.
25 Functions or subroutines? Number or entities to be returned: Only one entity to be returned from subprogram No values returned or more than one (or or > 1) FUNCTION SUBROUTINE Convenience of calling: FUNCTION can simply appear as part of an expression SUBROUTINE needs to be called on a separate line. Programming convention: avoiding side effects improving the readability: 1) Modification of procedure arguments. 2) Modification of data external to the procedure. 3) Saved variables. 4) Including stop-statements. 5) Performing I/O on units external of the procedure. 6) Calling other procedures with side effects.
26 Functions or subroutines? Functions Can appear as parts of more complicated expressions. The returned value has to be stored in a variable of the same type. Argument and result type may be scalar, string, array and subprogram. Subroutines Subroutines are invoked with an explicit call-statement, on a separate line. Arguments and results, if there are any, may be scalar, string, array and subprogram.
27 Subprograms of type function Function call in the main program: name_of_variable = name_of_function(argument_list) type function name_of_function(argument_list) [Declaration statements] [Executable statements] Dummy arguments name_of_function = expr RETURN! Not necessary END function [name_of_function] Note: Dummy arguments must maintain order and type Extra local variables can be used
28 Subprograms of type function Example real(kind=8) function dist (r1, r2) implicit none real(kind=8), intent(in), dimension(3) :: r1, r2!raux = auxiliary vector real(kind=8), dimension(3) :: raux raux(:) = r1(:) r2(:) dist = sqrt(dot_product(raux(:),raux(:))) return end function dist Function call: integer, parameter :: Natom=100! Matrix of coordinates real(kind=8), dimension(natom,3) :: r_c real(kind=8) :: d45!distance between atoms 4 and 5 d45 = dist(r_c(4,1:3),r_c(5,1:3))
29 Subprograms of type subroutine Subroutine call in the main program: CALL subroutine_name (argument_list)! Dummy arguments subroutine [name_of subroutine] (argument list) [Declaration statements] [Executable statements] Dummy arguments return! Not necessary, but advisable end subroutine [name_of subroutine] Note: Dummy arguments must maintain order and type Other local variables can be used
30 Subprograms of type subroutine: INTENT The statement INTENT tells the compiler how to use each dummy argument. subroutine name_subroutine(nf,nc,nout) integer, intent(in) :: nf integer, intent(inout) :: nc integer, intent(inout) :: nc Options: IN : subroutine takes the value from a formal argument and does not change its content. OUT : is a result; the value is not defined before the call to the subroutine and have to be stablish before leaving the soubroutine by using the statement return. INOUT : is both, an input data at the beginning of the execution and a result at the end of it.
31 Subprograms of type subroutine Example subroutine mat_wrt(a,nr,nc) implicit none! coments! It writes a matrix in unit 16 (mat_wrt.out)! a : matrix! nf, nc : number of rows and columns!! statements to declare arguments real(kind=8),dimension(nr,nc),intent(in) :: a integer, intent(in) :: nr, nc! statements to declare local variables integer :: i,j! open a file open(16, file = mat_wrt.out )! to write by rows do i= 1,nr write(16, (a12,1x,i4) ) Row number:, i write(16, (6(1x,E11.4)) ) (a(i,j), j=1,nc) end do! close the file and return close(16) return end subroutine mat_wrt
32 Subprograms In classroom practice 4 (15 minutes) 1) Write a subprogram (function or subroutine) that: a) Receives as arguments a real number and a real square matrix. b) The subprogram must return a matrix whose diagonal elements have been multiplied by the real number. 2) Write a main program that calls the subprogram and writes the matrix in an output file. Hint 1: Create two different files, one for the subroutine and one for the main program. Hint 2: How to compile: gfortran main_program.f90 subprogram.f90 -o myprog.exe
33 Where are the subprograms placed? As external subprograms: usually in a different file, interface statement As internal subprogram: same file, contains statement
34 External subprograms: INTERFACE Let s consider the subroutine mat_wrtt subroutine mat_wrt(a,nr,nc) implicit none! coments! Writes in unit 16 matrix a(mat_wrt.out)! a : matrix! nf, nc : number of rows and columns!! statements to declare arguments real(kind=8),dimension(nr,nc),intent(in) :: a integer, intent(in) :: nr, nc! statements to declare local variables integer :: i,j! open a file open(16, file = mat_wrt.out )! to write by rows do i= 1,nr write(16, (a12,1x,i4) ) Row number:, i write(16, (6(1x,E11.4)) ) (a(i,j), j=1,nc) end do! close the file and return close(16) return end subroutine mat_wrt To use the external subroutine we must define it in an interface statement: interface subroutine mat_wrt(a,nf,nc) implicit none integer, intent(in) :: nf, nc real(kind=8),dimension(:,:),intent(in) :: a end subroutine mat_wrt end interface
35 External subprograms: INTERFACE Output of program
36 Internal subprograms Internal subprograms: main-programs, external subprograms, and module subprograms can contain internal subprograms. For these, the contains-keyword needs to be added, on a line of its own, after the last executable statement of the host (sub)program. Then, the internal subprogram can be added between this line and the end program(/function/subroutine)-line of the host. Main program general syntax is: [PROGRAM name_of_program] [Declaration statements] [Executable statements]! It includes calls to subroutines [CONTAINS internal subprograms ] END [name_of_program] Example: PROGRAM test implicit none real, double precision(5,5) :: & a,b,c! Declaration statements integer, k,l,m! Executable statements call srint!call to a internal subroutine call srext_1!call to external subroutines call srext_2 CONTAINS subroutine srint end subroutine srint END PROGRAM test
37 What do we know (so far) about the structure of a program? I. We must have a main program II.We might have subprograms: placed in external files or contained in the same file What if our program gets big with a very long main program and loads of subroutines? How do think that the code can be arranged to make it easy to read? Fortran has two ways to ensemble code MODULES & LIBRARIES
38 Modules and Libraries What is the main difference between modules and libraries? Modules are compiled at the same time as the rest of code Libraries are precompiled and liked to the rest of code in the compilation
39 Modules Modules: external files that group items related to a particular task. Items which can be packaged in a module are: global data subprograms interface-blocks namelist-groups derived type definitions Modules syntax is: In the main program: module name_module [declaration statements] contains subprograms of the module] end [name_module] PROGRAM [name] use name_module implicit none [declaration statements] [executable statements] call subprogram END PROGRAM How to compile: gfortran module.f90 main_program.f90 -o myprog.exe
40 Modules: PUBLIC/PRIVATE All global entities of a module, by default, can be accessed by a program or another module using the USE statement. It is possible to set some restrictions that some entities are private. A private entity of a module can only be accessed within that module. Entities can explicitly be listed to be access from outside as well. Module Acessing module Compilation gfortran module.f90 main.f90 -o myprog.exe
41 Modules: Example Module with public subroutines to sort a vector of dimension n in ascending and descending order. Module contains as well private functions that return the highest and the lowest values of the vector. Do you think that we can call the private subroutines contained in the module sort?
42 Modules: Example Call from the main program:
43 Modules: other uses Define types: module MoleculeDef type atom character(len=2) :: name Integer :: Z real :: mass real :: q real, dimension(1:3) :: coord end type atom Define parameters: module constants real, parameter :: c = , pi= integer, parameter :: nxmax=10, nymax=20, nzmax=30 end module constants type molecule Integer :: Natom type(atom), dimension(1:1000) :: At end type molecule end module MoleculeDef
44 Modules In classroom practice 5 (15 minutes) 1) Using the subprogram that you wrote in practice 4 create a module in which the subprogram is public. 2) Add to the module: 2.a) a subroutine/function that receives as arguments a real number and a real square matrix. 2.b) the subprogram must return a matrix whose off-diagonal elements have been multiplied by the real number. 3) Write a main program that uses the module. Hint: How to compile: gfortran module.f90 main_program.f90 -o myprog.exe
45 11) Libraries
46 Libraries Library: collection of precompiled routines that can be used in any program. The routines, are stored in object format. Objects are linked to our program during compilation. An object file is the real output from the compilation phase..o.a: static libraries. Archive of the original.o object files.so: dynamic libraries. The suffix stands for shared object. Libraries are particularly useful for storing frequently used routines.
47 How are libraries created? Libraries: creation and usability Static libraries: gfortran -c subprograms.f90 ar -r libname.a subprograms.o Dynamic libraries: gfortran -fpic -c subprograms.f90 Objects gfortran -shared -o libname.so subprograms.o How do we link a library to our code? gfortran -o main.exe main.f90 -L/path_forlibrary -lname_of_library The linker automatically looks in libraries for routines that it does not find elsewhere.
48 Libraries: linking to main program 1)Divide the module sort.f90 into several files: ascending.f90 descending.f90 low.f90 high.f90 2)Create the library: a)gfortran -c ascending.f90 descending.f90 low.f90 high.f90 b)ar -r libsort.a ascending.o descending.o low.o high.o 3)Rewrite the main program that calles these subroutines: 4)Compile the program linking the library: gfortran -o main-static.exe main.f90 -L./dota -lsort 5)Execute the program:./main-static.exe
49 Libraries: let me introduce you to blas and lapack BLAS: Basis Linear Algebra Subprograms Routines that provide standard building blocks for performing basic vector and matrix operations. Level 1: perform scalar, vector and vector-vector operations Level 2: perform matrix-vector operations Level 3: perform matrix-matrix operations LAPACK: Linear Algebra Package Routines for solving systems of simultaneous linear equations, least-squares solutions of linear systems of equations, eigenvalue problems, and singular value problems. This libraries can be download and installed in most operating systems. They are already installed in these computers. The path where they are installed is: /usr/lib64
50 Libraries: use of a blas function Compilation gfortran -o example10.exe -L/usr/lib64 example10.f90 -lblas
51 Libraries: use of a blas subroutine Compilation gfortran -o example11.exe -L/usr/lib64 example11.f90 -lblas
52 Libraries (timewise...) In classroom practice 6 (15 minutes) 1) Create different files with each of the subprograms of module of practice 5. 2) Create the library. 3) Write a main program that uses the subprograms of the library. 4) Compile and link the library. Help: Static libraries: gfortran -c subprograms.f90 ar -r libname.a subprograms.o Dynamic libraries: gfortran -fpic -c subprograms.f90 Objects gfortran -shared -o libname.so subprograms.o gfortran -o main.exe main.f90 -L/path_forlibrary -lname_of_library
53 12) Makefiles:
54 Command line compilation Example: program abc.f90, and external subroutines a.f90, b.f90 and c.f90. Let s compile these in the usual command-line me thod: > gfortran -o abc.exe abc.f90 a.f90 b.f90 c.f90 If we modify b.f90 the program has to be recompiled: > gfortran -o abc.exe abc.f90 a.f90 b.f90 c.f90 f90 When our program has many modules and subprograms compilation can take long time
55 Makefile A makefile is a file that compiles the code. When changes are made to some of the code, only the updated files need to be recompiled. The code must be linked again to create the new executable. Makefile knows the pieces of a large program that need to be recompiled. Makefile has all the sentences to compile and link the code up. NOTE: The importance of separate the pieces of code in different files: Keeping all program units in a single file obliges a recompilation of the whole code when we do any small change.
56 Makefile structure: Example Makefile example for abc : [Tab] # makefile : makes the ABC program abc : a.o b.o c.o abc.o gfortran -o abc.exe abc.o a.o b.o c.o abc.o : abc.f90 gfortran -O -c abc.f90 a.o : a.f90 gfortran -O -c a.f90 b.o : b.f90 gfortran -O -c b.f90 c.o : c.f90 gfortran -O -c c.f90 clean: rm *.o *~
57 Makefile: important points Since abc depends on the files a.o, b.o and c.o, all of the.o files must exist and be up-to-date. Makefile will recompile those changed from last compilation. Comments: must be delimited by hash marks (#). Continuation character: backslash (\) the end of the line. By default, the first target file appearing in the makefile is the one that is built. The order of the other targets does not matter. Makefile is invoked from the command line typing make (if name of file is makefile ). If filename is not makefile then use: make -f <mymakefile> In the makefile we can define variables. Note that variables names in make are case-sensitive!
58 Makefile example Makefile using module Makefile using dynamic library
59 Makefiles In classroom practice 7 1) Create a makefile to compile the code of practice 6
Review More Arrays Modules Final Review
OUTLINE 1 REVIEW 2 MORE ARRAYS Using Arrays Why do we need dynamic arrays? Using Dynamic Arrays 3 MODULES Global Variables Interface Blocks Modular Programming 4 FINAL REVIEW THE STORY SO FAR... Create
More information7. Procedures and Structured Programming
7. Procedures and Structured Programming ONE BIG PROGRAM external procedure: separated small and reusable program units to conduct individual subtasks smaller main program Each program unit can be debugged
More informationAMath 483/583 Lecture 8
AMath 483/583 Lecture 8 This lecture: Fortran subroutines and functions Arrays Dynamic memory Reading: class notes: Fortran Arrays class notes: Fortran Subroutines and Functions class notes: gfortran flags
More informationIntroduction to Fortran Programming. -Internal subprograms (1)-
Introduction to Fortran Programming -Internal subprograms (1)- Subprograms Subprograms are used to split the program into separate smaller units. Internal subprogram is not an independent part of a program.
More informationAMath 483/583 Lecture 22. Notes: Another Send/Receive example. Notes: Notes: Another Send/Receive example. Outline:
AMath 483/583 Lecture 22 Outline: MPI Master Worker paradigm Linear algebra LAPACK and the BLAS References: $UWHPSC/codes/mpi class notes: MPI section class notes: Linear algebra Another Send/Receive example
More informationReusing this material
Modules Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-ncsa/4.0/deed.en_us
More informationSubroutines and Functions
Subroutines and Functions Procedures: Subroutines and Functions There are two types of procedures: SUBROUTINE: a parameterized named sequence of code which performs a specific task and can be invoked from
More informationSubroutines, Functions and Modules
Subroutines, Functions and Modules Subdividing the Problem Most problems are thousands of lines of code. Few people can grasp all of the details. Good design principle: Exhibit the overall structure in
More informationFORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017
FORTRAN 90: Functions, Modules, and Subroutines Meteorology 227 Fall 2017 Purpose First step in modular program design Cannot always anticipate all of the steps that will be needed to solve a problem Easier
More informationAllocating Storage for 1-Dimensional Arrays
Allocating Storage for 1-Dimensional Arrays Recall that if we know beforehand what size we want an array to be, then we allocate storage in the declaration statement, e.g., real, dimension (100 ) :: temperatures
More informationProgrammation in Fortran
Programmation in Fortran Adrien Poteaux CRIStAL, Université Lille Year 2017-2018 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. http://creativecommons.org/licenses/by-nc-sa/3.0/
More informationLecture V: Introduction to parallel programming with Fortran coarrays
Lecture V: Introduction to parallel programming with Fortran coarrays What is parallel computing? Serial computing Single processing unit (core) is used for solving a problem One task processed at a time
More informationDeclaration and Initialization
6. Arrays Declaration and Initialization a1 = sqrt(a1) a2 = sqrt(a2) a100 = sqrt(a100) real :: a(100) do i = 1, 100 a(i) = sqrt(a(i)) Declaring arrays real, dimension(100) :: a real :: a(100) real :: a(1:100)!
More informationInterfacing With Other Programming Languages Using Cython
Lab 19 Interfacing With Other Programming Languages Using Cython Lab Objective: Learn to interface with object files using Cython. This lab should be worked through on a machine that has already been configured
More informationTable 2 1. F90/95 Data Types and Pointer Attributes. Data Option. (Default Precision) Selected-Int-Kind
Chapter 2 Data Types Any computer program is going to have to operate on the available data. The valid data types that are available will vary from one language to another. Here we will examine the intrinsic
More information9. Linear Algebra Computation
9. Linear Algebra Computation Basic Linear Algebra Subprograms (BLAS) Routines that provide standard, low-level, building blocks for performing basic vector and matrix operations. Originally developed
More informationGoals for This Lecture:
Goals for This Lecture: Understand the various kinds of REAL types Understand how to select precision in a processor independent manner Introduction to Makefiles Kinds of REAL variables The default REAL
More informationIntroduction to Modern Fortran
Introduction to Modern Fortran p. 1/?? Introduction to Modern Fortran Advanced Use Of Procedures Nick Maclaren nmm1@cam.ac.uk March 2014 Introduction to Modern Fortran p. 2/?? Summary We have omitted some
More informationHigh Performance Fortran http://www-jics.cs.utk.edu jics@cs.utk.edu Kwai Lam Wong 1 Overview HPF : High Performance FORTRAN A language specification standard by High Performance FORTRAN Forum (HPFF), a
More informationNO CALCULATOR ALLOWED!!
CPSC 203 500 EXAM TWO Fall 2005 NO CALCULATOR ALLOWED!! Full Name (Please Print): UIN: Score Possible Points Prog Points Part One 33 pts Part Two 30 pts Part Three 20 pts Part Four 25 pts Total 108 pts
More informationParaFEM Coding Standard for Fortran 90. Contents. 1.0 Introduction. 2.0 Documentation. 2.1 External Documentation
ParaFEM Coding Standard for Fortran 90 This standard has been prepared by Lee Margetts, Francisco Calvo and Vendel Szeremi at the University of Manchester. It is based on Version 1.1 of the European Standards
More informationPACKAGE SPECIFICATION HSL 2013
PACKAGE SPECIFICATION HSL 2013 1 SUMMARY Given a rank-one or rank-two allocatable array, reallocates the array to have a different size, and can copy all or part of the original array into the new array.
More informationA quick guide to Fortran
A quick guide to Fortran Sergiy Bubin Department of Physics Nazarbayev University History of Fortran One of the oldest general purpose high-level computer languages First developed in 1957 at IBM in the
More informationExtrinsic Procedures. Section 6
Section Extrinsic Procedures 1 1 1 1 1 1 1 1 0 1 This chapter defines the mechanism by which HPF programs may call non-hpf subprograms as extrinsic procedures. It provides the information needed to write
More informationReview Functions Subroutines Flow Control Summary
OUTLINE 1 REVIEW 2 FUNCTIONS Why use functions How do they work 3 SUBROUTINES Why use subroutines? How do they work 4 FLOW CONTROL Logical Control Looping 5 SUMMARY OUTLINE 1 REVIEW 2 FUNCTIONS Why use
More informationShort LAPACK User s Guide
Short LAPACK User s Guide 12.01.2002 Bernhard Seiwald Institut für Theoretische Physik Abteilung Plasmaphysik Technische Universität Graz Petersgasse 16, A-8010 Graz, Austria Tel.: +43(316)873-8194 e-mail:
More informationAMath 483/583 Lecture 7
AMath 483/583 Lecture 7 This lecture: Python debugging demo Compiled langauges Introduction to Fortran 90 syntax Declaring variables, loops, booleans Reading: class notes: Python debugging class notes:
More informationModule 5.5: nag sym bnd lin sys Symmetric Banded Systems of Linear Equations. Contents
Module Contents Module 5.5: nag sym bnd lin sys Symmetric Banded Systems of nag sym bnd lin sys provides a procedure for solving real symmetric or complex Hermitian banded systems of linear equations with
More informationGoals for This Lecture:
Goals for This Lecture: Understand what function subprograms are Understand how to use function subprograms Understand the various kinds of REAL types Understand how to select precision in a processor
More informationWelcome. Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at BST
Welcome Modern Fortran (F77 to F90 and beyond) Virtual tutorial starts at 15.00 BST Modern Fortran: F77 to F90 and beyond Adrian Jackson adrianj@epcc.ed.ac.uk @adrianjhpc Fortran Ancient History (1967)
More informationFortran 95/2003 Course
Fortran 95/2003 Course Procedures and Modules by Hartmut Häfner March 25, 2015 STEINBUCH CENTRE FOR COMPUTING - SCC KIT University of the State of Baden-Württemberg and National Laboratory of the Helmholtz
More informationSUBPROGRAMS AND MODULES
SUBPROGRAMS AND MODULES FORTRAN PROGRAMING Zerihun Alemayehu AAiT.CED Program structure Advantages of subprograms Program units can be written and tested independently A program unit that has a well defined
More informationScientific Programming in C X. More features & Fortran interface
Scientific Programming in C X. More features & Fortran interface Susi Lehtola 20 November 2012 typedef typedefs are a way to make shorthand for data types, and possibly also make the code more general
More informationIntroduction to Fortran Programming. -External subprograms-
Introduction to Fortran Programming -External subprograms- Subprograms Subprograms are used to split a program into separate smaller units. Internal subprograms are dependent parts of a program. Fortran
More informationAn Introduction to Fortran
An Introduction to Fortran Sylvia Plöckinger March 10, 2011 Sylvia Plöckinger () An Introduction to Fortran March 10, 2011 1 / 43 General Information Find this file on: http://homepage.univie.ac.at/nigel.mitchell/numprac/
More informationInternational Standards Organisation. Parameterized Derived Types. Fortran
International Standards Organisation Parameterized Derived Types in Fortran Technical Report defining extension to ISO/IEC 1539-1 : 1996 {Produced 4-Jul-96} THIS PAGE TO BE REPLACED BY ISO CS ISO/IEC 1
More informationCompilation & linkage. Compilation & linkage. Make. Compilation & linkage. Explicit rules. What makefile contains
Linkage: g++ read main list o Compilation: g++ -c read main list read read read main main list list list If only one file is modified, do we have to recompile all over again? No. The Makefile uses the
More informationLecture 2: Variables, Vectors and Matrices in MATLAB
Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables
More informationChapter 3. Fortran Statements
Chapter 3 Fortran Statements This chapter describes each of the Fortran statements supported by the PGI Fortran compilers Each description includes a brief summary of the statement, a syntax description,
More informationAMath 483/583 Lecture 7. Notes: Notes: Changes in uwhpsc repository. AMath 483/583 Lecture 7. Notes:
AMath 483/583 Lecture 7 This lecture: Python debugging demo Compiled langauges Introduction to Fortran 90 syntax Declaring variables, loops, booleans Reading: class notes: Python debugging class notes:
More informationMATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1
MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED Christian Daude 1 Introduction MATLAB is a software package designed to handle a broad range of mathematical needs one may encounter when doing scientific
More informationAN INTRODUCTION TO FORTRAN 90 LECTURE 2. Consider the following system of linear equations: a x + a x + a x = b
AN INTRODUCTION TO FORTRAN 90 LECTURE 2 1. Fortran 90. Arrays, functions and subroutines. 2. Scientific plotting. Gnuplot 1 Each coefficient and variable is a scalar. Lengthy and cumbersome! Program Scalar
More informationSubprograms. FORTRAN 77 Chapter 5. Subprograms. Subprograms. Subprograms. Function Subprograms 1/5/2014. Satish Chandra.
FORTRAN 77 Chapter 5 Satish Chandra satish0402@gmail.com When a programs is more than a few hundred lines long, it gets hard to follow. Fortran codes that solve real research problems often have tens of
More informationChapter 4. Fortran Arrays
Chapter 4. Fortran Arrays Fortran arrays are any object with the dimension attribute. In Fortran 90/95, and in HPF, arrays may be very different from arrays in older versions of Fortran. Arrays can have
More informationFortran 90 - A thumbnail sketch
Fortran 90 - A thumbnail sketch Michael Metcalf CERN, Geneva, Switzerland. Abstract The main new features of Fortran 90 are presented. Keywords Fortran 1 New features In this brief paper, we describe in
More informationFortran Coding Standards and Style
Fortran Coding Standards and Style The Fortran Company Version 20160112 Copyright 2015-2016, The Fortran Company All rights reserved. Redistribution, with or without modification, is permitted provided
More informationFortran. (FORmula TRANslator) History
Fortran (FORmula TRANslator) History FORTRAN vs. Fortran 1954 FORTRAN first successful high level language John Backus (IBM) 1958 FORTRAN II (Logical IF, subroutines, functions) 1961 FORTRAN IV 1966 FORTRAN
More informationIntroduction to Programming with Fortran 90
Introduction to Programming with Fortran 90 p. 1/?? Introduction to Programming with Fortran 90 Array Concepts Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 November 2007 Introduction to Programming
More informationBLAS: Basic Linear Algebra Subroutines I
BLAS: Basic Linear Algebra Subroutines I Most numerical programs do similar operations 90% time is at 10% of the code If these 10% of the code is optimized, programs will be fast Frequently used subroutines
More informationMatrix Multiplication
Matrix Multiplication CPS343 Parallel and High Performance Computing Spring 2013 CPS343 (Parallel and HPC) Matrix Multiplication Spring 2013 1 / 32 Outline 1 Matrix operations Importance Dense and sparse
More informationGoals for This Lecture:
Goals for This Lecture: Understand what modules are Understand what module procedures are and how to use them Understand explicit and implicit interfaces Understand what automatic arrays are and how to
More informationAn interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.
Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose
More informationMatrices. Chapter Matrix A Mathematical Definition Matrix Dimensions and Notation
Chapter 7 Introduction to Matrices This chapter introduces the theory and application of matrices. It is divided into two main sections. Section 7.1 discusses some of the basic properties and operations
More informationISO/IEC : TECHNICAL CORRIGENDUM 2
ISO/IEC 1539-1:2010 - TECHNICAL CORRIGENDUM 2 ISO/IEC/JTC1/SC22/WG5-N1957 Notes for WG5: Edits included in this document from the interpretations in N1932 as amended by 12-193 and 12-194 and in N1949 as
More informationSami Ilvonen Pekka Manninen. Introduction to High-Performance Computing with Fortran. September 19 20, 2016 CSC IT Center for Science Ltd, Espoo
Sami Ilvonen Pekka Manninen Introduction to High-Performance Computing with Fortran September 19 20, 2016 CSC IT Center for Science Ltd, Espoo All material (C) 2009-2016 by CSC IT Center for Science Ltd.
More informationOld Questions Name: a. if b. open c. output d. write e. do f. exit
Old Questions Name: Part I. Multiple choice. One point each. 1. Which of the following is not a Fortran keyword? a. if b. open c. output d. write e. do f. exit 2. How many times will the code inside the
More informationIn context with optimizing Fortran 90 code it would be very helpful to have a selection of
1 ISO/IEC JTC1/SC22/WG5 N1186 03 June 1996 High Performance Computing with Fortran 90 Qualiers and Attributes In context with optimizing Fortran 90 code it would be very helpful to have a selection of
More informationMatrix Multiplication
Matrix Multiplication CPS343 Parallel and High Performance Computing Spring 2018 CPS343 (Parallel and HPC) Matrix Multiplication Spring 2018 1 / 32 Outline 1 Matrix operations Importance Dense and sparse
More informationCUDA Fortran COMPILERS &TOOLS. Porting Guide
Porting Guide CUDA Fortran CUDA Fortran is the Fortran analog of the NVIDIA CUDA C language for programming GPUs. This guide includes examples of common language features used when porting Fortran applications
More informationPaul F. Dubois. X-Division.
Large-scale simulations with Fortran 95: An object-based approach Lesson 3 Types and objects X-Division 1 of 29 In our first two lessons, we have concentrated on arrays, modules, and derived types. It
More informationSubprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu
1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized
More informationThe Fortran Basics. Handout Two February 10, 2006
The Fortran Basics Handout Two February 10, 2006 A Fortran program consists of a sequential list of Fortran statements and constructs. A statement can be seen a continuous line of code, like b=a*a*a or
More information41391 High performance computing: Miscellaneous parallel programmes in Fortran
1391 High performance computing: Miscellaneous parallel programmes in Fortran Nilas Mandrup Hansen, Ask Hjorth Larsen January 19, 0 1 Introduction This document concerns the implementation of a Fortran
More information2 3. Syllabus Time Event 9:00{10:00 morning lecture 10:00{10:30 morning break 10:30{12:30 morning practical session 12:30{1:30 lunch break 1:30{2:00 a
1 Syllabus for the Advanced 3 Day Fortran 90 Course AC Marshall cuniversity of Liverpool, 1997 Abstract The course is scheduled for 3 days. The timetable allows for two sessions a day each with a one hour
More informationPage 1 of 7. Date: 1998/05/31 To: WG5 From: J3/interop Subject: Interoperability syntax (Part 1) References: J3/98-132r1, J3/98-139
(J3/98-165r1) Date: 1998/05/31 To: WG5 From: J3/interop Subject: Interoperability syntax (Part 1) References: J3/98-132r1, J3/98-139 ISO/IEC JTC1/SC22/WG5 N1321 Page 1 of 7 Describing pre-defined C data
More informationNumerical Modelling in Fortran: day 2. Paul Tackley, 2017
Numerical Modelling in Fortran: day 2 Paul Tackley, 2017 Goals for today Review main points in online materials you read for homework http://www.cs.mtu.edu/%7eshene/courses/cs201/notes/intro.html More
More informationNAG Library Routine Document F08LEF (DGBBRD)
NAG Library Routine Document (DGBBRD) Note: before using this routine, please read the Users Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent
More informationLecture 2. Arrays. 1 Introduction
1 Introduction Lecture 2 Arrays As the name Matlab is a contraction of matrix laboratory, you would be correct in assuming that Scilab/Matlab have a particular emphasis on matrices, or more generally,
More informationC interfaces to HSL routines. J. D. Hogg. Version 1.0 5th December Numerical Analysis Group Internal Report
2011-1 Numerical Analysis Group Internal Report C interfaces to HSL routines J. D. Hogg Version 1.0 5th December 2011 Copyright (c) 2011 Science and Technology Facilities Council C interfaces to HSL routines
More informationModule 28.3: nag mv rotation Rotations. Contents
Multivariate Analysis Module Contents Module 28.3: nag mv rotation Rotations nag mv rotation contains a procedure to compute rotations for sets of data values. Contents Introduction..............................................................
More informationModern Fortran OO Features
Modern Fortran OO Features Salvatore Filippone School of Aerospace, Transport and Manufacturing, salvatore.filippone@cranfield.ac.uk IT4I, Ostrava, April 2016 S. Filippone (SATM) Modern Fortran OO Features
More informationBasic Fortran Programming. National Computational Infrastructure
Basic Fortran Programming National Computational Infrastructure Outline Introduction Declaration Arithmetic Do Loops Conditionals Functions I/O Libraries End 2 / 56 Fortran Programming Language Fortran
More informationMatrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:
Matrices A Matrix is an array of numbers: We talk about one matrix, or several matrices. There are many things we can do with them... Adding A Matrix (This one has 2 Rows and 3 Columns) To add two matrices:
More informationIndex. classes, 47, 228 coarray examples, 163, 168 copystring, 122 csam, 125 csaxpy, 119 csaxpyval, 120 csyscall, 127 dfetrf,14 dfetrs, 14
Index accessor-mutator routine example in a module, 7 PUBLIC or PRIVATE components, 6 ACM, ix editors of CALGO, ix Adams, Brainerd et al., see books, Fortran reference Airy s equation boundary value problem,
More informationHPF commands specify which processor gets which part of the data. Concurrency is defined by HPF commands based on Fortran90
149 Fortran and HPF 6.2 Concept High Performance Fortran 6.2 Concept Fortran90 extension SPMD (Single Program Multiple Data) model each process operates with its own part of data HPF commands specify which
More information1. User-Defined Functions & Subroutines Part 1 Outline
User-Defined Functions Subroutines Part 1 Outline 1. User-Defined Functions Subroutines Part 1 Outline 2. Intrinsic Functions Are Not Enough 3. User-Defined Functions 4. A User-Defined Function for Mean
More information10. Additional Intrinsic Data Types
10. Additional Intrinsic Data Types Example: You have written a test driver for SGESV in LAPACK consists of the following steps: 1. Generate the elements of the matrix [A] and the vector {x_exact} using
More informationAppendix D. Fortran quick reference
Appendix D Fortran quick reference D.1 Fortran syntax... 315 D.2 Coarrays... 318 D.3 Fortran intrisic functions... D.4 History... 322 323 D.5 Further information... 324 Fortran 1 is the oldest high-level
More informationMATFOR In Visual Basic
Quick Start t t MATFOR In Visual Basic ANCAD INCORPORATED TEL: +886(2) 8923-5411 FAX: +886(2) 2928-9364 support@ancad.com www.ancad.com 2 MATFOR QUICK START Information in this instruction manual is subject
More informationPractical Exercise 1 Question 1: The Hello World Program Write a Fortran 95 program to write out Hello World on the screen.
Practical Exercise Question : The Hello World Program Write a Fortran 95 program to write out Hello World on the screen. Question : Some Division One Results A particular number can be expressed as the
More informationPROBLEM SOLVING WITH FORTRAN 90
David R. Brooks PROBLEM SOLVING WITH FORTRAN 90 FOR SCIENTISTS AND ENGINEERS Springer Contents Preface v 1.1 Overview for Instructors v 1.1.1 The Case for Fortran 90 vi 1.1.2 Structure of the Text vii
More informationIt can be confusing when you type something like the expressions below and get an error message. a range variable definition a vector of sine values
7_april_ranges_.mcd Understanding Ranges, Sequences, and Vectors Introduction New Mathcad users are sometimes confused by the difference between range variables and vectors. This is particularly true considering
More informationInformation technology Programming languages Fortran Part 1: Base language
INTERNATIONAL STANDARD ISO/IEC 1539-1:2010 TECHNICAL CORRIGENDUM 2 Published 2013-06-01 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE
More informationBLAS: Basic Linear Algebra Subroutines I
BLAS: Basic Linear Algebra Subroutines I Most numerical programs do similar operations 90% time is at 10% of the code If these 10% of the code is optimized, programs will be fast Frequently used subroutines
More informationFORTRAN - ARRAYS. For example, to declare a one-dimensional array named number, of real numbers containing 5 elements, you write,
http://www.tutorialspoint.com/fortran/fortran_arrays.htm FORTRAN - ARRAYS Copyright tutorialspoint.com Arrays can store a fixed-size sequential collection of elements of the same type. An array is used
More informationM4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be
More informationor 5.00 or 5.000, and so on You can expand the decimal places of a number that already has digits to the right of the decimal point.
1 LESSON Understanding Rational and Irrational Numbers UNDERSTAND All numbers can be written with a For example, you can rewrite 22 and 5 with decimal points without changing their values. 22 5 22.0 or
More informationPorting the NAS-NPB Conjugate Gradient Benchmark to CUDA. NVIDIA Corporation
Porting the NAS-NPB Conjugate Gradient Benchmark to CUDA NVIDIA Corporation Outline! Overview of CG benchmark! Overview of CUDA Libraries! CUSPARSE! CUBLAS! Porting Sequence! Algorithm Analysis! Data/Code
More informationComputers in Engineering. Subroutines Michael A. Hawker
Computers in Engineering COMP 208 Subroutines Michael A. Hawker Subprograms Functions are one type of subprogram in FORTRAN Another type of subprogram FORTRAN allows is called a subroutine There are many
More information2. What are the advantages of simulating a molecule or a reaction over doing the experiment in a lab?
Name: Introduction 1. What is computational chemistry? 2. What are the advantages of simulating a molecule or a reaction over doing the experiment in a lab? Programming Match the following terms to their
More informationScientific Computing. Some slides from James Lambers, Stanford
Scientific Computing Some slides from James Lambers, Stanford Dense Linear Algebra Scaling and sums Transpose Rank-one updates Rotations Matrix vector products Matrix Matrix products BLAS Designing Numerical
More informationCSE/Math 485 Matlab Tutorial and Demo
CSE/Math 485 Matlab Tutorial and Demo Some Tutorial Information on MATLAB Matrices are the main data element. They can be introduced in the following four ways. 1. As an explicit list of elements. 2. Generated
More informationLesson 6 Introduction to Object-Oriented Programming
Lesson 6 Introduction to Object-Oriented Programming Programming Grade in Computer Engineering Outline 1. Motivation 2. Classes, objects and attributes 3. Constructors 4. Methods 5. Composition 6. Object
More informationMore Coarray Features. SC10 Tutorial, November 15 th 2010 Parallel Programming with Coarray Fortran
More Coarray Features SC10 Tutorial, November 15 th 2010 Parallel Programming with Coarray Fortran Overview Multiple Dimensions and Codimensions Allocatable Coarrays and Components of Coarray Structures
More information2.7 Numerical Linear Algebra Software
2.7 Numerical Linear Algebra Software In this section we will discuss three software packages for linear algebra operations: (i) (ii) (iii) Matlab, Basic Linear Algebra Subroutines (BLAS) and LAPACK. There
More informationProgramming. Dr Ben Dudson University of York
Programming Dr Ben Dudson University of York Outline Last lecture covered the basics of programming and IDL This lecture will cover More advanced IDL and plotting Fortran and C++ Programming techniques
More informationOur Strategy for Learning Fortran 90
Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data
More informationIntroduction to Fortran95 Programming Part II. By Deniz Savas, CiCS, Shef. Univ., 2018
Introduction to Fortran95 Programming Part II By Deniz Savas, CiCS, Shef. Univ., 2018 Summary of topics covered Logical Expressions, IF and CASE statements Data Declarations and Specifications ARRAYS and
More informationThe new features of Fortran 2003
The new features of Fortran 2003 David Muxworthy BSI Fortran Convenor Pages in Fortran Standards 0 100 200 300 400 500 600 700 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
More information0. Overview of this standard Design entities and configurations... 5
Contents 0. Overview of this standard... 1 0.1 Intent and scope of this standard... 1 0.2 Structure and terminology of this standard... 1 0.2.1 Syntactic description... 2 0.2.2 Semantic description...
More information