
Modern Fortran Support for new Fortran Language Elements by Intel® Fortran Composer XE Agenda • Introduction – Fortran History – Why Fortran • Modern Fortran – Some selected Features – Array Notation – Object-oriented programming – Do-Concurrent – Coarray Fortran • Intel Fortran Composer XE – Standard Support – Implementation of Coarrays • References/Summary Credit: Thanks to Mr. Reinhold Bader, LRZ Garching/Germany, who provided some of the slides used here Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Your Memory of Fortran ? IF (AA(J+L).EQ.0.0)GOTO42 TEST=TEST-1 THETA=ATAN(X,Y) GOTO30 42 TEST=TEST+1 THETA=ATAN(-X,Y) 30 CONTINUE “GOD is REAL (unless declared INTEGER)." Copyright© 2012, Intel Corporation. All rights reserved. 4 *Other brands and names are the property of their respective owners. FORTRAN Started 1954 as “ IBM Mathematical Formula Translation System” but abbreviated later to FORmula TRANslation • created by IBM developer John Backus and released to public in 1957 – Now called “Fortran I” • designed for scientific and engineering computation John Backus 1924-2007 • FORTRAN is the oldest programming language actively in use today • FORTRAN is still very popular for new software development in scientific applications • Many FORTRAN programs written +40 years ago are still in active use today! Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. IBM 704 Fortran manual, 1957 Copyright© 2012, Intel Corporation. All rights reserved. 6 *Other brands and names are the property of their respective owners. FORTRAN–History [1] • FORTRAN 1957 (“Fortran I”) • FORTRAN II, III – Clean up, separate module compilation • FORTRAN IV – IF statement, type declarations • FORTRAN 66 - ANSI Standard of 1966 – Clean up of FORTRAN IV • FORTRAN 77 - ANSI Standard released 1978 – CHARACTER data type, new DO-Loop semantic, IF-THEN-ELSE • FORTRAN 90 – ANSI Standard released 1992 – Free form, array section, dynamic memory allocation, derived types, modular programming • FORTRAN 95 – ANSI Standard released 1997 – Minor update of FORTRAN90; FORALL, PURE and ELEMENTAL routines Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. FORTRAN– History [2] • FORTRAN 2003 – ANSI Standard released 2003 – Object-oriented programming, C-interoperability, IEEE- arithmetic, parameterized derived types, ASSOCIATE, procedure pointers, … • FORTRAN 2008 – latest ANSI standard, released June 2010 – Coarrays, DO-CONCURRENT, bit manipulation intrinsics, sub-module concept Many dialects influenced FORTRAN standardization and all compilers support some non-standard extensions of these dialects – Cray Fortran (“Cray Pointers”) – DEC Fortran Some too progressive extensions like HPF-High Performance Fortran did not find much attention outside of academic research Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Why Fortran? A few Selected Arguments • Arrays are not only part of the language syntax but have representation in run-time environment – Different from C/C++ – Implies: – Easier programming (e.g. multi-dimensional array procedure arguments with variable bounds) – Better code generation (faster code) • Safer (more restrictive) semantic – POINTER much safer than for C/C++ – Aliasing of procedure arguments limited – Implies: More compiler optimizations, thus faster code • Module concept • Portability – 32 to 64 bit porting -> no changes needed ! – No problem to compile +40 year old programs • Existing code base Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Sample: Triade in Fortran and C C/C++ : void triade( int a[], int b[], int c[], int n) { Both vectorize int j; but C-version for (j=0; j<n; j++) requires run- a[j] = b[j] + 3.14 * c[j]; time alias } checking for ‘a’, ‘b’ and ‘a’, ’c’ Fortran: Fortran does subroutine triade(a, b, n) not allow 2 integer n arguments to integer, dimension (1:n) :: a,b,c do j = 1,n alias in case a(j) = b(j) + 3.14 * c(j) one is modified: end do Code is faster end subroutine triade Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Agenda • Introduction – Fortran History – Why Fortran • Modern Fortran – Some selected Features – Array Notation – Object-oriented programming – Do-Concurrent – Coarray Fortran • Intel® Fortran Composer XE – Standard Support – Implementation of Coarrays • References/Summary Credit: Thanks to Mr. Reinhold Bader, LRZ Garching/Germany, who provided some of the slides used here Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Array Sections • Introduced by FORTRAN90 • Similar to array notation of Intel® Cilk Plus introduced 20 years later as C/C++ extension – But syntax different: <lower bound>:<upper bound> [:<stride>] – And semantic for assignment different: LHS and RHS may overlap in Fortran, not in Cilk Plus !! A(1:10, 1:3) A(1:10:2, 1:10:2) 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 1 Example 2 2 3 3 REAL :: A(10, 10) 4 4 5 5 6 6 7 7 8 8 9 9 Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Modules in Fortran module mymodule ! My very own module use m1 ! import all objects of module m1 use m2, only : x, y ! import only x, y from module m2 implicit none !! Module variables go here real , dimension (20) :: x subroutine s1(a, b) ! An external procedure contains subroutine s2(foo , bar) ! An internal procedure end subroutine s2 end subroutine s2 end module mymodule Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Interoperation with C Portable, Standardized Interface Invoke C functions in a standard- Example C prototype defined way • Today (F2003) focusing on Fortran using C- void My_C_Subr(int, double *); objects • Future standard: Both directions program myprog use, intrinsic :: iso_c_binding • Invocation from Fortran: integer( c_int ) :: ic C intrinsic type matching: c_int, c_real … real( c_real ) :: rc4 real( c_double ), allocatable :: dc(:) character( c_char ) :: cc interface subroutine my_c_subr(i, d) bind(c, name=' My_C_Subr ') use, intrinsic :: iso_c_binding integer(c_int), value :: i • Suppress Fortran name mangling real(c_double) :: d(*) • Mixed case name resolution end subroutine my_c_subr end interface ic = … ; allocate(dc(ic)) • ic passed by value call my_c_subr(ic, dc) • address of first element of dc end program passed to subprogram Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Fortran 2003 OOP (1) Type extension Polymorphic entities • new kind of dynamic storage type :: body declared type body real :: mass : ! position, velocity class (body), & end type allocatable :: balloon type, extends (body) :: & typed allocation charged_body allocate(body :: balloon) charged_body real :: charge : ! send balloon on trip end type if (hit_by_lightning()) then : ! save balloon data type(charged_body) :: & deallocate(balloon) proton allocate( & must be an extension charged_body :: balloon) etc_body inherited balloon = … proton%mass = … ! balloon data + charge proton%charge = … end if : ! continue trip if possible change not only size, but also Single inheritance – always a DAG (dynamic) type of object during execution of program 15 Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. Fortran 2003 OOP (2) Associate procedures with type Run time type/class resolution • make components of dynamic type accessible type :: body object-bound procedure (pointer) : ! data components procedure(p), pointer :: print polymorphic entity contains select type (balloon) procedure :: dp type-bound type is (body) end type procedure (TBP) : ! balloon non-polymorphic here class is (rotating_body) subroutine dp(this, kick) : ! declared type lifted class (body), intent(inout) :: this class default real, intent(in) :: kick(3) : ! implementation incomplete? : ! give body a kick end select end subroutine • at most one block is executed • polymorphic dummy argument required for inheritance • same mechanism is used (internally) to resolve type-bound procedure calls • TBP can be overridden by extension (must specify essentially same interface, down to keywords) balloon%print => p_formatted call balloon%print() call balloon%dp(mykick) balloon matches this Copyright© 2012, Intel Corporation. All rights reserved. *Other brands and names are the property of their respective owners. F2008 DO CONCURRENT A new Parallel Loop Construct Syntax uses elements of Fortran 90 FORALL DO [,] CONCURRENT <forall-header> Semantically there is a key difference to FORALL however : A variable referenced can only be defined in the very same iteration or outside of the loop body • This excludes dependencies between different loop iterations The implementation in Intel® Compiler will execute the iterations in parallel using OpenMP* run-time system • requires compiler switch –parallel DO CONCURRENT (I = 1:N) ! Not conforming BLOCK REAL :: T DO CONCURRENT (I=1:N) T = A(I) + B(I) A(I+1) = A(I) + 3.145 C(I) = T + SQRT(T) END BLOCK END DO END
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages49 Page
-
File Size-