Skip to content

Commit 15e0bab

Browse files
authored
Abstract base type fitpack_fitter with shared fields and comm (#41)
2 parents 0eef226 + 2de59ba commit 15e0bab

17 files changed

+1360
-365
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"Bash(git push:*)",
1111
"Bash(grep:*)",
1212
"Bash(fpm build:*)",
13-
"Bash(git status:*)"
13+
"Bash(git status:*)",
14+
"Bash(git pull:*)",
15+
"Bash(git stash:*)",
16+
"Bash(git revert:*)"
1417
],
1518
"deny": [],
1619
"ask": []

project/fitpack.cbp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
<Option weight="0" />
9898
</Unit>
9999
<Unit filename="../src/fitpack_curves.f90">
100-
<Option weight="1" />
100+
<Option weight="0" />
101101
</Unit>
102102
<Unit filename="../src/fitpack_curves_c.f90">
103103
<Option weight="0" />
@@ -136,16 +136,16 @@
136136
<Option weight="0" />
137137
</Unit>
138138
<Unit filename="../test/fitpack_curve_tests.f90">
139-
<Option weight="1" />
139+
<Option weight="0" />
140140
</Unit>
141141
<Unit filename="../test/fitpack_test_data.f90">
142142
<Option weight="0" />
143143
</Unit>
144144
<Unit filename="../test/fitpack_tests.f90">
145-
<Option weight="1" />
145+
<Option weight="0" />
146146
</Unit>
147147
<Unit filename="../test/test.f90">
148-
<Option weight="2" />
148+
<Option weight="0" />
149149
</Unit>
150150
<Unit filename="../test/test_curve.cpp" />
151151
<Extensions />

project/fitpack.fdepend

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# fdepslib dependency file v1.1
2+
1771258224source:/Users/federico/code/fitpack/src/fitpack.f90
3+
4+
1704620662source:/Users/federico/code/fitpack/src/fitpack_closed_c.f90
5+
6+
1704623491source:/Users/federico/code/fitpack/src/fitpack_constrained_c.f90
7+
8+
1771258028source:/Users/federico/code/fitpack/src/fitpack_core.f90
9+
10+
1766849605source:/Users/federico/code/fitpack/src/fitpack_core_c.f90
11+
12+
1771259882source:/Users/federico/code/fitpack/src/fitpack_curves.f90
13+
14+
1764238257source:/Users/federico/code/fitpack/src/fitpack_curves_c.f90
15+
16+
1771259888source:/Users/federico/code/fitpack/src/fitpack_grid_surfaces.f90
17+
18+
1771259891source:/Users/federico/code/fitpack/src/fitpack_gridded_polar.f90
19+
20+
1771259893source:/Users/federico/code/fitpack/src/fitpack_gridded_sphere.f90
21+
22+
1771259882source:/Users/federico/code/fitpack/src/fitpack_parametric.f90
23+
24+
1741628651source:/Users/federico/code/fitpack/src/fitpack_parametric_c.f90
25+
26+
1771259895source:/Users/federico/code/fitpack/src/fitpack_parametric_surfaces.f90
27+
28+
1703948614source:/Users/federico/code/fitpack/src/fitpack_periodic_curves_c.f90
29+
30+
1771259887source:/Users/federico/code/fitpack/src/fitpack_polar.f90
31+
32+
1771259889source:/Users/federico/code/fitpack/src/fitpack_spheres.f90
33+
34+
1771259882source:/Users/federico/code/fitpack/src/fitpack_surfaces.f90
35+
36+
1704617612source:/Users/federico/code/fitpack/test/fitpack_cpp_tests.f90
37+
38+
1771258900source:/Users/federico/code/fitpack/test/fitpack_curve_tests.f90
39+
40+
1740771300source:/Users/federico/code/fitpack/test/fitpack_test_data.f90
41+
42+
1765036074source:/Users/federico/code/fitpack/test/fitpack_tests.f90
43+
44+
1771258788source:/Users/federico/code/fitpack/test/test.f90
45+

src/fitpack.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
! **************************************************************************************************
2020
module fitpack
2121
use fitpack_core
22+
use fitpack_fitters
2223
use fitpack_curves
2324
use fitpack_surfaces
2425
use fitpack_grid_surfaces
@@ -38,6 +39,9 @@ module fitpack
3839
public :: FP_FLAG
3940
public :: FP_BOOL
4041

42+
! Public interface: abstract base type
43+
public :: fitpack_fitter
44+
4145
! Public interface: types
4246
public :: fitpack_curve
4347
public :: fitpack_closed_curve

