%num_images: 1 %fcflags: -ffree-line-length-none program get_mpirun_version implicit none character(len=90000) :: str_buff call execute_command_line ("caf --version; caf --wraps; /usr/bin/gfortran --version; & &mpirun --version", wait=.true., cmdmsg=str_buff) print*, trim(str_buff) end program !! The following lines are Coarray Fortran jupyter notebook "magics". !! They are stripped before sending the code to the compiler ! Control how many coarray images we spawn: %num_images: 5 ! Pass command line arguments to our program: %args: IamOne IamTwo IamThree "I am Four" ! Use the following extra compilation flags: %fcflags: -fbacktrace -std=f2008 -W -Wall -Wextra -pedantic !! Begin the main program program main implicit none integer :: istat, num_arg character(len=32), allocatable :: arg(:) associate(me => this_image()) ! Use an associate construct to avoid repitition ! A simple "Hellow (Coarray) world" write(*,'(2(A,I0),A)') "Hello from image ", me, " of ", num_images(), "!" ! Have each image process one command line argument num_arg = command_argument_count() allocate(arg(num_arg)) if (me <= num_arg) then call get_command_argument (me, value=arg(me), status=istat) select case(istat) case(0) write(*,'(A,I0,A)') "Argument number ", me, " was: "//trim(arg(me)) case default write(*,'(A,I0,A)') "Image ", me, " encountered an unknown problem retrieving it's command line argument." end select end if end associate end program