BerkeleyLab / caffeine

A parallel runtime library for Fortran compilers
https://berkeleylab.github.io/caffeine/
Other
37 stars 7 forks source link

Add level of indirection to Caffeine implementation of `prif_team_type` #123

Closed bonachea closed 1 month ago

bonachea commented 1 month ago

Currently in prif.f90:

  type, public :: prif_team_type
    private
    type(c_ptr) :: gex_team
    type(c_ptr) :: heap_mspace
    integer(c_intptr_t) :: heap_start
    type(prif_team_type), pointer :: parent_team
    type(handle_data), pointer :: coarrays
  end type

This "unboxed" implementation of prif_team_type contains several mutable fields, and the WIP teams branch adds even more.

As such, I believe this is an unsuitable representation for prif_team_type: because it fails to provide the handle-like semantics of ISO_FORTRAN_ENV::TEAM_TYPE. IOW the client is free to make copies of TEAM_TYPE/prif_team_type variables, and all copies of the same prif_team_type value need to consistently reference the same abstract team, even after operations like CHANGE TEAM and prif_allocate_coarray that mutate the team's internal state.

The solution is to add a level of indirection, similar to what we already have prif_coarray_handle (for some of the same reasons). Eg:

  type, public :: prif_team_type
    private
    type(team_data), pointer :: info
  end type

...

  type, private :: team_data
    private
    type(c_ptr) :: gex_team
    type(c_ptr) :: heap_mspace
    integer(c_intptr_t) :: heap_start
    type(team_data), pointer :: parent_team
    type(handle_data), pointer :: coarrays
  end type

Along with updates to all the code that accesses prif_team_type components.

bonachea commented 1 month ago

Closely related: #59

bonachea commented 1 month ago

Resolved in #127