The hello_image.f90 sample is a hello world program. 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
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.
The -coarray option cannot be used in conjunction with -openmp options. One cannot mix Coarray Fortran language extensions with OpenMP extensions.
Copyright © 2011, Intel Corporation. All rights reserved.