Why is this a function declared inside the module and then used somewhere else in the same module not seen by the linker?

In the following, I’ll explain using the complete example below (which you can compile and link to try things): module mymodule contains integer function foo () foo = 1 end function integer function bar () integer :: foo bar = foo() end function end module program test use mymodule print *, bar() end In the … Read more

Function has no implicit type

Move the line end program to the end of your source file and, in its place, write the line contains As you have written your program it has no knowledge of the function test, which is what the compiler is telling you. I have suggested one of the ways in which you can provide the … Read more

Automatic array allocation upon assignment in Fortran

The validity of code like integer, allocatable :: array(:) array = (/1,2,3/) end depends on the standard of Fortran used to interpret it. Fortran 2003 introduced the concept of automatic allocation on intrinsic assignment. Before Fortran 2003 the array on the left-hand side of such an assignment statement must be allocated, and of the same … Read more

How to use command line arguments in Fortran?

If you want to get the arguments fed to your program on the command line, use the (since Fortran 2003) standard intrinsic subroutine GET_COMMAND_ARGUMENT. Something like this might work PROGRAM MAIN REAL(8) :: A,B integer :: num_args, ix character(len=12), dimension(:), allocatable :: args num_args = command_argument_count() allocate(args(num_args)) ! I’ve omitted checking the return status of … Read more

Where to put `implicit none` in Fortran

The implicit statement (including implicit none) applies to a scoping unit. Such a thing is defined as BLOCK construct, derived-type definition, interface body, program unit, or subprogram, excluding all nested scoping units in it This “excluding all nested scoping units in it” suggests that it may be necessary/desirable to have implicit none in each function … Read more

Fortran – explicit interface

“explicit interface” means that the interface to the procedure (subroutine or function) is declared to the compiler. This allows the compiler to check consistency of arguments between calls to the procedure and the actual procedure. This can find a lot of programmer mistakes. You can do this writing out the interface with an interface statement … Read more

Does Fortran have undefined behavior?

Yes, it has. It is just called differently. There are many things that you could do and will make your code not standard conforming, for which there is no requirement to for the processor (compiler) to diagnose such non-conformance (of course, many deviations must be diagnosed). Often the situations will be similar to C undefined-behaviour … Read more

How does BLAS get such extreme performance?

A good starting point is the great book The Science of Programming Matrix Computations by Robert A. van de Geijn and Enrique S. Quintana-Ortí. They provide a free download version. BLAS is divided into three levels: Level 1 defines a set of linear algebra functions that operate on vectors only. These functions benefit from vectorization … Read more