|
| 1 | +program out_of_memory |
| 2 | + use iso_c_binding, only: c_bool, c_size_t, c_ptr, c_null_funptr, c_int64_t |
| 3 | + use prif |
| 4 | + implicit none |
| 5 | + |
| 6 | + integer :: init_exit_code, me, i |
| 7 | + integer(c_size_t) :: size_in_bytes = ishft(500_c_size_t, 40) |
| 8 | + type(c_ptr) :: allocated_memory |
| 9 | + logical :: coarray = .false. |
| 10 | + character(len=256) :: arg |
| 11 | + |
| 12 | + call prif_init(init_exit_code) |
| 13 | + if (init_exit_code /= 0 .and. init_exit_code /= PRIF_STAT_ALREADY_INIT) then |
| 14 | + call prif_error_stop(quiet=.false._c_bool, stop_code_char="program startup failed") |
| 15 | + end if |
| 16 | + call prif_this_image_no_coarray(this_image=me) |
| 17 | + |
| 18 | + do i = 1, command_argument_count() |
| 19 | + call get_command_argument(i, arg) |
| 20 | + |
| 21 | + if (trim(arg) == "--coarray" .or. trim(arg) == "-c") then |
| 22 | + coarray = .true. |
| 23 | + else |
| 24 | + read(arg, *) size_in_bytes |
| 25 | + end if |
| 26 | + end do |
| 27 | + |
| 28 | + if (coarray) then |
| 29 | + if (me == 1) print *, "prif_allocate_coarray: ", size_in_bytes, " bytes" |
| 30 | + block |
| 31 | + integer(c_int64_t), dimension(1) :: lcobounds, ucobounds |
| 32 | + integer :: num_imgs |
| 33 | + type(prif_coarray_handle) :: coarray_handle |
| 34 | + |
| 35 | + call prif_num_images(num_images=num_imgs) |
| 36 | + lcobounds(1) = 1 |
| 37 | + ucobounds(1) = num_imgs |
| 38 | + |
| 39 | + call prif_allocate_coarray( & |
| 40 | + lcobounds, ucobounds, size_in_bytes, c_null_funptr, & |
| 41 | + coarray_handle, allocated_memory) |
| 42 | + end block |
| 43 | + else |
| 44 | + if (me == 1) print *, "prif_allocate: ", size_in_bytes, " bytes" |
| 45 | + call prif_sync_all() |
| 46 | + call prif_allocate(size_in_bytes, allocated_memory) |
| 47 | + end if |
| 48 | + |
| 49 | + |
| 50 | + call prif_sync_all() |
| 51 | + call prif_error_stop(quiet=.false._c_bool, stop_code_char="test failed") |
| 52 | + |
| 53 | +end program |
0 commit comments