Sender: QUASAR (Bikiş), News District: Fortran
Title: Comparison of Fortran 77, C, C and Fortran 90 (reproduced)
Sending station: Nanjing University Small Lily Station (Tue Jun 1 10:59:14 2004)
海星 云 - 文 阅 阅 [Discussion Forum: Mathtools]
Sender: Huicai (Old Amera), Letter Area: SCICOMP
Title: Comparison of Fortran 77, C, C and Fortran 90 (reproduced)
Sending station: 海星 云 (December 19, 2002 10:38 Thursday), station letters
[The following text reprinted from the Fortran discussion area]
[Original article published by Huicai]
Comparison of Fortran 77, C, C and Fortran 90
http://www.9cbs.net/develop/Article/16/16085.shtm
In the past 30 years, starting from Fortran 77, Fortran has become the main language of computing science. In this time, Fortran's numerical ability becomes very stable and better than other computer languages; the biggest change comes from growing various reliability The type of the numerical process library. Fortran Union (Union), its skill, the expansion value library gives a good foundation for computational science.
However, in the past decade, the importance of dynamic data structures (especially dynamic arrays) is not rising, UNIX workstations, complex interactive visualization tools, and closer parallel architecture - Fortran 77 is not implemented - It is the most obvious example of other languages as a computational language. The most obvious example is C. The recent C has also caused people's interest. Fortran makes up for its shortcomings in modern scientific calculations by developing to Fortran 90. This part is a usual Work is to compare the adaptability of scientific calculations in four languages. These four languages are representatives of C, C, C ) and two Fortran (Fortran 77, Fortran 90). The following table summarizes this Compare, the later content attempts to explain this level sort, from the best (1) to the worst (4)..
Function ------------ F77 - C - C - F90
Numerious robustness ---- 2 ---- 4 --- 3 ----- 1
Data parallelism ---- 3 ---- 3 --- 3 ----- 1
Data abstraction ------- 4 ---- 3 --- 2 ----- 1
Object-oriented program - 4 ---- 3 --- 1 ----- 2
Function type programming ---- 4 ---- 3 --- 2 ----- 1
Average rating ------ 3.4 - 3.2 - 2.2 - 1.2
1 numerical robustness
Numeric Polymorphism (numerical polymorphism) is an example of a graphic smoothing process given a generic name. The general capability described here is an additional numerical robustness as Fortran 90 exceeding Fortran 77 and C. Features. Fortran 77, Fortran 90, and Version of Smooth subsections are also given below for comparison. (Note that the Fortran 90 version uses the parallelism described in Section 4)
Numerical polymorphism, plus the actual type of parameters, decimal precision selection, and digital environment variable check, etc., prove the first in Fortran 90 in these four languages. Fortran 77 is in the second reason lies in it Complex variables are supported, which is important in many computational science applications. C is squeezed that the third bit is due to its ability to develop in the usual domain.
2 data parallelization
In these four languages, only the Fortran 90 has the ability to scientifically valuable data parallelism; other three languages are basically the same, that is, all. This explains four languages in this area. Rank.
Here is a set of Fortran 77 and C processes that completed Gaussian.
*********************************************************** ****************
* Programming determines the correct sub-process processing process: pivot.f, triang.f, and back.f. ** sub-process determines the solution of a series of synchronous equations *
*********************************************************** ****************
* 234567
Program TestG
Integer IMAX, JMAX
Parameter (iMax = 3, jmax = 4)
Real Matrix (IMAX, JMAX)
Real Matrix (IMAX)
Integer I, J, N
Data (Matrix (i, j), j = 1, jmax), i = 1, iMax)
/-1.0, 1.0, 2.0, 2.0, 3.0, -1.0, 1.0, 6.0,
-1.0, 3.0, 4.0, 4.0 /
n = iMax
Write (*, *) / "the Original Matrix, /", N, / "BY /", N = 1, / ": /"
Call Wrtmat (Matrix, N, N 1)
Call Pivot (Matrix, N)
Write (*, *) / "the massix after pivoting: /"
Call Wrtmat (Matrix, N, N 1)
Call Triang (Matrix, N)
Write (*, *) / "The Matrix After Lower Triangulation: /"
Call Wrtmat (Matrix, N, N 1)
Call Back (Solvec, Matrix, N)
Write (*, *) / "The Solution Vector After Back Substitution: /"
Write (*, *) / "**************************************** ** / "
Write (*, *) (Solvec (i), i = 1, n)
Write (*, *) / "**************************************** ** / "
end
*********************************************************** ******************
* Sub-process determines the maximum value of the first column coefficient matrix, exchange the line and first line of the maximum value, *
* Processor then repeats this processing for other rows and columns, for each stack, column location *
* The location of the line is increased (ie, 1st line - 1st column, then Chain 2 - Lein 2, then Chain 3 - News)
* 3 columns, etc. *
*********************************************************** ******************
* 234567
Subroutine Pivot (Matrix, N)
Integer I, J, K, N
Real Matrix (N, N 1), MaxVal, Tempval
DO 10, J = 1, N
Maxval = matrix (j, j)
DO 20, I = J 1, N
IF (MaxVal .lt. Matrix (i, j)).
Maxval = matrix (i, j)
DO 30, K = 1, N 1
Tempval = matrix (i, k)
Matrix (i, k) = matrix (j, k)
Matrix (J, K) = Tempval
30 Continue
ENDIF
20 Continue
10 Continue
end
***********************************************
* Complete low-level decomposition of a input matrix *
***********************************************
* 234567
Subroutine Triang (Matrix, N)
Integer I, J, K, N
Real Matrix (N, N 1), Pivot, PCELEM
DO 10, J = 1, N
Pivot = Matrix (J, J)
DO 20, K = J 1, N 1
Matrix (J, K) = Matrix (J, K) / Pivot
20 Continue
DO 30, i = J 1, N
PCELEM = Matrix (i, j)
DO 40, K = J 1, N 1
Matrix (i, k) = matrix (i, k) - PCELEM * MATRIX (J, K)
40 Continue
30 Continue
end
*********************************************************** *********
* The child process calculates a solution amount from a parameter matrix that has undergone low-level decomposition.
*********************************************************** *********
* 234567
Subroutine Back (Solvec, Matrix, N)
INTEGER N
Real solid (n), Matrix (N, N 1), SUM
Solvec (n) = matrix (n, n 1)
DO 10, I = N -1, 1, -1
SUM = 0.0
DO 20, J = I 1, N
SUM = SUM Matrix (i, j) * Solvec (j)
20 Continue
Solvec (i) = matrix (i, n 1) - sum
10 Continue
end
*********************************************************** **********
* The program of the beta process Bisec.f, Bisec.f determines the solution of an equation (f.f) *
* But this function does assume that the function -f is supported by two values. That is, the end of the user *
* Solution between * no more than one *
*********************************************************** **********
* 234567
Program testbs
Real Xleft, XRight
Real f
External f
Write (*, *) / "please enter an initial left and right value: /"
Read (*, *) XLEFT, XRIGHT
Call Bisec (F, Xleft, XRight)
end
Here is the C process of the same algorithm:
/ ************************************************** *******
* Determine three functions (pivot.c, triang.c, back.c) Programs correctly processed *
* These functions determine the solution of a series of synchronous equations *
*********************************************************** ****** /
#include
#define IMAX 3
#define jmax 4
Float Matrix [IMAX] [jmax] = {{-1.0, 1.0, 2.0, 2.0},
{3.0, -1.0, 1.0, 6.0},
{-1.0, 3.0, 4.0, 4.0}
}
FLOAT SOLVEC [IMAX] = {0.0, 0.0, 0.0};
Main ()
{
Void WRT_OUTPUT (VOID);
Void Pivot (Void);
Void Triang (Void);
Void back (void);
Void WRT_VECTOR (Void);
(void) Printf ("THE Original Matrix% D BY% D: / N", IMAX, JMAX);
(void) WRT_OUTPUT ();
(void) pivot ();
(void) Printf ("The Matrix After Pivoting: / N");
(void) WRT_OUTPUT ();
(void) Triang ();
(void) Printf ("" The Matrix After Lower Decomposition: / N ");
(void) WRT_OUTPUT ();
(void) back ();
(Void) Printf ("The Solution Vector After Back Substitution: / N");
(void) WRT_VECTOR ();
}
/ ************************************************** **********
* Decide the maximum element of the first column in the parameter matrix and move the first column containing the maximum line *
* To the first line. Then repeat other rows and columns to do this for each overlay *
* Generation, the location of the column and the position of the line increase (ie, Chain 1 - Level 1, then Chain 2 - *
* Less 2, then Chain 3 - Lesson 3, etc.
*********************************************************** ********** /
Void Pivot ()
{
INT I, J, K;
Float MaxVal, Tempval;
For (j = 1; j Maxval = matrix [j] [j]; For (i = (j 1); i IF (MaxVal Maxval = matrix [i] [j]; FOR (k = 0; k <= iMax; k ) { Tempval = matrix [i] [k]; Matrix [i] [k] = matrix [j] [k]; Matrix [J] [K] = TEMPVAL; } } } } } / ****************************************** * Complete a function of low-level decomposition of an input matrix * ******************************************* / Void Triang (Void) { INT I, J, K; Float Pivot, PCELEM; For (j = 0; j Pivot = matrix [j] [j]; For (k = (j 1); k <= iMax; k ) { Matrix [J] [K] = Matrix [J] [K] / Pivot; } For (i = (j 1); i PCELEM = Matrix [i] [j]; for (k = (j 1); k <= iMax; k ) { Matrix [i] [k] = matrix [i] [k] - (PCELEM * MATRIX [J] [K]); } } } } / ************************************************** ********* * The child process calculates a solution amount from a parameter matrix that has undergone low-level decomposition. *********************************************************** ******* / Void Back (void) { INT I, J; Float Sum; Solvec [iMax - 1] = Matrix [iMax - 1] [jmax -1]; For (i = (IMAX -1); i> -1; i--) { SUM = 0.0; For (j = (i 1); j SUM = SUM MATRIX [I] [J] * SOLVEC [J]; } Solvec [i] = matrix [i] [iMAX] - SUM; } } Void WRT_OUTPUT (VOID) { INT I, J; (void) PRINTF ("************************************************************************************************************** For (i = 0; i For (j = 0; j <(jmax - 1); J ) { (void) Printf ("% f", Matrix [i] [j]); } (void) Printf ("% f / n", Matrix [i] [jmax - 1]); } (void) Printf ("************************************************************************************************) ; } Void WRT_VECTOR (Void); { (void) PRINTF ("********************************************************************************************************* (void) Printf ("% f", SOLVEC [0]); (void) Printf ("% f", SOLVEC [1]); (void) PrintG ("% f / n", Solvec [2]); (void) Printf ("************************************************************************************************) ; } / ************************************************** ********** * The program of the test function Bisec.f, Bisec.f determines the solution of an equation (f) * * But this function does assume that the function -f is supported by two values. That is, the end of the user * * Solution between * no more than one * *********************************************************** ********** / #include #include Main () { Void Bisec (float init_left_val, float init_right_val); Float F (Float Value): Float Xleft, XRight; Char line [100]; (void) Printf ("" ""); (void) FGETS (Line, Sizeof (Line), stdin; (void) SSCANF (Line, "% f% f", & xlef, & xright); (void) BISEC (XLEFT, XRIGHT); Return (0); } 3 data abstraction Fortran 90 has a very useful ability to use simple data abstract capabilities. C as an important part of object-oriented programming, there is also a very well data abstract ability. Many benefits can be obtained from data abstraction without the additional complexity of object-oriented programming. Therefore, the Fortran 90 has a weak advantage in this regard. Fortran 77 and C are more inferior to Fortran 90 and C , although C is ranked in Fortran 77 due to support of the data structure over the Fortran 77. 4 Object-Oriented Programming Because the Fortran 90 does not support automatic inheritance, C is clearly leading to other languages at this point. The polymorphism of Fortran 90 (general) features are hand-made (rather than automatic) inheritance, this ability It is ahead of C and Fortran 77. Similarly, C is made in this general field to Fortran 77 due to its data structural capabilities. 5 function type programming Due to lack of recursive and data structures, Fortran 77 is clearly ranked in this regard. The other three languages have these basic aspects for function-type programming. However, in these three languages, only Fortran 90 is allowed "lazy evAaluation"; standard C (thus including C ) describes a "order point" between the function parameter evaluation and the function itself, hinders the "lazy evAaluation" of the function parameters. So in this standard, Fortran 90 It should be ranked first. Polymorphism is equally important in the functional programming, C is better than C this. - ※ Source: · 海星 cloud bbs.ustc.edu.cn · [from: 210.45.124.65] - ※ Reprinted: · 海星 云 bbs.ustc.edu.cn · [from: 210.45.124.65] [Previous] [This discussion area] [Next] [Tong theme reading] - ※ Source:. Nanjing University Small Lily Station http://bbs.nju.edu.cn [from: 221.226.2.24]