Skip to content

Commit 575a36c

Browse files
authored
Merge pull request #320 from bonachea/bind-c-handle
Overhaul coarray finalization, convert `prif_coarray_handle` to be interoperable
2 parents a608259 + 91c198d commit 575a36c

27 files changed

Lines changed: 567 additions & 324 deletions

‎.github/workflows/build.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ jobs:
144144
label: PRIF-0.6
145145
FFLAGS: -DFORCE_PRIF_0_6
146146
container: phhargrove/llvm-flang:21.1.0-latest
147+
- os: ubuntu-24.04
148+
compiler: flang
149+
version: 21
150+
network: smp
151+
label: PRIF-0.7
152+
FFLAGS: -DFORCE_PRIF_0_7
153+
container: phhargrove/llvm-flang:21.1.0-latest
147154

148155
# --- udp coverage for selected configs ---
149156
- os: macos-15

‎docs/implementation-status.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ selected constant values from `ISO_FORTRAN_ENV` of the hosting compiler.
6363

6464
| Procedure | Status | Notes |
6565
|-----------|--------|-------|
66-
| `prif_allocate_coarray` | **YES** | includes ucobound relaxation expected in PRIF 0.8 |
66+
| `prif_allocate_coarray` | **YES** | includes ucobound relaxation and `final_func` argument rename expected in PRIF 0.8 |
6767
| `prif_allocate` | **YES** | |
68-
| `prif_deallocate_coarray` | **YES** | `final_func` support requires flang 20+ |
69-
| `prif_deallocate_coarrays` | **YES** | `final_func` support requires flang 20+ |
68+
| `prif_deallocate_coarray` | **YES** | |
69+
| `prif_deallocate_coarrays` | **YES** | |
7070
| `prif_deallocate` | **YES** | |
7171
| `prif_alias_create` | **YES** | includes ucobound relaxation expected in PRIF 0.8 |
7272
| `prif_alias_destroy` | **YES** | |

‎example/support-test/out_of_memory.F90‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
program out_of_memory
2-
use iso_c_binding, only: c_bool, c_size_t, c_ptr, c_null_funptr, c_int64_t
2+
use unit_test_parameters_m, only: null_final_proc
3+
use iso_c_binding, only: c_bool, c_size_t, c_ptr, c_int64_t
34
use prif
45
implicit none
56

@@ -37,7 +38,7 @@ program out_of_memory
3738
ucobounds(1) = num_imgs
3839

3940
call prif_allocate_coarray( &
40-
lcobounds, ucobounds, size_in_bytes, c_null_funptr, &
41+
lcobounds, ucobounds, size_in_bytes, null_final_proc, &
4142
coarray_handle, allocated_memory)
4243
end block
4344
else

‎include/language-support.F90‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@
2929
#endif
3030
#endif
3131

32-
#ifndef HAVE_FINAL_FUNC_SUPPORT
33-
# if defined(__GFORTRAN__) && HAVE_GCC_VERSION < 160000
34-
! gfortran 14-15 defect prevents declaration of the coarray_cleanup interface:
35-
! https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113338
36-
! reportedly fixed in gfortran 16
37-
# define HAVE_FINAL_FUNC_SUPPORT 0
38-
# elif defined(__flang__) && __flang_major__ < 20
39-
! also missing in flang before 20
40-
# define HAVE_FINAL_FUNC_SUPPORT 0
41-
# else
42-
# define HAVE_FINAL_FUNC_SUPPORT 1
43-
# endif
44-
#endif
45-
4632
#ifndef NEED_C_FUNLOC_WORKAROUND
4733
# if __GFORTRAN__ && HAVE_GCC_VERSION <= 150200
4834
! Gfortran 13..15.2 bug workaround, believed to be fixed in 15.3 and 16.x:

‎include/version.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#elif FORCE_PRIF_0_8
3131
# define CAF_PRIF_VERSION_MINOR 8
3232
#else
33-
# define CAF_PRIF_VERSION_MINOR 7
33+
# define CAF_PRIF_VERSION_MINOR 8
3434
#endif
3535
#define CAF_PRIF_VERSION (100 * CAF_PRIF_VERSION_MAJOR + CAF_PRIF_VERSION_MINOR)
3636

‎src/caffeine/alias_s.F90‎

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
module procedure prif_alias_create
1515
integer(c_int) :: corank
16+
type(prif_coarray_descriptor), pointer :: cdp
17+
type(prif_coarray_descriptor), pointer :: alias_cdp
1618

