The programming language Fortran dates back to 1957 when a team of IBM engineers released the first Fortran Compiler. During the past 60 years, the language had been revised and updated several times to incorporate more features to enable writing clean and structured computer programs. The present version is Fortran 2018. Since the dawn of the computer era, there had been a constant demand for a “larger” and “faster” machine. To increase the speed there are three hurdles. The density of the active components on a VLSI chip cannot be increased indefinitely and with the increase of the density heat dissipation becomes a major problem. Finally, the speed of any signal cannot exceed the velocity of the light. However, by using several inexpensive processors in parallel coupled with specialized software and hardware, programmers can achieve computing speed similar to a supercomputer. This book can be used to learn the modern Fortran from the beginning and the technique of developing parallel programs using Fortran. It is for anyone who wants to learn Fortran. Knowledge beyond high school mathematics is not required. There is not another book on the market yet which deals with Fortran 2018 as well as parallel programming. FEATURES: Descriptions of majority of Fortran 2018 instructions Numerical Model String with Variable Length IEEE Arithmetic and Exceptions Dynamic Memory Management Pointers Bit handling C-Fortran Interoperability Object Oriented Programming Parallel Programming using Coarray Parallel Programming using OpenMP Parallel Programming using Message Passing Interface (MPI) THE AUTHOR Dr Subrata Ray, is a retired Professor, Indian Association for the Cultivation of Science, Kolkata.
Author(s): Subrata Ray
Publisher: CRC/Chapman & Hall/Taylor & Francis Group
Year: 2020
Language: English
Pages: 683
Tags: Fortran 2018, Parallel Programming
Cover......Page 1
Half Title......Page 2
Title Page......Page 4
Copyright Page......Page 5
Dedication......Page 6
Table of Contents......Page 8
Preface......Page 24
Acknowledgments......Page 26
Author......Page 28
1: Preliminaries......Page 30
1.1 Character Set......Page 31
1.2 Identifiers......Page 32
1.5 Integer Constants......Page 33
1.6 Real Constants......Page 34
1.8 Complex Constants......Page 35
1.12 Character Constants......Page 36
1.15 Variable Declarations......Page 37
1.16 Meaning of a Declaration......Page 38
1.18 Named Constants......Page 39
1.19 Keywords......Page 40
1.21 Delimiters......Page 41
1.23 Free Form......Page 42
1.24 Continuation of Character Strings......Page 44
1.26 IMPLICIT NONE......Page 45
1.27 IMPLICIT......Page 46
1.29 Type Declarations......Page 47
1.32 END Statement......Page 48
1.34 Number System......Page 49
1.38 Initialization Using DATA Statement......Page 50
1.40 Integer Variables and BOZ Numbers......Page 51
1.42 INCLUDE Directive......Page 52
1.45 Compilation and Execution of Fortran Programs......Page 53
2.1 Arithmetic Operators......Page 54
2.3 Assignment Sign......Page 55
2.4 Rules for Arithmetic Expressions......Page 56
2.5 Precedence of the Arithmetic Operators......Page 57
2.6 Multiple Statements......Page 58
2.7 Mixed-Mode Operations......Page 59
2.8 Integer Division......Page 61
2.10 Variable Assignment—Comparative Study......Page 62
2.11 Library Functions......Page 64
2.13 Programming Examples......Page 65
2.14 BLOCK Construct......Page 66
2.15 Assignment of BOZ Numbers......Page 67
2.17 Relational Operators......Page 68
2.20 Logical Operators......Page 69
2.22 Precedence of the Operators Discussed So Far......Page 71
3.1 GO TO Statement......Page 72
3.3 IF-THEN-ELSE......Page 73
3.4 ELSE-IF......Page 75
3.5 Nested IF......Page 77
3.7 Rules of Block IF......Page 78
3.8 CASE Statement......Page 80
3.9 CASE DEFAULT......Page 82
3.12 EXIT Statement and CASE......Page 83
3.13 Rules of CASE......Page 84
3.14 Programming Example......Page 85
3.15 DO Statement......Page 86
3.17 Infinite Loop......Page 88
3.19 CYCLE Statement......Page 89
3.20 DO WHILE......Page 90
3.21 Nested DO......Page 92
3.22 CYCLE, EXIT and the Nested Loop......Page 94
3.24 Rules of DO Statement......Page 95
3.25 Remark about Loop Statements......Page 99
4.2 Concatenation......Page 100
4.3 Collating Sequence......Page 101
4.5 Comparison of Character Strings......Page 102
4.6 Lexical Comparison Functions......Page 103
4.8 Trimming and Adjusting a String......Page 104
4.9 REPEAT......Page 105
4.11 Character Substring......Page 106
4.12 Programming Examples......Page 108
4.13 Library Functions INDEX, SCAN and VERIFY......Page 110
4.14 CASE and CHARACTER......Page 113
4.15 NEW LINE......Page 114
5: Precision and Range......Page 116
5.1 SELECTED_INT_KIND......Page 117
5.3 SELECTED_REAL_KIND......Page 119
5.5 KIND Intrinsic......Page 121
5.7 KIND and Character Handling Intrinsics......Page 123
5.9 DOUBLE COMPLEX......Page 124
5.10 IMPLICIT and SELECTED KIND......Page 125
5.12 Named Kind Constants......Page 126
6.1 Array Declaration......Page 128
6.3 Storage Arrangement of Two dimensional Array......Page 130
6.4 Characteristics of Array......Page 131
6.5 Array Constants......Page 133
6.7 Initialization with DATA Statement......Page 134
6.8 Repeat Factor and Initialization......Page 135
6.9 DATA Statement and Implied DO Loop......Page 136
6.11 Character Variable and Array Constructors......Page 137
6.13 Array Assignment and Array Arithmetic......Page 138
6.14 Array Section......Page 140
6.16 Array Output......Page 143
6.17 Programming Examples......Page 144
6.18 Array Bounds......Page 148
6.20 UBOUND......Page 149
6.21 RESHAPE......Page 150
6.22 Vector Subscripts......Page 153
6.23 WHERE Statement......Page 155
6.24 DO CONCURRENT......Page 158
6.25 FORALL Statement......Page 161
6.26 Rules for FORALL......Page 162
6.27 EQUIVALENCE Statement......Page 163
6.28 EQUIVALENCE and Character Variables......Page 165
6.29 Programming Examples......Page 167
6.31 Maximum, Minimum and Finding Location......Page 170
6.32 SUM and PRODUCT......Page 175
6.33 Handling of Arrays of More than Two Dimensions......Page 176
6.35 Matrix Multiplication......Page 178
6.36 TRANSPOSE of a Matrix......Page 179
6.37 Array Shift......Page 180
6.38 Euclidian Norm......Page 184
6.40 Locating and Counting Array Elements......Page 185
6.41 Packing and Unpacking......Page 187
6.42 MERGE......Page 190
6.43 REDUCE......Page 191
7.1 Derived Type......Page 192
7.2 Assignment......Page 193
7.4 Named Constant and Derived Type......Page 194
7.7 Input and Output......Page 195
7.8 Substrings......Page 196
7.9 Array and Derived Types......Page 197
7.10 Nested Derived Types......Page 198
7.11 Arrays as Elementary Items......Page 199
7.13 Derived Types and EQUIVALENCE Statement......Page 200
7.14 Parameterized Derived Types......Page 201
8.1 Edit Descriptors......Page 204
8.2 Input/Output Lists......Page 205
8.3 General Form of Format Statement......Page 206
8.6 Descriptor for Integer......Page 207
8.7 Descriptors for Real Number......Page 209
8.8 Insufficient Width......Page 212
8.9 Format and List Elements......Page 213
8.11 Descriptors for BOZ Numbers......Page 214
8.13 Descriptor for Character......Page 215
8.14 General Edit Descriptor......Page 216
8.16 Scale Factor......Page 218
8.17 Leading Signs......Page 219
8.18 Tab Descriptors......Page 220
8.20 Slash Descriptor......Page 221
8.21 Embedded Blanks......Page 222
8.22 Apostrophe and Quote Descriptors......Page 223
8.25 Rounding Modes......Page 224
8.26 Variable Format......Page 225
8.28 NAMELIST......Page 226
8.30 Rules for NAMELIST......Page 230
8.31 Processor Dependency......Page 231
9.3 Formatted Record......Page 232
9.9 Unit Number......Page 233
9.12 Optional Specifiers......Page 234
9.16 BACKSPACE Statement......Page 244
9.18 READ/WRITE Statement......Page 245
9.19 Asynchronous Input/Output......Page 248
9.21 Rules for Input/Output Control List......Page 250
9.24 Examples of File Operations......Page 251
9.26 Storage Unit of Stream Input/Output......Page 253
9.29 Unformatted Stream File......Page 254
9.30 Formatted Stream I/O......Page 255
9.31 Rule of Thumb......Page 256
9.33 Processor Dependencies......Page 257
10.2 BASE......Page 258
10.5 RANGE for Integers......Page 259
10.8 MAXEXPONENT and MINEXPONENT......Page 260
10.11 RANGE for Real Numbers......Page 261
10.15 EPSILON......Page 262
10.18 RRSPACING......Page 263
10.19 Programming Example......Page 264
11.4 Elemental Procedures......Page 266
11.8 Argument Keywords......Page 267
11.11 Types of Available Intrinsics......Page 268
11.14 Final Word......Page 269
12: Subprograms......Page 270
12.1 FUNCTION Subprogram......Page 271
12.2 SUBROUTINE Subprogram......Page 274
12.3 CALL Statement......Page 275
12.4 INTENT......Page 277
12.5 Internal Procedure......Page 278
12.6 Character Type Argument......Page 281
12.9 Call by Value......Page 284
12.10 RETURN Statement......Page 285
12.11 INTERFACE Block......Page 286
12.12 Array as Arguments......Page 287
12.13 User Defined Type as Argument......Page 289
12.14 MODULE......Page 290
12.15 MODULE PROCEDURE......Page 292
12.16 PUBLIC and PRIVATE Attributes......Page 294
12.17 PROTECTED Attribute......Page 299
12.18 Scope Rules......Page 301
12.19 Generic Subprograms......Page 303
12.20 ABSTRACT Interface......Page 305
12.21 Keyword Arguments......Page 307
12.22 Operator Overloading......Page 308
12.23 Overloading of Assignment Operator......Page 312
12.24 Overloading of Standard Library Functions......Page 313
12.25 User Defined Operators......Page 314
12.26 Use Statement and Renaming Operators......Page 316
12.28 Precedence of User Defined Operators......Page 317
12.29 OPTIONAL Arguments......Page 318
12.30 PRESENT Intrinsic......Page 319
12.31 Assumed Rank of Dummy Arguments......Page 320
12.33 SAVE Variables......Page 321
12.34 COMMON Statement......Page 323
12.35 BLOCK DATA......Page 324
12.38 COMMON and EQUIVALENCE......Page 326
12.39 EXTERNAL Statement......Page 327
12.41 RECURSIVE FUNCTION......Page 330
12.42 RECURSIVE SUBROUTINE......Page 332
12.44 Rules for PURE Procedure......Page 334
12.45 ELEMENTAL Procedure......Page 335
12.46 IMPURE ELEMENTAL Procedure......Page 336
12.47 SUBMODULE......Page 337
12.49 Function Calls and Side Effects......Page 340
12.51 Recursive Input/Output......Page 341
12.52 Programming Examples......Page 342
13.1 Assignment......Page 348
13.3 Comparison......Page 350
13.6 PUT_LINE......Page 351
13.7 GET......Page 352
13.10 REPLACE......Page 353
13.11 SPLIT......Page 354
14.2 Single Precision 32-Bit Floating Point Numbers (IEEE Standard)......Page 356
14.4 Representation of Zero......Page 359
14.5 Representation of Infinity......Page 360
14.7 Summary of IEEE “Numbers”......Page 361
14.13 IEEE Modules......Page 363
14.15 IEEE FLAGS......Page 364
14.17 IEEE Operators......Page 365
14.18 Inquiry Functions (Arithmetic Module)......Page 366
14.19 IEEE_CLASS......Page 367
14.21 IEEE_VALUE......Page 368
14.26 IEEE_INT......Page 369
14.31 IEEE_FMA......Page 370
14.33 IEEE_NEXT_AFTER, IEEE_NEXT_DOWN and IEEE_NEXT_UP......Page 371
14.36 IEEE_GET_ROUNDING_MODE......Page 372
14.38 IEEE_RINT......Page 373
14.41 IEEE_SET_HALTING_MODE......Page 374
14.43 IEEE_GET_STATUS and IEEE_SET_STATUS......Page 375
14.45 IEEE_GET_UNDERFLOW_MODE......Page 376
14.47 IEEE_SELECTED_REAL_KIND......Page 377
14.51 NaN, Infinity and Format......Page 378
14.52 Relational Operators, Infinity and NaN......Page 379
14.53 Exception within a Procedure......Page 380
14.54 Exception Outside a Procedure......Page 381
14.55 Programming Examples......Page 382
14.57 Processor Dependencies......Page 384
15.1 ALLOCATABLE Arrays......Page 386
15.2 DEALLOCATE Statement......Page 389
15.4 Derived Type and ALLOCATE......Page 390
15.5 Allocated Array and Subprogram......Page 391
15.6 ALLOCATE and Dummy Parameter......Page 394
15.7 Allocatable Character Length......Page 395
15.9 Allocatable Scalar......Page 396
15.10 Allocatable Function......Page 397
15.11 Allocation Transfer......Page 398
15.13 Programming Example......Page 399
16.2 TARGET......Page 402
16.5 POINTER Assignment......Page 403
16.7 POINTER and Array......Page 405
16.8 POINTER as Alias......Page 406
16.9 ALLOCATE and POINTER......Page 407
16.10 POINTER and ALLOCATABLE Array......Page 408
16.11 DEALLOCATE......Page 410
16.14 Dangling Pointer......Page 411
16.16 POINTER and Derived Type......Page 412
16.18 FUNCTION and POINTER......Page 413
16.19 POINTER and Subprogram......Page 414
16.21 PROCEDURE and POINTER......Page 415
16.22 ALLOCATE with SOURCE......Page 418
16.24 CONTIGUOUS......Page 419
16.26 Programming Example......Page 420
17.2 BTEST......Page 426
17.3 IBSET......Page 428
17.4 IBCLR......Page 429
17.5 IBITS......Page 430
17.6 LEADZ and TRAILZ......Page 432
17.9 MASKL......Page 433
17.11 IAND......Page 434
17.12 IOR......Page 436
17.13 IEOR......Page 437
17.15 Bit Sequence Comparison......Page 439
17.16 Programming Example......Page 440
17.17 ISHFT......Page 441
17.21 MERGE_BITS......Page 442
17.22 ISHFTC......Page 443
17.25 Logical Operations with Array Elements......Page 445
17.26 MVBITS......Page 447
17.27 TRANSFER......Page 449
18.1 Interoperability of Intrinsic Types......Page 452
18.5 Procedures in the Module ISO_C_BINDING......Page 454
18.8 Fortran and C Interoperability—Examples......Page 456
18.9 Interoperation with Global Variables......Page 465
18.10 C–Fortran Interoperation......Page 468
18.11 ENUMERATOR......Page 469
19.1 Object and Its Properties......Page 472
19.2 Inheritance......Page 473
19.3 ASSOCIATE......Page 474
19.4 Rules of ASSOCIATE......Page 476
19.5 Polymorphic Variables......Page 477
19.6 SELECT TYPE Construct......Page 479
19.7 Allocation and Polymorphic Variables......Page 485
19.8 Type Bound Procedure......Page 486
19.9 Generic Binding......Page 491
19.10 Overriding Type Bound Procedures......Page 493
19.11 Deferred Binding......Page 495
19.12 Finalization......Page 496
19.13 SAME_TYPE_AS......Page 499
19.14 EXTENDS_TYPE_OF......Page 500
19.15 Derived Type Input and Output......Page 501
20.1 Parallel Computing......Page 510
20.3 Compilation of Fortran Program with Coarray......Page 511
20.4 Declaration......Page 512
20.7 THIS_IMAGE......Page 513
20.9 SYNC ALL......Page 515
20.11 Multidimensional Coarray......Page 516
20.12 Upper Bound of the Last CODIMENSION......Page 517
20.14 LCOBOUND......Page 518
20.16 COSHAPE......Page 519
20.18 IMAGE_INDEX......Page 520
20.19 Synchronization......Page 521
20.20 CRITICAL Section......Page 523
20.22 CO Routines......Page 525
20.23 CO_MAX......Page 526
20.25 CO_SUM......Page 527
20.26 CO_REDUCE......Page 528
20.27 CO_BROADCAST......Page 529
20.28 Coarray and Subprogram......Page 530
20.29 Coarray and Function......Page 533
20.31 User Defined Type and Coarray......Page 534
20.32 COARRAY and POINTER......Page 538
20.33 Operator Overloading and Coarray......Page 539
20.34 Atomic Variables and Subroutines......Page 540
20.38 ATOMIC_FETCH_ADD......Page 541
20.42 ATOMIC_FETCH_OR......Page 542
20.45 ATOMIC_CAS......Page 543
20.46 LOCK and UNLOCK......Page 544
20.51 VOLATILE Variable......Page 545
20.53 EVENT POST......Page 546
20.54 EVENT WAIT......Page 547
20.56 Programming Examples Using Coarray......Page 548
21.2 Structured Block......Page 552
21.6 Compiler Support......Page 553
21.8 Structure of Compiler Directives......Page 554
21.10 Parallelization Directives......Page 555
21.11 Clauses Associated with the Directives......Page 556
21.12 Parallel Directive......Page 557
21.14 Three Runtime Routines......Page 558
21.15 Nested Parallel......Page 559
21.17 IF Clause......Page 560
21.19 PRIVATE......Page 561
21.23 DEFAULT SHARED......Page 562
21.25 Rules for OMP PARALLEL Directive......Page 563
21.27 OMP DO/OMP END DO......Page 565
21.29 OMP SECTIONS/OMP END SECTIONS......Page 566
21.30 OMP WORKSHARE......Page 568
21.31 OMP SINGLE/OMP END SINGLE......Page 570
21.32 OMP MASTER/OMP END MASTER......Page 571
21.33 REDUCTION......Page 572
21.34 CRITICAL/END CRITICAL......Page 575
21.35 LASTPRIVATE......Page 576
21.36 ATOMIC......Page 578
21.37 OMP BARRIER......Page 579
21.38 THREADPRIVATE......Page 580
21.40 COPYIN......Page 582
21.42 COPYPRIVATE......Page 584
21.43 NOWAIT......Page 585
21.45 Openmp LOCK......Page 586
21.46 SCHEDULE......Page 589
21.47 STATIC SCHEDULE......Page 590
21.48 DYNAMIC SCHEDULE......Page 591
21.49 GUIDED SCHEDULE......Page 592
21.52 Openmp Runtime Library Routines......Page 593
21.53 Runtime Time Routines......Page 595
21.55 Environment Variables......Page 596
21.56 Programming Examples......Page 597
21.57 Final Word......Page 599
22.2 Compilation......Page 600
22.4 MPI Version......Page 601
22.7 MPI_FINALIZE......Page 602
22.10 Structure of a MPI Program......Page 603
22.12 MPI_COMM_SIZE......Page 604
22.14 MPI_BARRIER......Page 605
22.17 Communication Modes......Page 606
22.19 MPI_SEND and MPI_RECV......Page 607
22.21 MPI_BSEND......Page 610
22.23 Deadlock......Page 611
22.24 Non-blocking Send and Receive......Page 612
22.26 MPI_ANY_TAG and MPI_ANY_SOURCE......Page 614
22.27 REDUCTION......Page 615
22.28 MPI_SCAN......Page 621
22.29 MPI_ALLREDUCE......Page 622
22.30 MPI_REDUCE_SCATTER_BLOCK......Page 624
22.31 MPI_REDUCE_SCATTER......Page 625
22.32 MPI_BROADCAST......Page 626
22.33 MPI_GATHER......Page 627
22.34 MPI_ALLGATHER......Page 628
22.35 MPI_SCATTER......Page 629
22.36 MPI_SCATTERV......Page 630
22.37 MPI_ALLTOALL......Page 632
22.39 MPI_TYPE_CONTIGUOUS......Page 633
22.40 MPI_TYPE_VECTOR......Page 635
22.41 MPI_TYPE_CREATE_HVECTOR......Page 636
22.42 MPI_TYPE_INDEXED......Page 637
22.44 MPI_TYPE_CREATE_INDEXED_BLOCK......Page 638
22.46 MPI_TYPE_CREATE_STRUCT......Page 639
22.47 MPI_PACK and MPI_UNPACK......Page 641
22.48 MPI_COMM_SPLIT......Page 642
22.50 Programming Examples......Page 644
22.51 Final Word......Page 649
Appendix A......Page 650
Appendix B......Page 652
Appendix C......Page 654
Appendix D......Page 662
Appendix E......Page 664
Appendix F......Page 666
Appendix G......Page 668
Appendix H......Page 670
Appendix I......Page 672
References......Page 674
Index......Page 676