Fortran 90 - Center 4 Fortran FORmula TRANslation 1950년대후반IBM에서개발 9가장오래된고급언어 국제표준채택(1980, ISO) FORTRAN 77 Fortran 90, Fortran 95, Fortran

Download Fortran 90 -   Center 4 Fortran FORmula TRANslation 1950년대후반IBM에서개발 9가장오래된고급언어 국제표준채택(1980, ISO) FORTRAN 77 Fortran 90, Fortran 95, Fortran

Post on 08-May-2018




16 download


<ul><li><p>Fortran 90Fortran 90</p><p>KISTI KISTI </p></li><li><p>Supercomputing Center Supercomputing Center 22</p><p>1.1. Fortran 90 Fortran 90 </p><p>2.2. Numerical RobustnessNumerical Robustness</p><p>3.3. Data ParallelismData Parallelism</p><p>4.4. </p></li><li><p> I I </p><p>Fortran 90 Fortran 90 </p><p>Fortran 90Fortran 90 </p><p> Fortran 77, C/C++Fortran 77, C/C++ </p><p>..</p></li><li><p>Supercomputing Center Supercomputing Center 44</p><p>Fortran Fortran </p><p>FORFORmula mula TRANTRANslationslation19501950 IBMIBM </p><p> (1980, ISO) (1980, ISO) FORTRAN 77FORTRAN 77</p><p>Fortran 90, Fortran 95, Fortran 2003Fortran 90, Fortran 95, Fortran 2003</p></li><li><p>Supercomputing Center Supercomputing Center 55</p><p>Fortran 77Fortran 77 (1/2)(1/2)</p><p>7272 55 66 11 , , </p><p> (6(6) ) </p></li><li><p>Supercomputing Center Supercomputing Center 66</p><p>Fortran 77Fortran 77 (2/2)(2/2)</p><p>(()) COMMON COMMON , EQUIVQALENCE , EQUIVQALENCE </p></li><li><p>Supercomputing Center Supercomputing Center 77</p><p>Type DeclarationType Declaration attributingattributing</p><p>New control structureNew control structure</p><p>Numeric ProcessingNumeric Processing</p><p>Array ProcessingArray Processing</p><p>PointersPointers</p><p>I/OI/O</p></li><li><p>Supercomputing Center Supercomputing Center 88</p><p>Fortran 90Fortran 90</p><p>(http://www.comphys.uni(</p></li><li><p>Supercomputing Center Supercomputing Center 99</p><p> (1/12)(1/12)</p><p> 132132 </p><p>IBM XL FortranIBM XL Fortran 67006700 ;; !! &amp;&amp; 3131 (( ))</p><p>IBM XL FortranIBM XL Fortran 250250 </p><p>.LT., .LE., .EQ., .NE., .GE., .GT. .LT., .LE., .EQ., .NE., .GE., .GT. </p></li><li><p>Supercomputing Center Supercomputing Center 1010</p><p> (2/12)(2/12)</p><p>PRINT*, "This line is continued &amp;on the next line"; END ! of program</p></li><li><p>Supercomputing Center Supercomputing Center 1111</p><p> (3/12)(3/12)</p><p>Fortran 90Fortran 90 -- : a: a--z, Az, A--Z, 0Z, 0--9, _ (underscore)9, _ (underscore)</p><p>Symbol Description Symbol Description </p><p>SpaceSpace == EqualEqual</p><p>++ PlusPlus -- MinusMinus</p><p>** AsteriskAsterisk // SlashSlash</p><p>(( Left parenthesisLeft parenthesis )) Right parenthesisRight parenthesis</p><p>,, CommaComma .. PeriodPeriod</p><p> Single quoteSingle quote Double quoteDouble quote</p><p>:: ColonColon ;; Semi colonSemi colon</p><p>!! ShriekShriek &amp;&amp; Ampersand Ampersand </p><p>%% PercentPercent &gt; Greater thanGreater than $$ Dollar Dollar </p><p>?? Question markQuestion mark</p></li><li><p>Supercomputing Center Supercomputing Center 1212</p><p> (4/12)(4/12)</p><p>Type Declaration and AttributingType Declaration and Attributing</p><p>Fortran77 Fortran90FUNCTION encode(pixels)</p><p>INTEGER nPARAMETER(n=1000) INTEGER pixels(n, n), encode(n, n) REAL x(n), y(n) INTEGER*8 callcall = 0 ...END</p><p>FUNCTION encode(pixels)</p><p>IMPLICIT NONEINTEGER, PARAMETER :: n=1000 INTEGER, DIMENSION(n, n) :: pixels, encode REAL, DIMENSION(n) :: x, y INTEGER(8) :: call=0 ...END</p></li><li><p>Supercomputing Center Supercomputing Center 1313</p><p> (5/12)(5/12)</p><p>New Control Structure(1)New Control Structure(1)SELECTSELECT--CASECASE</p><p>IF IF </p><p>SELECT CASE (expression)CASE(value-list)CASE(value-list)</p><p>END SELECT</p></li><li><p>Supercomputing Center Supercomputing Center 1414</p><p> (6/12)(6/12)</p><p>New Control Structure(2)New Control Structure(2)</p><p>PROGRAM select</p><p>INTEGER :: n, kPRINT *, 'Enter the value n = 'READ *, n</p><p>SELECT CASE(n)CASE (:0)</p><p>k = -nCASE (10:)</p><p>k = n+10CASE DEFAULT</p><p>k = nEND SELECT</p><p>PRINT *, k</p><p>END</p></li><li><p>Supercomputing Center Supercomputing Center 1515</p><p> (7/12)(7/12)</p><p>New Control Structure(3)New Control Structure(3) DO DO </p><p>DO DO END DOEND DODO WHILE DO WHILE END DOEND DO</p><p>DOIF (logical-expr) EXIT</p><p>END DO</p><p>DO WHILE (logical-expr)</p><p>END DO</p></li><li><p>Supercomputing Center Supercomputing Center 1616</p><p> (8/12)(8/12)</p><p>Numeric ProcessingNumeric Processing </p><p>kind kind </p><p>Array ProcessingArray ProcessingPointersPointers</p><p>REAL, TARGET :: B(100,100) ! B target .REAL, POINTER :: U(:,:),V(:),W(:,:) ! 3 </p><p>...U =&gt; B(I:I+2,J:J+2) ! U B 3x3 pointALLOCATE ( W(M,N) ) ! MxN W V =&gt; B(:,J) ! V B J point V =&gt; W(I-1,1:N:2) ! V W I-1 point </p></li><li><p>Supercomputing Center Supercomputing Center 1717</p><p> (9/12)(9/12)</p><p> + + </p><p>TYPE RATIONAL ! This defines the type RATIONAL.INTEGER :: NUMERATORINTEGER :: DENOMINATOR</p><p>END TYPE RATIONAL...TYPE (RATIONAL) :: X, Y(100,100) ! X and Y are variables of type RATIONAL.X%NUMERATOR = 2; X%DENOMINATOR = 3</p><p>INTERFACE OPERATOR(+)FUNCTION RAT_ADD(X, Y)</p><p>TYPE (RATIONAL) :: RAT_ADDTYPE (RATIONAL), INTENT(IN) :: X, Y</p><p>END FUNCTION RAT_ADDEND INTERFACE</p></li><li><p>Supercomputing Center Supercomputing Center 1818</p><p> (10/12)(10/12)</p><p>Recursive Recursive </p><p> OPTIONAL, INTENE OPTIONAL, INTENE </p><p>TYPE LISTREAL :: DATATYPE (LIST), POINTER :: PREVIOUS, NEXT !Recursive Components </p><p>END TYPE LIST</p></li><li><p>Supercomputing Center Supercomputing Center 1919</p><p> (11/12)(11/12)</p><p>(1)(1) </p><p>Generic Generic </p></li><li><p>Supercomputing Center Supercomputing Center 2020</p><p> (12/12)(12/12)</p><p>(2)(2)MODULE RATIONAL_ARITHMETIC</p><p>TYPE RATIONALINTEGER :: NUMERATORINTEGER :: DENOMINATOR</p><p>END TYPE RATIONAL</p><p>INTERFACE OPERATOR (+)FUNCTION RAT_ADD(X,Y)</p><p>TYPE (RATIONAL) :: RAT_ADDTYPE (RATIONAL), INTENT(IN) :: X, Y</p><p>END FUNCTION RAT_ADDEND INTERFACE</p><p>... ! and other stuff for a complete rational arithmetic facility</p><p>END MODULE RATIONAL_ARITHMETIC</p></li><li><p>Supercomputing Center Supercomputing Center 2121</p><p>Fortran 90Fortran 90 Data abstractionData abstraction</p><p>Data hidingData hiding</p><p>EncapsulationEncapsulation</p><p>Inheritance and ExtensibilityInheritance and Extensibility</p><p>PolymorphismPolymorphism</p><p>ReusabilityReusability</p></li><li><p>Supercomputing Center Supercomputing Center 2222</p><p>Fortran 90Fortran 90 (1/4)(1/4)</p><p>Data AbstractionData Abstraction </p><p>) ) </p><p>Fortran 90Fortran 90 , , </p><p>TYPE T1INTEGER(KIND=1) :: heightREAL(KIND=1) :: weight</p><p>END TYPE T1TYPE T2</p><p>INTEGER(KIND=2) :: heightREAL(KIND=2) :: weight</p><p>END TYPE T2</p><p>TYPE T1(n)INTEGER(KIND=n) :: heightREAL(KIND=n) :: weight</p><p>END TYPE T1</p></li><li><p>Supercomputing Center Supercomputing Center 2323</p><p>Fortran 90Fortran 90 (2/4)(2/4)</p><p>Data HidingData HidingPUBLIC, PRIVATE PUBLIC, PRIVATE </p><p>PRIVATE ! set default visibilityINTEGER :: pos, store, stack_size ! hiddenINTEGER, PUBLIC :: pop, push ! not hidden</p></li><li><p>Supercomputing Center Supercomputing Center 2424</p><p>Fortran 90Fortran 90 (3/4)(3/4)</p><p>EncapsulationEncapsulation </p><p>data hiding, module/module procedure, usedata hiding, module/module procedure, use modulemodule renamerename </p><p>MODULE globalsREAL, SAVE : a, b, cINTEGER, SAVE :: i, j, k</p><p>END MODULE globals</p><p>USE globals ! allows all variables in the module to be accessedUSE globals, ONLY: a, c ! allows only variables a and c to be accessedUSE globals, r =&gt;a, s =&gt; b ! allows a and b to be accessed with local variables r and s</p></li><li><p>Supercomputing Center Supercomputing Center 2525</p><p>Fortran 90Fortran 90 (4/4)(4/4)</p><p>Inheritance and ExtensibilityInheritance and Extensibility </p><p> supersuper--type type subsub--type type </p><p>PolymorphismPolymorphismGeneric Generic polymorphism polymorphism </p><p>ReusabilityReusabilitymodulemodule unitunit </p></li><li><p>Supercomputing Center Supercomputing Center 2626</p><p>Fortran 77, C/C++Fortran 77, C/C++ Fortran 90Fortran 90 </p></li><li><p>Supercomputing Center Supercomputing Center 2727</p><p>((http://www.comphys.unihttp://www.comphys.uni--duisburgduisburg. de / . de / Fortran90/pl/pl.html) Fortran90/pl/pl.html) </p><p>Functionality Fortran 77 C C++Fortran</p><p>90Numerical Robustness 2 4 3 1Data Parallelism 3 3 3 1Data Abstraction 4 3 2 1Object Oriented Programming 4 3 1 2Functional Programming 4 3 2 1Average 3.4 3.2 2.2 1.2</p></li><li><p>Supercomputing Center Supercomputing Center 2828</p><p>Fortran 77, C/C++Fortran 77, C/C++ (1/5)(1/5)</p><p>Numerical RobustnessNumerical Robustness11: Fortran90 : Fortran90 </p><p>numeric polymorphism, kind type, numeric polymorphism, kind type, , , numeric environmental inquiry numeric environmental inquiry </p><p>22: Fortran 77: Fortran 77complex type complex type </p><p>33: C++: C++CC polymorphism polymorphism </p><p>44: C: C</p></li><li><p>Supercomputing Center Supercomputing Center 2929</p><p>Fortran 77, C/C++Fortran 77, C/C++ (2/5)(2/5)</p><p>Data parallelismData parallelism11: Fortran90 : Fortran90 </p><p>Fortran 90Fortran 90 </p><p>Fortran 77, C, C++Fortran 77, C, C++ </p></li><li><p>Supercomputing Center Supercomputing Center 3030</p><p>Fortran 77, C/C++Fortran 77, C/C++ (3/5)(3/5)</p><p>Data AbstractionData Abstraction11: Fortran90 : Fortran90 </p><p>22: C++: C++ </p><p>33: C: C Fortran 77 Fortran 77 </p><p>44: Fortran 77: Fortran 77</p></li><li><p>Supercomputing Center Supercomputing Center 3131</p><p>Fortran 77, C/C++Fortran 77, C/C++ (4/5)(4/5)</p><p>11: C++ : C++ </p><p>22: Fortran90 : Fortran90 polymorphic polymorphic </p><p>33: C: C Fortran 77 Fortran 77 </p><p>44: Fortran 77: Fortran 77</p></li><li><p>Supercomputing Center Supercomputing Center 3232</p><p>Fortran 77, C/C++Fortran 77, C/C++ (5/5)(5/5)</p><p>Functional ProgrammingFunctional Programming11: Fortran90: Fortran90</p><p>lazy evaluation lazy evaluation : : </p><p>22: C++ : C++ polymorphism polymorphism </p><p>33: C: C</p><p>44: Fortran 77: Fortran 77recursion, recursion, </p></li><li><p> II II </p><p>Numerical RobustnessNumerical Robustness</p><p> Fortran 90Fortran 90 </p><p> . . </p></li><li><p>Supercomputing Center Supercomputing Center 3434</p><p>Numerical RobustnessNumerical Robustness</p><p>, , (()) 44 </p><p>type kind mechanismtype kind mechanismnumeric approximation modelnumeric approximation modelenvironmental intrinsic functionenvironmental intrinsic function</p></li><li><p>Supercomputing Center Supercomputing Center 3535</p><p>Numeric Kind Parameterization (1/2)Numeric Kind Parameterization (1/2)</p><p>Fortran 77Fortran 77*size*size</p><p>REAL = REAL*4REAL = REAL*4DOUBLE PRECISION = REAL*8DOUBLE PRECISION = REAL*8</p><p>Fortran 90Fortran 90 kind kind kind kind implementationimplementation REALREAL 4, DOUBLE PRECISION4, DOUBLE PRECISION 88 </p><p>REAL = REAL(4) = REAL(kind=4)REAL = REAL(4) = REAL(kind=4)DOUBLE PRECISION = REAL(8) = REAL(kind=8)DOUBLE PRECISION = REAL(8) = REAL(kind=8)</p></li><li><p>Supercomputing Center Supercomputing Center 3636</p><p>Numeric Kind Parameterization (2/2)Numeric Kind Parameterization (2/2)</p><p>Intrinsic Function: Intrinsic Function: KINDKINDImplementationImplementation kind kind </p><p>INTEGER, PARAMETER :: SINGLE = KIND(1.0), &amp;DOUBLE = KIND(1D0)</p><p>REAL(KIND=SINGLE) single precision variables REAL(KIND=DOUBLE) double precision variables </p></li><li><p>Supercomputing Center Supercomputing Center 3737</p><p>Intrinsic Function: Intrinsic Function: SELECTED_REAL_KINDSELECTED_REAL_KIND kind kind : : </p><p>INTEGER, PARAMETER :: P9 = SELECTED_REAL_KIND(9)</p><p>REAL(KIND=P9) 9 digit (at least) precision real variables </p><p>1.41_SINGLE and 1.41 are the same,1.41_DOUBLE and 1.41D0 are the same,1.41_P9 is the appropriate 9+ digit representation of 1.41, and typically will be equivalent to 1.41_SINGLE(Cray) or 1.41_DOUBLE(IBM)</p></li><li><p>Supercomputing Center Supercomputing Center 3838</p><p>Numeric Polymorphism (1/5)Numeric Polymorphism (1/5)</p><p>Intrinsic Function: Intrinsic Function: GGeneric eneric SINGLE x SINGLE x COS(x) is singleCOS(x) is singleDOUBLE x DOUBLE x COS(x) is doubleCOS(x) is double</p><p>Fortran 90Fortran 90 generic generic . . </p><p>interface block interface block generic name generic name generic namegeneric name </p></li><li><p>Supercomputing Center Supercomputing Center 3939</p><p>Numeric Polymorphism (2/5)Numeric Polymorphism (2/5)</p><p>integerinteger realreal swapswap </p><p>SUBROUTINE swapint (a, b)INTEGER, INTENT(INOUT) :: a, bINTEGER :: temptemp = a; a = b; b = temp</p><p>END SUBROUTINE swapint</p><p>SUBROUTINE swapreal (a, b)REAL, INTENT(INOUT) :: a, bREAL :: temptemp = a; a = b; b = temp</p><p>END SUBROUTINE swapreal</p></li><li><p>Supercomputing Center Supercomputing Center 4040</p><p>Numeric Polymorphism (3/5)Numeric Polymorphism (3/5)</p><p>generic name generic name swapswap INTERFACE swap ! generic name</p><p>SUBROUTINE swapreal (a,b)REAL, INTENT(INOUT) :: a, b</p><p>END SUBROUTINE swaprealSUBROUTINE swapint (a, b)</p><p>INTEGER, INTENT(INOUT) :: a, bEND SUBROUTINE swapint</p><p>END INTERFACE</p><p>!main programINTEGER :: m,nREAL :: x,y...CALL swap(m,n)CALL swap(x,y)</p></li><li><p>Supercomputing Center Supercomputing Center 4141</p><p>Numeric Polymorphism (4/5)Numeric Polymorphism (4/5)</p><p>INTERFACE SMOOTH ! SMOOTH is the generic nameINTEGER FUNCTION SMOOTH_INT(AA) ! for procedures SMOOTH_INT</p><p>INTEGER :: AA(:,:) ! SMOOTH_SINGLEEND FUNCTION SMOOTH_INT ! SMOOTH_DOUBLE</p><p>! SMOOTH_RATIONALINTEGER FUNCTION SMOOTH_SINGLE(AA)</p><p>REAL(SINGLE) :: AA(:,:) ! AA is an assumed shape two-END FUNCTION SMOOTH_SINGLE ! dimensional array in each case.</p><p>INTEGER FUNCTION SMOOTH_DOUBLE(AA)REAL(DOUBLE) :: AA(:,:)</p><p>END FUNCTION SMOOTH_DOUBLE</p><p>INTEGER FUNCTION SMOOTH_RATIONAL(AA)TYPE(RATIONAL) :: AA(:,:)</p><p>END FUNCTION SMOOTH_RATIONALEND INTERFACE</p></li><li><p>Supercomputing Center Supercomputing Center 4242</p><p>Numeric Polymorphism (5/5)Numeric Polymorphism (5/5)</p><p> generic namegeneric name </p><p>INTERFACE COS ! Extends the generic propertiesFUNCTION RATIONAL_COS(X) ! of COS to return results of</p><p>TYPE(RATIONAL) :: RATIONAL_COS ! type RATIONAL, assuming theTYPE(RATIONAL) :: X ! argument is of type RATIONAL.</p><p>END FUNCTION RATIONAL_COS END INTERFACE</p></li><li><p>Supercomputing Center Supercomputing Center 4343</p><p>Numeric Approximation Model (1/3)Numeric Approximation Model (1/3)</p><p>ImplementationImplementation numerical numerical 1616intrinsic function intrinsic function </p><p>Environmental inquiry: 9Environmental inquiry: 9Numeric manipulation: 7Numeric manipulation: 7</p></li><li><p>Supercomputing Center Supercomputing Center 4444</p><p>Numeric Approximation Model (2/3)Numeric Approximation Model (2/3)</p><p>wherewhere</p><p>x x is the real value is the real value ss is (the sign of the value) is (the sign of the value) b b is the radix (base) and is usually 2; is the radix (base) and is usually 2; bb is constant for a given real kind is constant for a given real kind p p is the base b precision; is the base b precision; pp is constant for a given real kind is constant for a given real kind ee is the base is the base bb exponent of the value exponent of the value </p><p>is the digit, base is the digit, base bb, of the value; ; , of the value; ; may be 0 only if all are 0may be 0 only if all are 0</p><p> == pibfsbx iie ,,1</p><p>if thiif if</p><p>bf i </p></li><li><p>Supercomputing Center Supercomputing Center 4545</p><p>Numeric Approximation Model (3/3)Numeric Approximation Model (3/3)</p><p>IEEE arithmeticIEEE arithmeticbb = 2 : binary representation= 2 : binary representation...</p></li></ul>


View more >