1719
! validate inputs
1820
call_assert(coarray_handle_check(source_handle))
1921
corank = size(alias_lcobounds)
2022
call_assert(corank > 0)
23+
call_assert(corank <= 15)
2124
if (size(alias_ucobounds) == corank) then
2225
call_assert(all(alias_lcobounds <= alias_ucobounds))
2326
call_assert(product(alias_ucobounds - alias_lcobounds + 1) >= current_team%info%num_images)
@@ -26,50 +29,50 @@
2629
call_assert(all(alias_lcobounds(1:corank-1) <= alias_ucobounds))
2730
end if
2831

29-
30-
allocate(alias_handle%info)
32+
cdp => handle_to_cdp(source_handle)
3133
! start with a copy of the source descriptor
32-
alias_handle%info = source_handle%info
34+
allocate(alias_cdp, source=cdp)
3335

3436
# if CAF_PRIF_VERSION >= 6
35-
alias_handle%info%coarray_data = &
36-
as_c_ptr(as_int(alias_handle%info%coarray_data) + data_pointer_offset)
37+
alias_cdp%coarray_data = &
38+
as_c_ptr(as_int(alias_cdp%coarray_data) + data_pointer_offset)
3739
# endif
3840

3941
! apply provided cobounds
40-
alias_handle%info%corank = corank
41-
alias_handle%info%lcobounds(1:corank) = alias_lcobounds
42-
alias_handle%info%ucobounds(1:corank-1) = alias_ucobounds(1:corank-1)
42+
alias_cdp%corank = corank
43+
alias_cdp%lcobounds(1:corank) = alias_lcobounds
44+
alias_cdp%ucobounds(1:corank-1) = alias_ucobounds(1:corank-1)
4345
call compute_coshape_epp(alias_lcobounds, alias_ucobounds, &
44-
alias_handle%info%coshape_epp(1:corank))
46+
alias_cdp%coshape_epp(1:corank))
4547
# if ASSERTIONS
4648
! The following entries are dead, but initialize them to help detect defects
47-
alias_handle%info%lcobounds(corank+1:15) = huge(0_c_int64_t)
48-
alias_handle%info%ucobounds(corank:14) = -huge(0_c_int64_t)
49-
alias_handle%info%coshape_epp(corank+1:15) = 0
49+
alias_cdp%lcobounds(corank+1:15) = huge(0_c_int64_t)
50+
alias_cdp%ucobounds(corank:14) = -huge(0_c_int64_t)
51+
alias_cdp%coshape_epp(corank+1:15) = 0
5052
# endif
5153

5254
! reset some fields that are unused in aliases
53-
alias_handle%info%reserved = c_null_ptr
54-
alias_handle%info%previous_handle = c_null_ptr
55-
alias_handle%info%next_handle = c_null_ptr
56-
alias_handle%info%final_func = c_null_funptr
55+
alias_cdp%reserved = c_null_ptr
56+
alias_cdp%previous_handle = c_null_ptr
57+
alias_cdp%next_handle = c_null_ptr
58+
alias_cdp%final_proc = c_null_funptr
5759

60+
alias_handle = cdp_to_handle(alias_cdp)
5861
call_assert(coarray_handle_check(alias_handle))
5962
end procedure
6063

6164
module procedure prif_alias_destroy
62-
type(prif_coarray_descriptor), pointer :: info
65+
type(prif_coarray_descriptor), pointer :: cdp
6366

6467
call_assert(coarray_handle_check(alias_handle))
6568

66-
info => alias_handle%info
67-
call_assert(.not. c_associated(info%reserved))
68-
call_assert(.not. c_associated(info%previous_handle))
69-
call_assert(.not. c_associated(info%next_handle))
70-
call_assert(.not. c_associated(info%final_func))
69+
cdp => handle_to_cdp(alias_handle)
70+
call_assert(.not. c_associated(cdp%reserved))
71+
call_assert(.not. c_associated(cdp%previous_handle))
72+
call_assert(.not. c_associated(cdp%next_handle))
73+
call_assert(.not. c_associated(cdp%final_proc))
7174

72-
deallocate(info)
75+
deallocate(cdp)
7376
end procedure
7477

7578
end submodule alias_s

0 commit comments

Comments
 (0)