|
45 | 45 | end associate |
46 | 46 | end procedure |
47 | 47 |
|
48 | | - module procedure prif_image_index |
49 | | - integer :: dim, i |
50 | | - integer(c_int) :: prior_size, num_img |
51 | | - logical :: invalid_cosubscripts |
52 | | - |
53 | | - call_assert(coarray_handle_check(coarray_handle)) |
| 48 | + subroutine image_index_helper(coarray_handle, sub, num_images, image_index) |
| 49 | + implicit none |
| 50 | + type(prif_coarray_handle), intent(in) :: coarray_handle |
| 51 | + integer(c_int64_t), intent(in) :: sub(:) |
| 52 | + integer(c_int), intent(in) :: num_images |
| 53 | + integer(c_int), intent(out) :: image_index |
54 | 54 |
|
55 | | - invalid_cosubscripts = .false. |
| 55 | + integer :: dim |
| 56 | + integer(c_int) :: prior_size |
56 | 57 |
|
57 | | - check_subscripts: do i = 1, size(sub) |
58 | | - if (sub(i) .lt. coarray_handle%info%lcobounds(i) .or. sub(i) .gt. coarray_handle%info%ucobounds(i)) then |
59 | | - invalid_cosubscripts = .true. |
60 | | - exit check_subscripts |
61 | | - end if |
62 | | - end do check_subscripts |
| 58 | + call_assert(coarray_handle_check(coarray_handle)) |
63 | 59 |
|
64 | | - if (.not. invalid_cosubscripts) then |
65 | | - image_index = 1 + INT(sub(1) - coarray_handle%info%lcobounds(1), c_int) |
| 60 | + associate (info => coarray_handle%info) |
| 61 | + call_assert(size(sub) == info%corank) |
| 62 | + if (sub(1) .lt. info%lcobounds(1) .or. sub(1) .gt. info%ucobounds(1)) then |
| 63 | + image_index = 0 |
| 64 | + return |
| 65 | + end if |
| 66 | + image_index = 1 + INT(sub(1) - info%lcobounds(1), c_int) |
66 | 67 | prior_size = 1 |
67 | 68 | ! Future work: values of prior_size are invariant across calls w/ the same coarray_handle |
68 | 69 | ! We could store them in the coarray metadata at allocation rather than redundantly |
69 | 70 | ! computing them here, which would accelerate calls with corank > 1 by removing |
70 | 71 | ! corank multiply/add operations and the loop-carried dependence |
71 | 72 | do dim = 2, size(sub) |
72 | | - prior_size = prior_size * INT(coarray_handle%info%ucobounds(dim-1) - coarray_handle%info%lcobounds(dim-1) + 1, c_int) |
73 | | - image_index = image_index + INT(sub(dim) - coarray_handle%info%lcobounds(dim), c_int) * prior_size |
| 73 | + prior_size = prior_size * INT(info%ucobounds(dim-1) - info%lcobounds(dim-1) + 1, c_int) |
| 74 | + if (sub(dim) .lt. info%lcobounds(dim) .or. sub(dim) .gt. info%ucobounds(dim)) then |
| 75 | + image_index = 0 |
| 76 | + return |
| 77 | + end if |
| 78 | + image_index = image_index + INT(sub(dim) - info%lcobounds(dim), c_int) * prior_size |
74 | 79 | end do |
75 | | - end if |
| 80 | + end associate |
76 | 81 |
|
77 | | - call prif_num_images(num_images=num_img) |
78 | | - if (invalid_cosubscripts .or. image_index .gt. num_img) then |
| 82 | + if (image_index .gt. num_images) then |
79 | 83 | image_index = 0 |
80 | 84 | end if |
| 85 | + end subroutine |
| 86 | + |
| 87 | + module procedure prif_image_index |
| 88 | + call image_index_helper(coarray_handle, sub, current_team%info%num_images, image_index) |
81 | 89 | end procedure |
82 | 90 |
|
83 | 91 | module procedure prif_image_index_with_team |
84 | | - call_assert(coarray_handle_check(coarray_handle)) |
85 | | - |
86 | | - call unimplemented("prif_image_index_with_team") |
| 92 | + call image_index_helper(coarray_handle, sub, team%info%num_images, image_index) |
87 | 93 | end procedure |
88 | 94 |
|
89 | 95 | module procedure prif_image_index_with_team_number |
90 | | - call_assert(coarray_handle_check(coarray_handle)) |
91 | | - |
92 | | - call unimplemented("prif_image_index_with_team_number") |
| 96 | + if (team_number == -1) then |
| 97 | + call image_index_helper(coarray_handle, sub, initial_team%num_images, image_index) |
| 98 | + else if (team_number == current_team%info%team_number) then |
| 99 | + call image_index_helper(coarray_handle, sub, current_team%info%num_images, image_index) |
| 100 | + else |
| 101 | + call unimplemented("prif_image_index_with_team_number: no support for sibling teams") |
| 102 | + end if |
93 | 103 | end procedure |
94 | 104 |
|
95 | 105 | module procedure prif_local_data_pointer |
|
0 commit comments