Comparision Between Java and Fortran
Comparision Between Java and Fortran
"#$"%%&
Today
!!
Assigned
!! !!
Program 7b due date extended to 5pm Monday May 9 Final exam Wed. May 11, 7pm C programming
"! Performance "! Language
!!
Topics
!!
!!
Program 7b
4/29/11
C vs. Fortran
!!
www.ibiblio.org/pub/languages/fortran and comments from the Fortran FAQ We can say that the difference between Fortran and C is ...
"! [Fortran "! [C
!!
Quotes:
!!
is a] language designed for numerical computations, and is a] language designed for other purposes (system programming)
!!
Fortran advantages...
"! scientifically
oriented, better optimized code, a lot of existing code, easier to learn, more efficient mathematics, easier to use and more robust, better diagnostics
%&
!"#$"%%&
C
!!
J.V. Ashby, UKs STFC Rutherford Appleton Laboratory Fortran was one of the first high-level languages developed, and the programming model it implicitly contains is shaped by its early target market of mathematicians and scientists who wished to write programs that looked like the mathematical formulae they were used to manipulating on paper. Its very name comes from FORmula TRANslation, and the basic objects of the language, reals, integers, arrays, etc., are direct counterparts of the variables and constants which appear in any mathematical model.
ATMS 391 Spring 2011 4/29/11 6
Fortran
!! !!
C was developed in the early 1970s, largely as a systems' programming language for Unix [2] ... it is much "closer to the machine" in that its datatypes and model of programming map more directly onto the logical representation of data in memory. This gives it more power, but also can prevent several of the important optimisations available to Fortran compilers. On the other hand, a good C programmer can produce hand optimised code which is comparable with machine optimised Fortran. The price paid for this is often in code readability and maintainability. For those that deal with system functionality (such as I/O, interprocess communication, user interfaces, graphics, etc.) ... C's close-to-machine nature is a clear advantage.
ATMS 391 Spring 2011 4/29/11
!!
!!
Java
!!
Performance evaluation
!!
Java looks very similar to C and C++, and incorporates much of C++'s object-oriented programming model [3]. ..distinguishes itself from its predecessors in two major respects:
"! the
!!
We took programs written to perform a sparse matrix-matrix multiply using the same underlying algorithm in each language and ran them on a variety of matrices and on a variety of computers. The time taken was normalised by the cycle time of the processor. The differences between languages are similar in magnitude to the differences between different compilers for the same language. Fortran 90 is faster than C (though not by much and this is very dependent upon the compiler) and Java is considerably slower.
definition in the original language of a large range of class libraries, particularly for user interface activities (window management, mouse interaction, menus, etc.) and being platform independent. This independence is achieved since Java code is either interpreted at run-time (as with BASIC) or it is compiled into machine code for a virtual machine, the Java Virtual Machine (JVM). This compiled code can then be run on any platform
!!
!!
First results
!!
"! in
!!
4/29/11
4/29/11
#&
!"#$"%%&
Overall summary
!!
The results ... suggest that (at least for the limited range of problems considered) Java has still a long way to go before it can be considered a serious contender for numerically intensive computing. On the other hand, the performance of C and Fortran 90 is now so close as to make any distinction between the languages on performance grounds specious. Programmers will, and indeed, should, use the language they are most comfortable with to develop their code.
!!
!!
4/29/11
10
4/29/11
Online versions of full 15-page doc available, such as this: www.nd.edu/~hpcc/solaris_opt/SUNWspro.forte6u1/WS6U1/lib/ locale/C/html/manuals/fortran/prog_guide/11_cfort.html this document is for calling C from Fortran (or v.v.) but contains useful descriptions of language differences. data types I/O character strings loop functionality
4/29/11
Types
"! Fortran "! Fortran
INTEGER is typically C int REAL is typically C float "! Fortran LOGICAL is typically C int "! Fortran CHARACTER is typically C char
!!
!!
Overview
subroutines and functions arrays and index order variable names: case if-then syntax
!!
Case
"! Fortran
11
12
4/29/11
'&
!"#$"%%&
Fortran:
IF (a == 3) THEN ... ELSE IF (b == 7.5) THEN ... ELSE ... ENDIF
!!
C:
If (a == 3) { ... } else if (b == 7.5) { ... } else { ... }
REAL TMP(10) is assumed to run elements 1,2,...,10 "! You can change it when declaring the array, e.g. REAL TMP(0:9)
!!
C starts at zero (always). REAL TMP(M,N) in Fortran; FLOAT TMP[M][N] in C Fortran stored in column-major order; C is row-major If exchanging arrays between Fortran and C, be aware of this.
"! Fortran: A(3,2) "! C:
!! !!
Notation
!!
13
4/29/11
14
4/29/11
Program 7b tasks:
!!
Fortran:
DO i = 2, 14, 3 ... ENDDO
!!
C:
for ( i=2; i<=14; i+=3) { ... }
Program 7b
!! !!
!!
Defaults
!!
!! !!
Defaults
!!
compute and plot the 2D field for lifetime of simulation: of max surface vorticity, wind speed, rain mixing ratio, and min pressure
"!
none.
And...
you can use multiple variable initializations, tests, increments: for ( i=2,j=4; i<3 && j>1; i++, j--)
!!
!!
create plots vs. radius of vertical velocity (max w/height), rainwater mixing ratio, and wind speed
"!
well do this for just one time. well do this for just one time.
!!
15
4/29/11
16
4/29/11
!&