Hello World in Co-array Fortran

Our first program will print the classic “hello world” message. Here’s the full source code.

program hello_world
    print *, "hello world"
end program hello_world

To run the program, compile the code into an executable file using gfortran, and then execute it.

$ gfortran hello_world.f90 -o hello_world
$ ./hello_world
 hello world

Sometimes we’ll want to build our programs into binaries that can be executed directly. In Fortran, we usually compile the source file directly into an executable.

First, compile the code:

$ gfortran hello_world.f90 -o hello_world
$ ls
hello_world       hello_world.f90

We can then execute the built binary directly:

$ ./hello_world
 hello world

Now that we can run and build basic Fortran programs, let’s learn more about the language.