The hello_image.f90 sample is a hello world application. Unlike the usual hello world, this coarray Fortran program will spawn multiple images, or processes, that will run concurrently on the host computer. Examining the source code for this application shows a simple Fortran program:
program hello_image
write(*,*) "Hello from image ", this_image(), &
"out of ", num_images()," total images"
end program hello_image
Note the function calls to this_image() and num_images(). These are new Fortran 2008 intrinsic functions. The num_images() function returns the total number of images or processes spawned for this program. The this_image() function returns a unique identifier for each image in the range 1 to N, where N is the total number of images created for this program.
To compile the sample program containing the Coarray Fortran features, use the coarray compiler option.
ifort -coarray hello_image.f90 -o hello_image
If you run the hello_image executable, the output will vary depending on the number of processor cores on your system:
./hello_image
Your output should be similar to this:
Hello from image 1 out of 8 total images Hello from image 6 out of 8 total images Hello from image 7 out of 8 total images Hello from image 2 out of 8 total images Hello from image 5 out of 8 total images Hello from image 8 out of 8 total images Hello from image 3 out of 8 total images Hello from image 4 out of 8 total images
By default, when a Coarray Fortran application is compiled with the Intel Fortran Compiler, the invocation creates as many images as there are processor cores on the host platform. The example shown above was run on a dual quad-core host system with eight total cores. As shown, each image is a separately spawned process on the system and executes asynchronously.
Do not use the -coarray option with the -openmp option. You cannot mix Coarray Fortran and OpenMP language extensions.