Skip to content

Commit

Permalink
The best approach seems to be resolving the type inside create_block
Browse files Browse the repository at this point in the history
  • Loading branch information
pbartholomew08 committed Jan 17, 2025
1 parent a440606 commit efdb2cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/allocator.f90
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,23 @@ subroutine compute_padded_dims(self, sz)

end subroutine

function create_block(self) result(ptr)
function create_block(self, next) result(ptr)
!! Allocate memory for a new block and return a pointer to a new
!! [[m_allocator(module):field_t(type)]] object.
class(allocator_t), intent(inout) :: self
class(field_t), pointer, intent(in) :: next
type(field_t), pointer :: newblock
class(field_t), pointer :: ptr
self%next_id = self%next_id + 1
allocate (newblock)
newblock = field_t(self%ngrid, self%first, id=self%next_id)
associate(p_next => next)
select type (p_next)
type is (field_t)
newblock = field_t(self%ngrid, p_next, id=self%next_id)
class default
error stop "Incorrect overloading for create_block"
end select
end associate
ptr => newblock
end function create_block

Expand All @@ -130,7 +138,7 @@ function get_block(self, dir, data_loc) result(handle)
if (.not. associated(self%first)) then
! Construct a field_t. This effectively allocates
! storage space.
self%first => self%create_block()
self%first => self%create_block(self%first)
end if
handle => self%first
self%first => self%first%next ! 2nd block becomes head block
Expand Down
6 changes: 3 additions & 3 deletions src/cuda/allocator.f90
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ function cuda_allocator_init(mesh, sz) result(allocator)
allocator%allocator_t = allocator_t(mesh, sz)
end function cuda_allocator_init

function create_cuda_block(self) result(ptr)
function create_cuda_block(self, next) result(ptr)
class(cuda_allocator_t), intent(inout) :: self
type(cuda_field_t), pointer, intent(in) :: next
type(cuda_field_t), pointer :: next
type(cuda_field_t), pointer :: newblock
class(field_t), pointer :: ptr
allocate (newblock)
self%next_id = self%next_id + 1
newblock = cuda_field_t(self%ngrid, self%first, id=self%next_id)
newblock = cuda_field_t(self%ngrid, next, id=self%next_id)
ptr => newblock
end function create_cuda_block

Expand Down

0 comments on commit efdb2cf

Please sign in to comment.