|
| 1 | +program hello_world |
| 2 | + use iso_c_binding, only: c_bool |
| 3 | + use iso_fortran_env, only: output_unit,error_unit |
| 4 | + use prif, only : & |
| 5 | + prif_init & |
| 6 | + ,prif_this_image_no_coarray & |
| 7 | + ,prif_num_images & |
| 8 | + ,prif_stop & |
| 9 | + ,prif_error_stop & |
| 10 | + ,prif_sync_all |
| 11 | + implicit none |
| 12 | + |
| 13 | + integer :: init_exit_code, me, num_imgs, exitcase = 1 |
| 14 | + logical(kind=c_bool), parameter :: false = .false._c_bool, true = .true._c_bool |
| 15 | + character(len=256) :: arg_string |
| 16 | + |
| 17 | + call prif_init(init_exit_code) |
| 18 | + if (init_exit_code /= 0) call prif_error_stop(quiet=false, stop_code_char="program startup failed") |
| 19 | + |
| 20 | + call prif_this_image_no_coarray(this_image=me) |
| 21 | + call prif_num_images(num_images=num_imgs) |
| 22 | + if (command_argument_count() > 0) then |
| 23 | + call get_command_argument(1, arg_string) |
| 24 | + read(arg_string, *) exitcase |
| 25 | + end if |
| 26 | + if (me == 1) write(output_unit,*) "testing exit case ", exitcase |
| 27 | + |
| 28 | + call prif_sync_all() |
| 29 | + |
| 30 | + write(output_unit,'(A,I1,A,I1)') "stdout from image ", me, " of ", num_imgs |
| 31 | + write(error_unit,'(A,I1,A,I1)') "stderr from image ", me, " of ", num_imgs |
| 32 | + |
| 33 | + call prif_sync_all() |
| 34 | + |
| 35 | + select case (exitcase) |
| 36 | + case (1) |
| 37 | + call prif_stop(quiet=true, stop_code_int=exitcase+100) |
| 38 | + case (2) |
| 39 | + call prif_stop(quiet=false, stop_code_int=exitcase+100) |
| 40 | + case (3) |
| 41 | + if (me == num_imgs) call prif_error_stop(quiet=true, stop_code_int=exitcase+100) |
| 42 | + case default |
| 43 | + if (me == num_imgs) call prif_error_stop(quiet=false, stop_code_int=exitcase+100) |
| 44 | + end select |
| 45 | + |
| 46 | + call prif_sync_all() |
| 47 | + |
| 48 | +end program |
0 commit comments