Skip to content

Commit 43699ed

Browse files
authored
Merge pull request #229 from bonachea/image_index
Implement image_index_with_team and this_image_with_{coarray,dim}, partial {image_index,num_images}_with_team_number
2 parents 89c94b9 + 255761f commit 43699ed

File tree

6 files changed

+298
-38
lines changed

6 files changed

+298
-38
lines changed

docs/implementation-status.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ are accepted, but in some cases, the associated runtime behavior is not fully im
5454
|-----------|--------|-------|
5555
| `prif_num_images` | **YES** | |
5656
| `prif_num_images_with_team` | **YES** | |
57-
| `prif_num_images_with_team_number` | no | |
57+
| `prif_num_images_with_team_number` | *partial* | no support for sibling teams |
5858
| `prif_this_image_no_coarray` | **YES** | |
59-
| `prif_this_image_with_coarray`, `prif_this_image_with_dim` | no | |
59+
| `prif_this_image_with_coarray`, `prif_this_image_with_dim` | **YES** | |
6060
| `prif_failed_images` | **YES** | |
6161
| `prif_stopped_images` | **YES** | |
6262
| `prif_image_status` | **YES** | |
@@ -87,8 +87,8 @@ are accepted, but in some cases, the associated runtime behavior is not fully im
8787
| `prif_coshape` | **YES** | |
8888
| `prif_local_data_pointer` | **YES** | |
8989
| `prif_image_index` | **YES** | |
90-
| `prif_image_index_with_team` | no | |
91-
| `prif_image_index_with_team_number` | no | |
90+
| `prif_image_index_with_team` | **YES** | |
91+
| `prif_image_index_with_team_number` | *partial* | no support for sibling teams |
9292

9393
---
9494

src/caffeine/coarray_queries_s.F90

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,51 +45,61 @@
4545
end associate
4646
end procedure
4747

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
5454

55-
invalid_cosubscripts = .false.
55+
integer :: dim
56+
integer(c_int) :: prior_size
5657

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))
6359

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)
6667
prior_size = 1
6768
! Future work: values of prior_size are invariant across calls w/ the same coarray_handle
6869
! We could store them in the coarray metadata at allocation rather than redundantly
6970
! computing them here, which would accelerate calls with corank > 1 by removing
7071
! corank multiply/add operations and the loop-carried dependence
7172
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
7479
end do
75-
end if
80+
end associate
7681

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
7983
image_index = 0
8084
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)
8189
end procedure
8290

8391
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)
8793
end procedure
8894

8995
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
93103
end procedure
94104

95105
module procedure prif_local_data_pointer

src/caffeine/image_queries_s.F90

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
end procedure
2020

2121
module procedure prif_num_images_with_team_number
22-
call unimplemented("prif_num_images_with_team_number")
22+
if (team_number == -1) then
23+
num_images = initial_team%num_images
24+
else if (team_number == current_team%info%team_number) then
25+
num_images = current_team%info%num_images
26+
else
27+
call unimplemented("prif_num_images_with_team_number: no support for sibling teams")
28+
end if
2329
end procedure
2430

2531
module procedure prif_this_image_no_coarray
@@ -31,15 +37,56 @@
3137
end procedure
3238

3339
module procedure prif_this_image_with_coarray
40+
integer(c_int) :: offset, doff, dsz
41+
integer :: dim
42+
3443
call_assert(coarray_handle_check(coarray_handle))
3544

36-
call unimplemented("prif_this_image_with_coarray")
45+
if (present(team)) then
46+
offset = team%info%this_image - 1
47+
else
48+
offset = current_team%info%this_image - 1
49+
endif
50+
51+
associate (info => coarray_handle%info)
52+
call_assert(size(cosubscripts) == info%corank)
53+
do dim = 1, info%corank-1
54+
dsz = INT(info%ucobounds(dim) - info%lcobounds(dim) + 1, c_int)
55+
doff = mod(offset, dsz)
56+
cosubscripts(dim) = doff + info%lcobounds(dim)
57+
call_assert(cosubscripts(dim) <= info%ucobounds(dim))
58+
offset = offset / dsz
59+
end do
60+
cosubscripts(info%corank) = offset + info%lcobounds(info%corank)
61+
call_assert(cosubscripts(info%corank) <= info%ucobounds(info%corank))
62+
end associate
63+
64+
# if ASSERTIONS
65+
block ! sanity check
66+
integer(c_int) :: image_index
67+
if (present(team)) then
68+
call prif_image_index_with_team(coarray_handle, cosubscripts, team, image_index)
69+
call_assert(image_index == team%info%this_image)
70+
else
71+
call prif_image_index(coarray_handle, cosubscripts, image_index)
72+
call_assert(image_index == current_team%info%this_image)
73+
end if
74+
end block
75+
# endif
3776
end procedure
3877

3978
module procedure prif_this_image_with_dim
4079
call_assert(coarray_handle_check(coarray_handle))
4180

42-
call unimplemented("prif_this_image_with_dim")
81+
block
82+
integer(c_int64_t) :: cosubscripts(coarray_handle%info%corank)
83+
84+
call_assert(dim >= 1 .and. dim <= coarray_handle%info%corank)
85+
86+
call prif_this_image_with_coarray(coarray_handle, team, cosubscripts)
87+
88+
cosubscript = cosubscripts(dim)
89+
end block
4390
end procedure
4491

4592
module procedure prif_failed_images

src/prif.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ module subroutine prif_image_index_with_team_number(coarray_handle, sub, team_nu
499499
implicit none
500500
type(prif_coarray_handle), intent(in) :: coarray_handle
501501
integer(c_int64_t), intent(in) :: sub(:)
502-
integer(c_int), intent(in) :: team_number
502+
integer(c_int64_t), intent(in) :: team_number
503503
integer(c_int), intent(out) :: image_index
504504
end subroutine
505505

0 commit comments

Comments
 (0)