Skip to content

Commit

Permalink
Add Fortran allocate with mold
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Oct 30, 2024
1 parent c9cf796 commit e64f1b8
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 1 deletion.
147 changes: 146 additions & 1 deletion pluto/src/pluto_f/pluto_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ subroutine c_pluto_scope_pop() bind(c)
procedure :: pluto_allocator_allocate_real64_r2
procedure :: pluto_allocator_allocate_real64_r3
procedure :: pluto_allocator_allocate_real64_r4
procedure :: pluto_allocator_allocate_mold_int32_r1
procedure :: pluto_allocator_allocate_mold_int32_r2
procedure :: pluto_allocator_allocate_mold_int32_r3
procedure :: pluto_allocator_allocate_mold_int32_r4
procedure :: pluto_allocator_allocate_mold_int64_r1
procedure :: pluto_allocator_allocate_mold_int64_r2
procedure :: pluto_allocator_allocate_mold_int64_r3
procedure :: pluto_allocator_allocate_mold_int64_r4
procedure :: pluto_allocator_allocate_mold_real32_r1
procedure :: pluto_allocator_allocate_mold_real32_r2
procedure :: pluto_allocator_allocate_mold_real32_r3
procedure :: pluto_allocator_allocate_mold_real32_r4
procedure :: pluto_allocator_allocate_mold_real64_r1
procedure :: pluto_allocator_allocate_mold_real64_r2
procedure :: pluto_allocator_allocate_mold_real64_r3
procedure :: pluto_allocator_allocate_mold_real64_r4

generic :: allocate => &
& pluto_allocator_allocate_int32_r1, &
Expand All @@ -89,7 +105,23 @@ subroutine c_pluto_scope_pop() bind(c)
& pluto_allocator_allocate_real64_r1, &
& pluto_allocator_allocate_real64_r2, &
& pluto_allocator_allocate_real64_r3, &
& pluto_allocator_allocate_real64_r4
& pluto_allocator_allocate_real64_r4, &
& pluto_allocator_allocate_mold_int32_r1, &
& pluto_allocator_allocate_mold_int32_r2, &
& pluto_allocator_allocate_mold_int32_r3, &
& pluto_allocator_allocate_mold_int32_r4, &
& pluto_allocator_allocate_mold_int64_r1, &
& pluto_allocator_allocate_mold_int64_r2, &
& pluto_allocator_allocate_mold_int64_r3, &
& pluto_allocator_allocate_mold_int64_r4, &
& pluto_allocator_allocate_mold_real32_r1, &
& pluto_allocator_allocate_mold_real32_r2, &
& pluto_allocator_allocate_mold_real32_r3, &
& pluto_allocator_allocate_mold_real32_r4, &
& pluto_allocator_allocate_mold_real64_r1, &
& pluto_allocator_allocate_mold_real64_r2, &
& pluto_allocator_allocate_mold_real64_r3, &
& pluto_allocator_allocate_mold_real64_r4


procedure :: pluto_allocator_deallocate_int32_r1
Expand Down Expand Up @@ -461,6 +493,119 @@ subroutine pluto_allocator_allocate_real64_r4(this, array, shape)
endif
end subroutine


