I'm trying to run a Fortran code that follows the example for the book:
Curcic, M. 2020. Modern Fortran: Building Efficient Parallel Applications.
Although I get the following error when I run it and I'm not experienced enough to understand what the problem is, could someone kindly help me?
program hello
implicit none
integer :: a[*] ! error here
integer :: i
a = this_image()
if (this_image() == 1) then
do i = 1, num_images()
print *, 'Value on image', i, 'is', a[i]
end do
end if
end program
Error: Coarrays disabled at (1), use '-fcoarray=' to enable|
Your program use a special feature of standard Fortran called coarrays. They are used for modern parallel computing. However most traditional parallel programs used in computational physics and meteorology use MPI for distributed parallelism instead.
There is nothing wrong in learning coarrays at any stage, but it might not be the skill you are supposed to learn now. It is currently not the most useful skill for data analysis in meteorology.
With coarrays, different copies ("images") of the program are running concurrently on different CPU cores of a computer or even of several computing nodes in a cluster.
integer :: a[*]
means that the variable a
exists on each image and the images can look at the value in different images and read it or change it.
a[i]
means that you want to use the value of a
at image number i
.
To use Coarrays with Gfortran you either can compile the program as a (pretty-useless) single image program using -fcoarray=single
or you have to install a dedicated library called OpenCoarrays and then compile with -fcoarray=lib
pointing to the library.