The History of Fortran Presented by Maj Stenmark Based on The History of FORTRAN I, II, and III by John Backus. The Rise and Fall of High Performance Fortran: An Historical Object Lesson by K. Kennedy, C. Koelbel and H. Zima. Once upon a Dme … Computer Science in 1954 Why FORTRAN? • • • • “AutomaDc programming” HandwriSen assembly IBM 704 Efficient compiler! John Backus FORmula TRANslaDng system • ScienDfic compuDng • FORTRAN I, starDng 1954 • FORTRAN II, 1958, FuncDons, global variables • FORTRAN III, 1958, never released • FORTRAN 77, If-‐esle • Fortran 90 Immature high-‐performance • Fortran 95 High-‐performance • Fortran 2003 Object-‐oriented • Fortran 2008 concurrent Early FORTRAN • • • • • • Variables 1-‐2 characters FuncDons 3 characters Expressions Assignments Blanks ignored FREQUENCY, GOTO, DO-‐loops, STOP, PAUSE • No blocks, if, type declara3ons! The Translator • • • • Compiler, step-‐wise SecDon 1: Read file, store in tables SecDon 2: OpDmal code. Difficult SecDons 3-‐6: OpDmal register allocaDon. • a * b * c + a * b as (a * b) * c + (a * b) Translator trivia • FREQUENCY – Monte Carlo simulaDon • Release in 1957. On decks. Then magneDc tape! hello.f90 Program Hello Print *, "Hello World!" End Program Hello Compiling: $ gfortran -‐o hello hello.f90 gfortran: varning: kunde inte förstå kern.osversion ”14.3.0 $ ./hello Hello World! ProjecDle.f90 PROGRAM ProjecDle IMPLICIT NONE REAL, PARAMETER :: g = 9.8 ! acceleraDon due to gravity REAL, PARAMETER :: PI = 3.1415926 ! you knew this. didn't you REAL :: Angle ! launch angle in degree REAL :: Time ! Dme to flight REAL :: Theta ! direcDon at Dme in degree REAL :: U ! launch velocity REAL :: V ! resultant velocity REAL :: Vx ! horizontal velocity REAL :: Vy ! verDcal velocity REAL :: X ! horizontal displacement REAL :: Y ! verDcal displacement READ(*,*) Angle, Time, U Angle = Angle * PI / 180.0 ! convert to radian X = U * COS(Angle) * Time Y = U * SIN(Angle) * Time -‐ g*Time*Time / 2.0 Vx = U * COS(Angle) Vy = U * SIN(Angle) -‐ g * Time V = SQRT(Vx*Vx + Vy*Vy) Theta = ATAN(Vy/Vx) * 180.0 / PI WRITE(*,*) 'Horizontal displacement : ', X WRITE(*,*) 'VerDcal displacement : ', Y WRITE(*,*) 'Resultant velocity : ', V WRITE(*,*) 'DirecDon (in degree) : ', Theta END PROGRAM ProjecDle High performance Fortran • Parallel compuDng systems • Data parallel – single thread of control – Communicate data between processes • Shared-‐memory over one bus – Parallel loops • Distributed memory – Programming complexity HPF • • • • • • Support scalability Data parallelism: distributed arrays Single thread of control Implicit communicaDon Produce high performance code! Included a standard library HPF Library Language REAL A(1000, 1000), B(1000, 1000) !HPF$ DISTRIBUTE A(BLOCK, *) !HPF$ DISTRIBUTE A(CYCLIC, *) DO J = 2, N A(I,J) = A(I, J+1) + 2 * B(I, J) + …. ENDDO Language REAL A(1000, 1000), B(1000, 1000) !HPF$ DISTRIBUTE A(BLOCK, *) !HPF$ DISTRIBUTE A(CYCLIC, *) !HPF$ ALIGH B(I, J) WITH A(I, J) DO J = 2, N !HPF$ INDEPENDENT A(I,J) = A(I, J+1) + 2 * B(I, J) + …. ENDDO Why HPF didn’t succeed • • • • Immature compiler technology Too few features Inconsistency in the implementaDons DifficulDes to debug Impact • SDll used! • SupercompuDng: weather, computaDonal physics, fluid dynamics, chemistry. • First high-‐level language. Exercise 1/2 Write a program that reads an integer n from the console and then recursively calculates and outputs the nth Fibonacci number. That is n = 4 should output 3. Save the code in fib.f90. Exercise 2/2 Write a program that reads a number n from the console and then, using n steps, stepwise integrates the funcDon eiθ from A) 0 to θ = π B) 0 to θ = 2π Save the program in compl.f90 Running instrucDons • Login to the server: $ ssh [email protected] Create a new folder and go there $ mkdir fortran $cd fortran Compile your files: $ gfortran -‐o fib fib.f90 (fib will be the name of your program) And run it: $./fib Send your files to Maj.
© Copyright 2024