subroutine pluto_allocator_allocate_mold_int32_r1(this, array, mold)
class(pluto_allocator) :: this
integer(c_int32_t), pointer, intent(out) :: array(:)
integer(c_int32_t), intent(in) :: mold(:)
call pluto_allocator_allocate_int32_r1(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_int32_r2(this, array, mold)
class(pluto_allocator) :: this
integer(c_int32_t), pointer, intent(out) :: array(:,:)
integer(c_int32_t), intent(in) :: mold(:,:)
call pluto_allocator_allocate_int32_r2(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_int32_r3(this, array, mold)
class(pluto_allocator) :: this
integer(c_int32_t), pointer, intent(out) :: array(:,:,:)
integer(c_int32_t), intent(in) :: mold(:,:,:)
call pluto_allocator_allocate_int32_r3(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_int32_r4(this, array, mold)
class(pluto_allocator) :: this
integer(c_int32_t), pointer, intent(out) :: array(:,:,:,:)
integer(c_int32_t), intent(in) :: mold(:,:,:,:)
call pluto_allocator_allocate_int32_r4(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_int64_r1(this, array, mold)
class(pluto_allocator) :: this
integer(c_int64_t), pointer, intent(out) :: array(:)
integer(c_int64_t), intent(in) :: mold(:)
call pluto_allocator_allocate_int64_r1(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_int64_r2(this, array, mold)
class(pluto_allocator) :: this
integer(c_int64_t), pointer, intent(out) :: array(:,:)
integer(c_int64_t), intent(in) :: mold(:,:)
call pluto_allocator_allocate_int64_r2(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_int64_r3(this, array, mold)
class(pluto_allocator) :: this
integer(c_int64_t), pointer, intent(out) :: array(:,:,:)
integer(c_int64_t), intent(in) :: mold(:,:,:)
call pluto_allocator_allocate_int64_r3(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_int64_r4(this, array, mold)
class(pluto_allocator) :: this
integer(c_int64_t), pointer, intent(out) :: array(:,:,:,:)
integer(c_int64_t), intent(in) :: mold(:,:,:,:)
call pluto_allocator_allocate_int64_r4(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real32_r1(this, array, mold)
class(pluto_allocator) :: this
real(c_float), pointer, intent(out) :: array(:)
real(c_float), intent(in) :: mold(:)
call pluto_allocator_allocate_real32_r1(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real32_r2(this, array, mold)
class(pluto_allocator) :: this
real(c_float), pointer, intent(out) :: array(:,:)
real(c_float), intent(in) :: mold(:,:)
call pluto_allocator_allocate_real32_r2(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real32_r3(this, array, mold)
class(pluto_allocator) :: this
real(c_float), pointer, intent(out) :: array(:,:,:)
real(c_float), intent(in) :: mold(:,:,:)
call pluto_allocator_allocate_real32_r3(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real32_r4(this, array, mold)
class(pluto_allocator) :: this
real(c_float), pointer, intent(out) :: array(:,:,:,:)
real(c_float), intent(in) :: mold(:,:,:,:)
call pluto_allocator_allocate_real32_r4(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real64_r1(this, array, mold)
class(pluto_allocator) :: this
real(c_double), pointer, intent(out) :: array(:)
real(c_double), intent(in) :: mold(:)
call pluto_allocator_allocate_real64_r1(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real64_r2(this, array, mold)
class(pluto_allocator) :: this
real(c_double), pointer, intent(out) :: array(:,:)
real(c_double), intent(in) :: mold(:,:)
call pluto_allocator_allocate_real64_r2(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real64_r3(this, array, mold)
class(pluto_allocator) :: this
real(c_double), pointer, intent(out) :: array(:,:,:)
real(c_double), intent(in) :: mold(:,:,:)
call pluto_allocator_allocate_real64_r3(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_allocate_mold_real64_r4(this, array, mold)
class(pluto_allocator) :: this
real(c_double), pointer, intent(out) :: array(:,:,:,:)
real(c_double), intent(in) :: mold(:,:,:,:)
call pluto_allocator_allocate_real64_r4(this, array, shape(mold))
end subroutine

subroutine pluto_allocator_deallocate_int32_r1(this, array)
class(pluto_allocator) :: this
integer(c_int32_t), pointer, intent(inout) :: array(:)
Expand Down
8 changes: 8 additions & 0 deletions pluto/tests/test_pluto_f.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ program pluto_test_pluto_f
real(wp), pointer :: array1d(:), array2d(:,:), array3d(:,:,:), array4d(:,:,:,:)
real(wp) :: real_value

integer(4), pointer :: iarray1d(:), jarray1d(:)


call pluto%host%set_default_resource("pluto::managed_resource")
call pluto%host%get_default_resource(host_memory_resource)
call host_memory_resource%allocate(mem, 10*c_sizeof(real_value))
Expand All @@ -35,4 +38,9 @@ program pluto_test_pluto_f
call host_allocator%allocate(array4d, [5,2,3,6])
call host_allocator%deallocate(array4d)

call host_allocator%allocate(iarray1d, shape=[20])
call host_allocator%allocate(jarray1d, mold=iarray1d)
call host_allocator%deallocate(iarray1d)
call host_allocator%deallocate(jarray1d)

end program

0 comments on commit e64f1b8

Please sign in to comment.