src/fitpack_core.F90

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,23 @@ end function fitpack_polar_boundary
181181
interface FP_COMM_SIZE
182182
module procedure FP_REAL_COMM_SIZE_1D
183183
module procedure FP_REAL_COMM_SIZE_2D
184+
module procedure FP_REAL_COMM_SIZE_3D
184185
module procedure FP_SIZE_COMM_SIZE_1D
185186
end interface FP_COMM_SIZE
186187

187-
!> Pack allocatable 1D arrays into communication buffer
188+
!> Pack allocatable arrays into communication buffer
188189
interface FP_COMM_PACK
189190
module procedure FP_REAL_COMM_PACK_1D
190191
module procedure FP_REAL_COMM_PACK_2D
192+
module procedure FP_REAL_COMM_PACK_3D
191193
module procedure FP_SIZE_COMM_PACK_1D
192194
end interface FP_COMM_PACK
193195

194-
!> Expand communication buffer into allocatable 1D arrays
196+
!> Expand communication buffer into allocatable arrays
195197
interface FP_COMM_EXPAND
196198
module procedure FP_REAL_COMM_EXPAND_1D
197199
module procedure FP_REAL_COMM_EXPAND_2D
200+
module procedure FP_REAL_COMM_EXPAND_3D
198201
module procedure FP_SIZE_COMM_EXPAND_1D
199202
end interface FP_COMM_EXPAND
200203

@@ -18325,6 +18328,18 @@ pure integer(FP_SIZE) function FP_REAL_COMM_SIZE_2D(array)
1832518328
end if
1832618329
end function FP_REAL_COMM_SIZE_2D
1832718330

18331+
!> Calculate storage size for 3D real(FP_REAL) allocatable array
18332+
pure integer(FP_SIZE) function FP_REAL_COMM_SIZE_3D(array)
18333+
real(FP_REAL), allocatable, intent(in) :: array(:,:,:)
18334+
integer(FP_SIZE) :: n
18335+
18336+
FP_REAL_COMM_SIZE_3D = rank(array) ! Header (3 dimensions)
18337+
if (allocated(array)) then
18338+
n = size(array, kind=FP_SIZE)
18339+
FP_REAL_COMM_SIZE_3D = FP_REAL_COMM_SIZE_3D + FP_RCOMMS_PER_BITS(n * storage_size(array))
18340+
end if
18341+
end function FP_REAL_COMM_SIZE_3D
18342+
1832818343
!> Calculate storage size for 1D integer(FP_SIZE) allocatable array
1832918344
pure integer(FP_SIZE) function FP_SIZE_COMM_SIZE_1D(array)
1833018345
integer(FP_SIZE), allocatable, intent(in) :: array(:)
@@ -18384,6 +18399,33 @@ pure subroutine FP_REAL_COMM_PACK_2D(array, buffer)
1838418399
end if
1838518400
end subroutine FP_REAL_COMM_PACK_2D
1838618401

18402+
!> Pack 3D real(FP_REAL) allocatable array into communication buffer
18403+
pure subroutine FP_REAL_COMM_PACK_3D(array, buffer)
18404+
real(FP_REAL), allocatable, intent(in) :: array(:,:,:)
18405+
real(FP_COMM), intent(out) :: buffer(:)
18406+
18407+
integer(FP_SIZE) :: bnd(2, 3), ndoubles
18408+
integer(FP_SIZE), parameter :: header = 3
18409+
18410+
if (allocated(array)) then
18411+
bnd(1, 1) = lbound(array, 1, FP_SIZE)
18412+
bnd(2, 1) = ubound(array, 1, FP_SIZE)
18413+
bnd(1, 2) = lbound(array, 2, FP_SIZE)
18414+
bnd(2, 2) = ubound(array, 2, FP_SIZE)
18415+
bnd(1, 3) = lbound(array, 3, FP_SIZE)
18416+
bnd(2, 3) = ubound(array, 3, FP_SIZE)
18417+
else
18418+
bnd = FP_NOT_ALLOC
18419+
end if
18420+
18421+
buffer(1:header) = transfer(bnd, buffer(1:header), int(header))
18422+
18423+
if (all(bnd /= FP_NOT_ALLOC)) then
18424+
ndoubles = FP_RCOMMS_PER_BITS(size(array, kind=FP_SIZE) * storage_size(array))
18425+
buffer(header+1:header+ndoubles) = transfer(array, buffer(header+1:header+ndoubles), int(ndoubles))
18426+
end if
18427+
end subroutine FP_REAL_COMM_PACK_3D
18428+
1838718429
!> Pack 1D integer(FP_SIZE) allocatable array into communication buffer
1838818430
pure subroutine FP_SIZE_COMM_PACK_1D(array, buffer)
1838918431
integer(FP_SIZE), allocatable, intent(in) :: array(:)
@@ -18419,7 +18461,13 @@ pure subroutine FP_REAL_COMM_EXPAND_1D(array, buffer)
1841918461
if (all(bnd /= FP_NOT_ALLOC)) then
1842018462
allocate(array(bnd(1):bnd(2)))
1842118463
n = FP_RCOMMS_PER_BITS(size(array, kind=FP_SIZE) * storage_size(array))
18464+
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
18465+
! Intel: avoid transfer() — temporary overflows the stack for large arrays.
18466+
! FP_REAL == FP_COMM (both c_double), so direct assignment is valid.
18467+
array(:) = buffer(header+1:header+n)
18468+
#else
1842218469
array = transfer(buffer(header+1:header+n), array)
18470+
#endif
1842318471
end if
1842418472
end subroutine FP_REAL_COMM_EXPAND_1D
1842518473

