• Fortran programming language - description, basic commands and functions. Fortran programming language

    I first heard about Fortran in early childhood from my father. He said that in the 70s he had to stand in line for hours at almost the only computer in the university in order to run a primitive code using a punched card. I admit honestly, from then until recently (despite the technical education I received) I was in full confidence that Fortran remained somewhere far out there, in a world where information carriers are strange cardboard boxes with holes, and computers are so expensive, that are perceived as a real attraction.

    Imagine my surprise when I learned that Fortran is not only still used somewhere, it is being developed, in demand and is still relevant. If you also believed until this moment that Fortran had long been dead, then here are a few for you: interesting facts why is he still walking?

    Survived at least 10 updates

    In fact, the Fortran you hear about from teachers at school or university was created between 1954 and 1957. It went down in history as the first fully implemented language. high level, made a small breakthrough in the IT world, but essentially it was not very convenient or functional. IBM began to “finish” it almost immediately; already in 1958, FORTRAN II appeared and, in parallel, FORTRAN III. But it acquired a more or less decent appearance only in the 70s, when fairly portable machines appeared, when a full-fledged IBM FORTRAN IV standard was developed, and FORTRAN 66 appeared with loops, labels, conditional statements, input/output commands and others by modern standards primitive capabilities.

    The latest version appeared in 2010, its name is Fortran 2008 (as you can see, in the course of history, the name stopped being written exclusively in capital letters), the distinctive feature of which is all kinds of parallel computing, which have a positive effect both on the speed of data processing and on the size of the processed arrays. In addition, the release of Fortran 2015 is planned for 2018. From the announcement it follows that it will improve integration with C and also eliminate current shortcomings.

    Among the 30 most popular programming languages

    To date, 0.743% of requests in search engines Regarding programming languages, it is dedicated specifically to Fortran. To give you an idea of ​​how cool this is, just imagine that languages ​​like Lisp, Scala, Clojure, LabVIEW, Haskell, Rust, and VHDL are ranked lower.

    Can work on Android (and more)

    Over its long history, compilers for Fortana have been developed by companies such as IBM, Microsoft, Compaq, HP, Oracle, thanks to which today the language is compatible with Windows, Mac OS and Linux. Moreover, convenient application with the compiler you can now take with you, thanks to the CCTools application for Android. You can run the compiler on your iPhone, but in this case you need to do a little magic.

    Competes with MATLAB

    So far, this text has not said the main thing, namely the scope of Fortran. So this is a language in demand in science and engineering, used in whole or in part for weather forecasting, oceanography, molecular dynamics, and seismological analysis. In general, this is a real “Data Science” language from the time when the calculator first went on mass sale.

    It is worth recognizing that Fortran owes part of its popularity to its heritage. Over the years, with virtually no competition, the language has acquired a huge base of clients, libraries and add-ons. In addition, each subsequent version of Fortran inevitably supports the previous ones. Therefore, a situation has arisen where there are no significant factors for scientists and engineers to abandon this alliance.

    In fact, Fortran's main competitor today is MATLAB, which is more universal, more functional and convenient. However, MATLAB has strict limitations on the software used, is quite expensive and in most cases is simply unnecessary.

    Has a relatively bright future

    Of course, we cannot predict what will happen in 10-20 years, and how the IT world will change during this time. However, if you look at possible new competitors for Fortran (such as Go), their main disadvantage is their generalization. That is, the creators of Fortran very quickly outlined target audience in the form of scientists, their opinions and wishes have priority. Therefore, it is difficult to imagine that tomorrow they will abandon their “special order” for the sake of some fashion trend. It is on this basis that we can say that another generation of Fortran is leaving boldly.

    And then they'll just release a new version.

    Ministry of Education and Science of the Russian Federation

    Ural Federal University

    named after the first President of Russia

    PROGRAMMING BASICS

    IN FORTRAN

    Tutorial

    Yekaterinburg

    Introduction. 3

    Historical information. 5

    Program structure... 8

    Differences between Fortran 90 and Fortran 77. 11

    Access to computing resources. 15

    Running tasks on the cluster. 17

    Rewrite program texts on the server. 17

    Compilation of programs. 17

    Launching the program on the account. 19

    Data types. 22

    Whole constant. 22

    Real constant. 23

    Double precision real constant. 23

    Complex constant. 23

    Double precision complex constant. 24

    Logical constant. 24

    Text constant. 24

    Operators for describing data types. 26

    INTEGER of an integer type. 26

    REAL and DOUBLE PRECISION real type. 27

    COMPLEX and DOUBLE COMPLEX complex type. 28

    CHARACTER is a character type. 29

    LOGICAL is a logical type. 29

    DIMENSION of arrays. 30

    Attribute PARAMETER.. 32

    Varieties of built-in data types. 35

    Expressions, operations and assignments. 36

    Arithmetic expressions. 36

    Expressions of attitude. 37

    Logical expressions. 38

    Rules for evaluating expressions. 38

    I/O operators. 39

    Input operator DATA.. 39

    Input statement READ.. 40

    The WRITE output statement. 41

    PRINT display operator. 42

    I/O Format Statement (FORMAT) 43

    Specifications X, T. 43

    Specifier I 44

    Separators. 45

    Specification F.46

    Repeaters. 49

    Specification E.50

    Specification G..51

    Data descriptors. 52

    Conditional operators. 53

    Logical condition operator. 53

    Arithmetic condition operator. 57

    SELECT CASE construction. 60

    Loop operators. 62

    Loop operator DO.. 62

    DO WHILE loop operator. 64

    Stop operator STOP. 65

    Loop exit operator EXIT. 66

    Transition operators. 67

    Bus-word transition operator GOTO.. 67

    Computed jump operator GOTO.. 67

    Conditional jump operator IF … GOTO.. 68

    Working with arrays. 69

    Entering arrays. 69

    Output of arrays. 71

    Processing arrays. 73

    Subroutines.. 76

    Operator-function. 78

    Subroutine-function FUNCTION.. 81

    Subprocedure SUBROUTINE. 83

    Working with external files. 85

    Opening operator file OPEN.. 85

    File closing operator CLOSE. 86

    Examples of working with files. 86

    Literature. 89

    Introduction

    A characteristic feature of parallel computers is the ability to simultaneously use a large number of processors to process information. Application of multiprocessor computing systems(MVS) poses two problems of constructing parallel algorithms: parallelizing existing sequential algorithms and creating new algorithms with a focus on parallel computing systems.

    The most common programming technology for parallel computers distributed memory is currently MPI. The main way parallel processes interact in such systems is by passing messages to each other. This is reflected in the name of this technology - Message Passing Interface. The MPI standard defines an interface that must be followed both by the programming system on each computing platform and by the user when creating their programs. The MPI communication library has become a generally accepted standard in parallel programming using a message passing mechanism.

    An MPI program is a set of independent processes, each of which performs its own own program(not necessarily the same one), written in C or FORTRAN. In FORTRAN, most MPI procedures are subroutines (called using CALL operator), and the error code is returned through the additional last parameter of the procedure. Several procedures written as functions do not return an error code. There is no requirement to strictly adhere to the case of characters in the names of subroutines and named constants. Arrays are indexed with 1. MPI objects, which are structures in C, are represented as integer arrays in FORTRAN.

    The IMM is programmed in Fortran. The main difficulty in using it for large problems is coordinating the interaction of parts of the large problem. Fortran 90 includes mechanisms for interacting objects in accordance with object-oriented programming technology, which facilitate teamwork on a large project. These are modules for designing libraries, structures and derived data types for organizing complex data, dynamic memory allocation, as well as a number of mechanisms for processing arrays, including the formation of various cuts (sections). The ability to combine in one family (genus) standard processing procedures that differ in the types of their arguments can be a useful tool in a number of tasks. Kinds (families) of data types allow you to easily customize the implementation of the type based on the properties of the hardware (for example, the INTEGER type can be declared long or short through the KIND type control). Some style rules can help development, for example, declaring entrance, exit and changeable parameters procedure helps to find errors in the interaction of program units. Rules for recording data properties, comments, and other elements make written programs easier to read, which speeds up the search for errors.

    Historical background

    1954 – IBM, the first language translator Fortran.

    1958 – FortranII.

    1962 – FortranIV.

    1966 – Fortran 66.

    1978 – Fortran 77.

    A modification of the Fortran language that appeared in 1958 was called FortranII and contained the concept of a subroutine and common variables to provide communication between segments.

    By 1962, the appearance of a language known as Fortran IV. Development completed in 1966 American standard into ANSI (American National Standards Institute) language, the language is called Fortran 66. In 1978, the second version of the ANSI standard was developed - the language Fortran 77, including elements of structured programming, for example, structured IF, character types.

    The third version of the ANSI standard is Fortran 90, implemented in 1991. Fortran 90 is the development of language Fortran 77, so a program written in Fortran 77, can be compiled and run as a program on Fortran 90. Standard Fortran 90 Standard introduces many new facilities for array operations, new precision specification methods, free format source code, recursion, dynamic arrays etc.

    Programs in the current standard language Fortran 77 can be compiled successfully by compilers Fortran 90 without any changes. However, the program structure in the language Fortran 90 may differ significantly from the structure of an equivalent program in Fortran 77. The programmer must beware of mixing the two styles.

    To the same extent, the compiler with Fortran 90 requires providing explanations for the reporting of certain inconsistency (inconsistency) codes, that is, the use of operators or variables that are allowed beyond the set of rules that fall outside the scope of the standard.

    Fortran takes pride of place among modern programming languages. It is one of the first high-level programming languages ​​and from its very birth it was intended to solve complex computing problems. Among application programmers, Fortran was initially met with skepticism, since it was believed that the price for the convenience of programming in a high-level language would come at the cost of a significant loss of computational speed. When it comes to modeling complex processes or processing large amounts of information, computational speed is a decisive factor in determining the choice of language, computing platform and programming technology.

    The Fortran programming language is used primarily for scientific computing. Invented in 1954, it is the oldest high-level programming language, followed by Lisp (1958), Algol (1958), and COBOL (1959). The number of scientific libraries written in Fortran and the creation of special translator-compilers allow the language to be used today. In addition, multiple calculators have been created for vectorization, coprocessors, parallelism, which intersperse this language for use in industrial production modern world.

    John Backus, an IBM radio engineer, published articles in 1954 entitled "Preliminary Report", "Specifications for the IBM Matmal Transmula TRANslating System", which gave rise to the term FORTRAN. Then it took another two years of effort from the whole team, which he led, to write the first compiler for the Fortran programming language (25,000 lines for the IBM 704).

    The name of the language was originally written in capital letters FORTRAN and was used to designate language versions up to Fortran 77, as opposed to free versions syntax since Fortran 90. In the Fortran 77 standard, lowercase letters are not part of the language, but most compilers support them in addition to the standard.

    Today, the Fortran programming language is the dominant programming language used in engineering applications. Therefore, it is important that graduate engineers can read and modify Fortran code. From time to time, so-called experts predict that the language will lose its popularity and will soon cease to be used altogether.

    These predictions always failed. Fortran is the most enduring computer programming language in history. One of the main reasons why the Fortran programming language has survived and will survive is inertia software. After a company has spent many resources and perhaps millions of dollars on a software product, it is unlikely that it will translate the software into another language.

    The main advantage of Fortran is that it is standardized by the international bodies ANSI and ISO. Therefore, if a program is written in ANSI, then it will run on any computer with a Fortran 77 compiler. This important information. Thus, programs of the object-oriented programming language Fortran exist in different software devices.

    Stages of creating a language platform:

    1. In 1954-1957, the first compiler was developed from scratch. In those days there were no "high level languages" (=HLL), most operating systems were simple, and the memory was small, something like 16 Kb. The first compiler ran on the IBM 704. This HLL language was much more efficient than assembly programming and very popular in its time.
    2. FORTRAN II was published in 1958. That same year, FORTRAN III was developed but never released into widespread production.
    3. In 1961, FORTRAN IV was created. It contained improvements such as the implementation of the COMMON and EQUIVALENCE statements.
    4. In 1962, an ASA committee began developing a standard for the object-oriented programming language Fortran. This allowed the seller to use it in every new computer. And this fact made it even more popular HLL, the language became available in Apple systems and TRS80.
    5. In 1967, FORTRAN 66, the world's first HLL standard, was released. The publication of the standard meant that the language became more widely implemented than any other. By the mid-1970s, virtually every computer, mini, or mainframe was equipped with the standard FORTRAN 66 language. The language used if-statements, goto-statements, and spagethi programs. This type of structured programming became popular in the 60s and 70s.
    6. "Fortran" existed on punched cards in particular, with the FMS system, optimizing the layout of its sources until Fortran 90 introduced a "free" syntax. In it, the Fortran array code starts from the 7th column and should not exceed 72 thousand characters.

    It should also be noted that before Fortran 90, spaces had no meaning between the 7th and 72nd column. Thus the cycle "DO I = 1.5" can also be written "DOI = 1.5". On the other hand, "DO I = 1.5" is equivalent to "DOI = 1.5".

    Numerous industrial codes have been written in Nastran, NAG and the IMSL-Fortran library. Compatibility of new versions with previous ones is important. For this reason, Fortran 90 is fully compatible with Fortran 77. However, next versions the standard has already introduced incompatibilities.

    The more advanced languages ​​Fortran 90 and Fortran 95 soon followed, updated to the current Fortran-2003 standard. Given that modern compilers work unlimitedly in all current Windows versions and even support 64-bit processors. Meanwhile, manufacturers have recognized the trend of the times and are offering compilers for Linux in the form of the object-oriented programming language Actor Fortran.

    Prerequisites for using a programming language

    It must be understood that Fortran is still a widely used programming language and is mainly used in the field of discovery. Classic applications, for example in physics or engineering, where extensive and complex mathematical calculations are performed. They are very useful due to the extensive mathematical libraries that exist for different compilers. To sum up, we can say that today Fortran language is still used for a number of reasons:

    • Availability of numerous functional libraries developed over many years.
    • Availability of software in Fortran, which requires very important resources for development when switching to another language is considered too costly.
    • Availability of powerful compilers with built-in Fortran functions that produce very fast executable files.
    • The language is more accessible to an inventor who has not had a specialized computer course.

    Many scientific programs are now written in C and C++, for which compilers are available on most machines. Other compiled languages ​​are sometimes used for scientific computing, and especially for programs such as Scilab or Matlab. The latter also include the BLAS and LAPACK libraries developed in Fortran programming. Matlab was originally a Fortran program distributed to universities and research centers.

    Although Tom Lahey is now the "only" general compiler, Lahey Computer Systems continues to be used by many programmers. Lahey has been working with Fujitsu for several years now, with Lahey concentrating on the Fortran parser and Fujitsu on the code generator. The current Compiler Suite for Windows is called Lahey Fujitsu Fortran 95 (LF95) and is available in different versions, some of which also integrate with Visual Studio.NET 2003.

    There is also an inexpensive version of LF95 Express without its own IDE. The current version is 7.1. on Linux is called by the Lahey/Fujitsu Fortran 95 v6.2 compiler for Linux and is available in two different versions. For example, Pro version includes OpenMP v2.0 compatibility, simple graphics engine Winteracter Starter Kit, math library and scientific library Fujitsu 2 routines.

    Another manufacturer is Absoft. Compilers and C++ exist not only for Windows and Linux, but also for OS X on the Macintosh. These compilers are of interest to developers who need or want to support all three platforms. Unfortunately, Absoft differentiates between 32-bit and 64-bit versions for Linux, currently using version 10.0 of Fortran 95 for 64-bit Linux.

    Relatively new to the market is the EKOPath Compiler Suite. This consists of C++ compilers and a Fortran development environment for Linux, which are also available separately and are mainly aimed at 64-bit AMDusers. It also runs on Intel EM64T. Microsoft also once tried to find a "cheap market" for Fortran and introduced the Microsoft Powerstation to the market.

    The market may have been too small for the software giant, but Digital took over some of the code in 1997 and used its experience with the Digital Unix and OpenVMS compilers. This was the birth of the still very successful Digital Visual Fortran. At some point Digital then moved to Compaq, the compiler was developed to current version Compaq Visual Fortran (CVF) v6.6.

    In addition to "normal" 32-bit platforms, there are various 64-bit compilers, for example for Intel Itanium and Intel EM64T. Although they are not "urgent" for the scope of supply, they are available for free download via Intel Premier Web Support.

    After a one-time, somewhat cumbersome registration, you can use it for a year, with new updates every few weeks. Even older versions will remain available.

    A Fortran program is a sequence of lines of text. The text must follow a specific syntax. For example: a circle of radius r, area c.

    This program reads the real radius and determines the area of ​​a circle with radius r:

    "Radius r:"read (*, *) r;

    area = 3.14159 * r * r;

    write (*, *) "Area =";

    Lines starting with "C" are comments and have no purpose other than to make the program more readable for people. Initially, all Fortran programs were written in capital letters. Most programmers now write lowercase because it's more legible.

    A Fortran program typically consists of a main program or driver and several subroutines, procedures, or subroutines. Main program structure:

    • program name;
    • declarations;
    • statements;
    • stop;
    • end.

    Italics should not be taken as literal text, but rather as general description. The stop statement is optional and may seem unnecessary since the program will stop when it reaches the end anyway, but it is recommended to always end a program with a stop statement to emphasize that the flow of execution is being terminated.

    Column position rules

    Fortran 77 is not a free format language, but has a very strict set of rules for formatting source code. Most important rules are the rules for the arrangement of columns:

    • Col. 1: Blank or “c” or “*” for comments.
    • Col. 2-5: operator mark.
    • Col. 6: continuation of the previous line.
    • Col. 7-72: statement.
    • Col. 73- 80: Sequence number.

    A Fortran line beginning with the letter "c" or an asterisk in the first column is a comment. Comments can appear anywhere in a program. Well written, they are critical to the readability of a program. Commercial codes Fortran files often contain about 50% comments. You may also encounter programs that use exclamation mark(!). This is very non-standard in Fortran 77, but is allowed in Fortran 90.

    The exclamation mark can appear anywhere on a line. Sometimes a statement does not fit on one line, then you can break the statement into two or more lines and use a continuation sign in position.

    1. C23456789 - This demonstrates the position of the column.
    2. "C" - next statement passes through two areas of physical lines.
    3. Area = 3.14159265358979+ * r * r.

    Empty spaces are ignored starting with Fortran 77. Therefore, if you remove all the spaces in Fortran 77, the program is still syntactically correct, although it is almost unreadable to the operators.

    Variable names in Fortran consist of 1-6 characters, chosen from letters a-z and numbers 0-9. The first character must be a letter. Fortran 90 allows variable names of arbitrary length. Fortran 77 does not distinguish between upper and lower case, in fact it assumes all input is upper case. However, almost all F 77 compilers will accept lowercase letters. Each variable must be defined in a declaration. This sets the type of the variable. The most common variable lists are:

    • integer;
    • real;
    • double precision;
    • complex;
    • logical;
    • character.

    The list of variables must consist of names separated by commas. Each variable must be declared exactly once. If a variable is not declared, F 77 uses a set of implicit rules to establish the type. This means that all variables starting with the letters "in" are integers, and all others are real numbers. Many older F 77 programs use these implicit rules, but programmers should not do so because the likelihood of program errors increases dramatically if they declare variables inconsistently.

    Fortran 77 has only one type for integer variables. Integers are typically stored as 32-bit (4 bytes) variables. Therefore, all integer variables must take values ​​in the range [-m, m], where m is approximately 2 * 10 9.

    F 77 has two different types for floating point variables, called real double precision. Some numerical calculations require very high precision and double precision should be used. Typically real is a 4 byte variable and double precision is 8 bytes, but this depends on the machine.

    Non-standard versions of Fortran use real*8 syntax to refer to 8-byte floating point variables. Some constants appear many times in a program. Therefore, it is advisable to define them only once, at the beginning of the program. The parameter operator is used for this. It also makes programs more readable. For example, a program for the area of ​​a circle should be written like this.

    Parameter operator syntax (name = constant, ..., name = constant). Rules for the parameter operator:

    1. A "variable" defined in a parameter statement is not a variable, but a constant whose value can never change.
    2. "Variable" can display at most one parameter statement.
    3. The operator parameter must come before the first executable operator

    Some good reasons to use a parameter - helps reduce typos, easy to change a constant that appears many times in a program.

    Boolean expressions can only have the value .TRUE. or.FALSE. and can be formed by comparison using relational operators.

    You cannot use characters such as "<» или «=» для сравнения в F 77, но можно использовать правильную двухбуквенную аббревиатуру, заключенную точками. Однако такие символы разрешены в Fortran 90.

    Logical expressions can be combined with the logical operators "AND", "OR", "NOT", which have obvious meaning. Truth values ​​can be stored in boolean variables. The assignment is similar to the arithmetic assignment.

    Example: logical a, ba = .TRUE.b = a .AND. 3.LT. 5/2

    The order of priority is very important. The rule is that arithmetic expressions are evaluated first, then relational operators, and finally logical operators. Therefore, b will be assigned .FALSE. In the example above, boolean variables are rarely used in Fortran, but they are often used in conditional statements such as the "if" statement.

    Constant and purpose

    The simplest form of an expression is a constant. There are 6 types of constants corresponding to 6 data types. Here are some integer constants: 10-10032767+15

    Real constants: 1.0-0.252.0E63.333E-1.

    E-notation means to multiply the constant by 10, raised to the power following the "E". Therefore, 2.0E6 is two million, and 3.333E-1 is approximately one third. For constants that are larger than the largest actually allowed, or that require high precision, double precision should be used. The notation is the same as for real constants, except that "E" is replaced by "D".

    Example:2.0D-11D99.

    Here 2.0D-1 is double precision with one fifth, while 1D99 is one followed by 99 zeros.

    The next type is complex constants. They are denoted by a pair of constants (integer or real), separated by a comma and enclosed in parentheses.

    Examples are: (2, -3)(1,9,9E-1). The first number denotes the real part, and the second the imaginary part.

    The fifth type is logical constants. They can only have one of two meanings:

    Please note that dots containing letters are required to be written.

    The last type is character constants. They are most often used as an array of characters called a string. They consist of an arbitrary sequence of characters enclosed in apostrophes (single quotes):

    "Anything goes!"

    "It's a nice day"

    String and character constants are case sensitive. The problem arises if you want to have a real apostrophe in the line itself. In this case, you need to double the apostrophe: “It” “s a nice day”, which means “What a wonderful day”

    Conditional statements are important components of any programming language. The most common of these statements in Fortran is the "if" statement, which actually has several forms.

    The simplest is the logical expression “if” in the Fortran description: if (logical expression) executable statement.

    This should be written on one line, for example when determining the absolute value of x:

    if (x .LT. 0) x = -x

    If more than one statement is to be executed in an "if", then the following syntax should be used: if (logical expression) thenstatementsendif.

    Flow of execution from top to bottom. Conditional expressions are evaluated sequentially until a true value is found. The appropriate code is then executed and the control moves to the next statement after the end "if".

    If statements can be nested multiple levels. To ensure readability, it is important to use proper indentation. Here's an example:

    if (x .GT. 0) thenif (x .GE. y) thenwrite(*,*) "x is positive and x >= y"elsewrite(*,*) "x is positive but x< y"endifelseif (x .LT. 0) thenwrite(*,*) "x is negative"elsewrite(*,*) "x is zero"endif

    Programmers should avoid nesting many levels of "if" statements as it will be difficult to follow.

    You can use any Unix workstation with an F 77 compiler. Experienced programmers recommend using either Sun or Dec.

    A Fortran program consists of plain text that follows certain syntax rules. This is called source code. Programmers use an editor to write source code. The most common editors on Unix are emacs and vi, but they can be a little complex for novice users. You can use a simpler editor such as xedit, which runs under X windows.

    Once a Fortran program is written, it is saved in a file with a “.f” or “.for” extension and the program is converted into machine-readable form. This is done using a special program called a compiler. The Fortran 77 compiler is commonly called f77. The compilation output is given the somewhat cryptic name "a.out" by default, but you can choose a different name if needed. To run the program, simply enter the name of the executable file, for example, "a.out". The compiler translates the source code into object code, and the linker or loader translates it into an executable file. As you can see, this procedure is not at all complicated and is accessible to any user.

    Simulation is one of the most commonly used manufacturing methods and other systems found in modern factories. Most simulation models are built using the object-oriented programming language Actor Fortran, or a simulation software package written in a traditional language. These tools have their limitations. Object-oriented technology has seen increasing adoption in many fields and promises a more flexible and efficient approach to modeling business systems.

    Simula Fortran programming is compared to a conventional scientific programming language called FORTRAN. A typical military simulation model is programmed in both SIMULA and FORTRAN. The SIMULA program was 24% shorter than the FORTRAN version.

    The SIMULA version is also simpler and gives a better picture of the model being simulated. On the other hand, the execution time for production runs is 64% faster with the object-oriented programming language Simula Fortran. Weighing the pros and cons shows that SIMULA will be an increasingly profitable software, with higher personnel costs and lower computer costs.

    CUDA shows how high-performance application developers can harness the power of GPUs using Fortran, a common language for scientific computing and supercomputer performance testing. The authors do not assume any prior parallel computing experience and cover only the basics as well as best practices. The computing efficiency of GPUs using CUDA Fortran is enabled by the target GPU architecture.

    CUDA Fortran for Scientists and Engineers will identify computationally intensive parts of the code and modify the code for data management, parallelism, and performance optimization. All this is done in Fortran, without the need to rewrite the program into another language. Each concept is illustrated with actual examples so you can immediately evaluate the code's performance.

    Perhaps someday a global corporation will “finally globalize” and decide that Fortran is no longer needed, but not now. Thanks to the current capabilities of modern Fortran, many programmers and scientists see it as the future. In addition, there are enough manufacturers in the world who live by developing modern compilers and make good money from this process.

    Mid 50's characterized by rapid progress in the field of programming. The role of programming in machine codes began to decrease, and new types of programming languages ​​began to appear, acting as an intermediary between machines and programmers. The time has come for the second and third generations of programming languages

    Since the mid-50s. XX century began to create the first high-level programming languages. These languages ​​were Machine independent (not tied to a specific type of computer).

    But each language has developed its own compilers - a program that does the compilation.

    Compilation is the translation of a program written in a high-level source language into an equivalent program in a low-level language close to machine code (absolute code, object module, sometimes assembly language)

    FORTRAN programming language

    The first high-level language was created between 1954 and 1957 by a group of programmers led by John Backus at IBM Corporation and this became the next stage in the development of programming languages. It was the FORTRAN programming language. It was intended for scientific and technical calculations. The name Fortran is short for FORmulaTRANslator (formula translator).

    History of the language

    At the end of 1953, John Backus proposed to begin developing an effective alternative to assembler for programming on the IBM 704 PC. By mid-1954, the draft specification of the Fortran language was completed. The first manual for Fortran appeared in October 1956, along with the first compiler, shipped in April 1957. The compiler was an optimizing compiler because customers were reluctant to use a high-level programming language that was unable to generate code with performance lower than assembly.

    At the time, the community was skeptical of the new way of programming and did not believe that Fortran would allow faster and more efficient programming. According to John Backus himself, most of his work was aimed at “being lazy.” He really didn't like writing programs for the IBM 701 in assembler.

    The language has been widely adopted by scientists for writing computationally intensive programs. The inclusion of a complex data type made it particularly suitable for technical applications.

    By 1960, there were versions of Fortran for the IBM 709, 650, 1620, 7090 computers. Its great popularity encouraged competing computer manufacturers to create Fortran compilers for their computers. Thus, by 1963 there were more than 40 compilers for different platforms. This is why Fortran is considered the first widely used programming language.

    Fortran in the USSR

    Fortran appeared in the USSR later than in the West, since at first Algol was considered a more promising language in our country. Communication between Soviet physicists and their colleagues at CERN played a major role in the introduction of Fortran, where in the 1960s almost all calculations were carried out using Fortran programs.

    The first Soviet Fortran compiler was created in 1967 for the Minsk-2 machine, but it did not gain much popularity. The widespread introduction of Fortran began after the creation in 1968 of the FORTRAN-DUBNA compiler for the BESM-6 machine. ES computers, which appeared in 1972, already initially had a Fortran translator (“borrowed” from IBM/360 along with other software)

    Modern Fortran. Virtues of language

    Fortran was widely used mainly for scientific and engineering computing. It is perfect for solving numerical problems, since many libraries have been written over more than 50 years, so the language is used now and is not in danger of being forgotten in the near future. It is still used to this day, however, not so much because of its successful design, but because of the large number of programs written on it, which make no sense to change and, especially, rewrite.

    Probably, if you want to quickly calculate something, then Fortran will be one of the best options. This is precisely why language was invented.

    Its structure allows the compiler to optimize calculations very well.

    Among scientists, for example, there is a saying that any mathematical problem already has a solution in Fortran, and, indeed, you can find among thousands of Fortran packages a package for multiplying matrices, a package for solving complex integral equations, and many, many others.

    Among scientists, for example, there is a saying that any mathematical problem already has a solution in Fortran, and, indeed, among thousands of Fortran packages you can find a package for matrix multiplication, a package for solving complex integral equations, and many, many others. A number of such packages have been created over the decades and are still popular in the scientific community to this day, for example - IMSL ( English).

    Most of these libraries are actually the property of humanity: they are available in source code, well documented, debugged and very effective. Therefore, it is expensive to change, let alone rewrite them in other programming languages, despite the fact that attempts are regularly made to automatically convert FORTRAN code into modern programming languages.

    Modern Fortran (Fortran 95 and Fortran 2003) has acquired the features necessary for effective programming for new computing architectures and allows the use of modern programming technologies, in particular OOP.

    Evolution of language standards

    Fortran is a highly standardized language, which is why it is easily portable to various platforms. New language standards largely maintain continuity with older ones, which makes it possible to use codes from previously written programs and modify them.

    FORTRAN 66 (1972) Based on the IBM standard FORTRAN IV FORTRAN 77 (1980) Many improvements were introduced: Fortran 90 (1991) The language standard was significantly revised. Fortran 95 (1997) Correction of the previous standard. The FORALL operator and construction have been introduced, allowing more flexibility than the WHERE operator and construction to assign arrays and replace cumbersome loops. FORALL allows you to replace any section assignment or WHERE clause, in particular, it provides access to the diagonal of a matrix. This operator is considered promising in parallel computing, facilitating parallelization more efficient than loops. Fortran 2003 (2004) Further development of OOP support in the language. Interaction with the operating system. The following features have also been added: Fortran 2008 (2010) The standard assumes support by means of the parallel computing language (Co-Arrays Fortran). It is also planned to increase the maximum dimension of arrays to 15, add built-in special mathematical functions, etc.

    Compilers

    Since the initial development of the language, Fortran compilers have been produced by IBM. Currently, IBM supplies the VS Fortran optimizing compiler for IBM System z mainframes, the history of the development of various versions of which dates back to 1964, as well as the XL Fortran compiler for platforms based on the PowerPC-AIX architecture, Linux and the Blue Gene supercomputer (a version was also produced for Mac OS X, when Macintosh computers used PowerPC processors). Both of these compilers contain very complex optimizers, the result of continuous scientific work by IBM specialists over half a century. Based on the IBM Fortran XL compiler, Absoft, an IBM business partner, has created and supplied the Absoft Pro Fortran compiler for systems based on PowerPC (Linux, Mac OS X) and Intel (Linux, Mac OS X, Windows) processors.

    The GNU Free Software Foundation produced an open-source Fortran-77 compiler, g77, available for virtually any platform and fully compatible with GCC. Now it has been replaced by the GFortran compiler, which implements almost all the constructs of the Fortran 95 standard and many constructs of the Fortran 2003 and Fortran 2008 standards. It is also fully backward compatible with Fortran 77. There is also an independent project called g95 to create a Fortran-95 compiler based on GCC.

    Features and structure of the program

    Fortran has a fairly large set of built-in mathematical functions and supports working with integer, real and complex numbers of high precision. The expressive means of the language were initially very poor, since Fortran was one of the first high-level languages. Subsequently, many lexical structures characteristic of structural, functional and even object-oriented programming were added to Fortran.

    Punched card with column markings for Fortran.

    The structure of the programs was initially focused on input from punched cards and had a number of properties convenient for this particular case. Thus, the 1st column served to mark the text as a comment (with the symbol C), from 1st to 5th the label area was located, and from 7th to 72nd the actual text of the operator or comment was located. Columns 73 to 80 could be used to number cards (to restore a randomly scattered deck) or for a brief comment; they were ignored by the translator. If the operator's text did not fit into the allotted space (from the 7th to 72nd column), a continuation sign was placed in the 6th column of the next card, and then the operator continued on it. It was impossible to place two or more statements on one line (map). When punch cards became a thing of history, these advantages turned into serious inconveniences.

    That is why in the Fortran standard, starting with Fortran 90, in addition to the fixed format of the source text, a free format appeared, which does not regulate line positions, and also allows you to write more than one operator per line. The introduction of a free format made it possible to create code whose readability and clarity is not inferior to code created using other modern programming languages, such as Java.

    A kind of “calling card” of the old Fortran is the huge number of labels that were used both in unconditional jump operators GOTO and in loop operators, and in format input/output description operators FORMAT. The large number of labels and GOTO statements often made Fortran programs difficult to understand.

    It was this negative experience that became the reason why in a number of modern programming languages ​​(for example, Java) labels and associated unconditional jump operators are greatly modified.

    However, modern Fortran gets rid of the excess of labels due to the introduction of operators such as DO ... END DO, DO WHILE, SELECT CASE. Moreover, modern language standards retain only the classic GOTO operator, which is still used in many languages ​​today. The computed GOTO statement, as well as the ENTRY construct - multiple entry into procedures, have been eliminated.

    Also, the positive features of modern Fortran include a large number of built-in operations with arrays and flexible support for arrays with unusual indexing. Example:

    Real ,dimension (: ,: ) :: V ... allocate (V(- 2 : 2 ,0 : 10 ) ) ! Allocate memory for an array whose indices can ! vary from -2 to 2 (first index) ! and from 0 to 10 - second... V (2 .2 : 3 ) = V (- 1 : 0 .1 ) ! Rotate a piece of an array write(* ,* ) V(1 ,: ) ! Print all elements of array V whose first index is 1. deallocate(V)

    Hello, World!

    Fixed format (spaces in line positions 1 to 6 are marked with “␣” characters):

    ␣␣␣␣␣␣PROGRAM hello ␣␣␣␣␣␣PRINT* , "Hello, World!" ␣␣␣␣␣␣END

    Free format:

    Program hello print * , "Hello, World!" end

    Notes.

    • The PROGRAM statement is optional. Strictly speaking, the only required statement in a Fortran program is the END statement.
    • The choice of uppercase or lowercase letters for writing program statements is arbitrary. From the point of view of modern Fortran language standards, the set of uppercase letters and the set of lowercase letters coincide when writing language statements.

    Interaction with other languages

    Many programming systems allow you to combine object files obtained as a result of translation of a Fortran program with object files obtained from compilers from other languages, which allows you to create more flexible and feature-rich applications. A large number of libraries are also available for the Fortran language, containing both routines for solving classical computing problems (LAPACK, IMSL, BLAS), problems organizing distributed computing (MPI, pvm), and tasks for constructing graphical interfaces (Quickwin, FORTRAN/TK) or accessing DBMS (Oracle).

    Fortran in the USSR

    Notes

    1. See, for example: Netlib Repository at UTK and ORNL
    2. A. M. Gorelik. Evolution of the Fortran programming language (1957-2007) and prospects for its development // Computational methods and programming, 2008, Vol. 9, p. 53-71
    3. Bartenyev O.V. Modern Fortran. - M.: Dialogue MEPhI, 2005. - ISBN 5-86404-113-0
    4. A. M. Gorelik. object-oriented programming in modern Fortran
    5. S. D. Algazin, V. V. Kondratiev. Programming in Visual Fortran. - M.: “Dialogue MEPhI”, 2008. - 448 p. - ISBN 5-8243-0759-8
    6. Gorelik A. M. News
    7. VS FORTRAN
    8. XL Fortran for Linux
    9. Absoft Pro Fortran Compiler Suites General Overview
    10. Sun Studio - Benchmarks
    11. Essay by Alexander Rastorguev about the appearance of Fortran in Dubna
    12. History of computer graphics in Russia

    Literature

    • Fortran. Programmer's Reference Manual. The Fortran Automatic Coding System for the IBM 704 EDPM. - IBM Corp., 1956. - 51 p.
    • ISO/IEC 1539-2:2000 Information technology - Programming languages ​​- Fortran - Part 2: Varying length character strings
    • Robert W. Sebesta. 2.3. IBM 704 computer and the Fortran language // Basic concepts of programming languages ​​= Concepts of Programming Languages ​​/ Transl. from English - 5th ed. - M.: Williams, 2001. - pp. 63-69. - 672 s. - 5000 copies. - ISBN 5-8459-0192-8 (Russian), ISBN 0-201-75295-6 (English)

    Links

    • gfortran - Fortran 95/2003/2008 compiler, part of the GNU Compiler Collection
    • in Progopedia - encyclopedia of programming languages ​​(Russian)