@@ -18436,10 +18484,39 @@ pure subroutine FP_REAL_COMM_EXPAND_2D(array, buffer)
1843618484
if (all(bnd /= FP_NOT_ALLOC)) then
1843718485
allocate(array(bnd(1,1):bnd(2,1), bnd(1,2):bnd(2,2)))
1843818486
n = FP_RCOMMS_PER_BITS(size(array, kind=FP_SIZE) * storage_size(array))
18487+
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
18488+
! Intel: avoid transfer() — temporary overflows the stack for large arrays.
18489+
! FP_REAL == FP_COMM (both c_double), so reshape buffer directly.
18490+
array(:,:) = reshape(buffer(header+1:header+n), shape(array))
18491+
#else
1843918492
array = reshape(transfer(buffer(header+1:header+n), array, size(array)), shape(array))
18493+
#endif
1844018494
end if
1844118495
end subroutine FP_REAL_COMM_EXPAND_2D
1844218496

18497+
!> Expand communication buffer into 3D real(FP_REAL) allocatable array
18498+
pure subroutine FP_REAL_COMM_EXPAND_3D(array, buffer)
18499+
real(FP_REAL), allocatable, intent(out) :: array(:,:,:)
18500+
real(FP_COMM), intent(in) :: buffer(:)
18501+
18502+
integer(FP_SIZE) :: bnd(2, 3), n
18503+
integer(FP_SIZE), parameter :: header = 3
18504+
18505+
bnd = reshape(transfer(buffer(:header), bnd), shape(bnd))
18506+
18507+
if (all(bnd /= FP_NOT_ALLOC)) then
18508+
allocate(array(bnd(1,1):bnd(2,1), bnd(1,2):bnd(2,2), bnd(1,3):bnd(2,3)))
18509+
n = FP_RCOMMS_PER_BITS(size(array, kind=FP_SIZE) * storage_size(array))
18510+
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
18511+
! Intel: avoid transfer() — temporary overflows the stack for large arrays.
18512+
! FP_REAL == FP_COMM (both c_double), so reshape buffer directly.
18513+
array(:,:,:) = reshape(buffer(header+1:header+n), shape(array))
18514+
#else
18515+
array = reshape(transfer(buffer(header+1:header+n), array, size(array)), shape(array))
18516+
#endif
18517+
end if
18518+
end subroutine FP_REAL_COMM_EXPAND_3D
18519+
1844318520
!> Expand communication buffer into 1D integer(FP_SIZE) allocatable array
1844418521
pure subroutine FP_SIZE_COMM_EXPAND_1D(array, buffer)
1844518522
integer(FP_SIZE), allocatable, intent(out) :: array(:)
@@ -18453,7 +18530,11 @@ pure subroutine FP_SIZE_COMM_EXPAND_1D(array, buffer)
1845318530
if (all(bnd /= FP_NOT_ALLOC)) then
1845418531
allocate(array(bnd(1):bnd(2)))
1845518532
ndoubles = FP_RCOMMS_PER_BITS(size(array, kind=FP_SIZE) * storage_size(array))
18533+
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
18534+
array(:) = transfer(buffer(header+1:header+ndoubles), 0_FP_SIZE, size(array))
18535+
#else
1845618536
array = transfer(buffer(header+1:header+ndoubles), array)
18537+
#endif
1845718538
end if
1845818539
end subroutine FP_SIZE_COMM_EXPAND_1D
1845918540

0 commit comments

Comments
 (0)