Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intrinsics module with alternative implementations #915

Merged
merged 54 commits into from
Feb 27, 2025
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
08ec0aa
intrinsics module with fast sums
jalvesz Dec 24, 2024
c36251e
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Dec 24, 2024
2207f41
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Dec 26, 2024
2bc7af9
add fast dot_product and start tests
jalvesz Dec 26, 2024
4625205
Merge branch 'intrinsics' of https://github.com/jalvesz/stdlib into i…
jalvesz Dec 26, 2024
243ea6f
add complex sum test
jalvesz Dec 26, 2024
c38dcd6
test masked sum
jalvesz Dec 26, 2024
bf1ce2f
add dot_product tests
jalvesz Dec 26, 2024
cc9df61
start specs
jalvesz Dec 29, 2024
671fd61
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Jan 2, 2025
75945f1
split into submodules
jalvesz Jan 2, 2025
d05903f
specs and examples
jalvesz Jan 2, 2025
c0d96e5
Merge branch 'intrinsics' of https://github.com/jalvesz/stdlib into i…
jalvesz Jan 2, 2025
4abd8d3
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Jan 3, 2025
7c6e8a4
fix specs
jalvesz Jan 3, 2025
7cea1fd
fix test: complex initialization
jalvesz Jan 3, 2025
eaffa4a
fix test: complex assignment caused accuracy loss
jalvesz Jan 4, 2025
ad64162
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Jan 5, 2025
a3d24e4
extend fsum support for ndarrays
jalvesz Jan 5, 2025
5a1fdcb
remove unnecessary definition
jalvesz Jan 5, 2025
47396ac
update specs, change name of kahan kernel
jalvesz Jan 5, 2025
ecb7050
small reorganization
jalvesz Jan 7, 2025
87ef502
Merge branch 'intrinsics' of https://github.com/jalvesz/stdlib into i…
jalvesz Jan 7, 2025
14be974
change names to stdlib_*
jalvesz Jan 11, 2025
aaa68bc
add comments
jalvesz Jan 12, 2025
cc232e1
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Jan 17, 2025
6e36b6f
extend kahan sum for rank N arrays
jalvesz Jan 17, 2025
65175d7
Merge branch 'intrinsics' of https://github.com/jalvesz/stdlib into i…
jalvesz Jan 17, 2025
8a35f38
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Jan 29, 2025
16a0e96
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Jan 30, 2025
f0ed271
Update src/stdlib_intrinsics.fypp
jalvesz Feb 7, 2025
316269b
Update test/intrinsics/test_intrinsics.fypp
jalvesz Feb 7, 2025
52aab02
Update test/intrinsics/test_intrinsics.fypp
jalvesz Feb 7, 2025
a6be0a0
fix test allocation
jalvesz Feb 7, 2025
3e171f7
nmask allocation
jalvesz Feb 7, 2025
332b748
revert nmask allocation
jalvesz Feb 7, 2025
537cef8
change kahan reference
jalvesz Feb 10, 2025
a4370c2
Merge branch 'fortran-lang:master' into intrinsics
jalvesz Feb 10, 2025
9c5b2e0
Refactor stdlib module functions to unify handling of integer, real, …
jalvesz Feb 20, 2025
10add87
Update src/stdlib_intrinsics.fypp
jalvesz Feb 20, 2025
4b1c7e7
Update src/stdlib_intrinsics.fypp
jalvesz Feb 20, 2025
23981d6
Update src/stdlib_intrinsics.fypp
jalvesz Feb 20, 2025
db97da9
Update src/stdlib_intrinsics.fypp
jalvesz Feb 20, 2025
1b9019c
Update src/stdlib_intrinsics.fypp
jalvesz Feb 20, 2025
783aabd
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 20, 2025
f867f5a
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 20, 2025
a54b962
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 20, 2025
6fd728d
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 20, 2025
11fb555
Merge branch 'intrinsics' of https://github.com/jalvesz/stdlib into i…
jalvesz Feb 20, 2025
cf76219
fix documentation
jalvesz Feb 22, 2025
86b0ebc
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 24, 2025
7bc190e
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 24, 2025
d905ed8
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 24, 2025
12612bc
Update doc/specs/stdlib_intrinsics.md
jalvesz Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
intrinsics module with fast sums
jalvesz committed Dec 24, 2024
commit 08ec0aa208ed11e4d36d0a1205e8a6594f1dd9c3
159 changes: 159 additions & 0 deletions src/stdlib_intrinsics.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#:include "common.fypp"
#:set R_KINDS_TYPES = list(zip(REAL_KINDS, REAL_TYPES, REAL_SUFFIX))
#:set C_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES, CMPLX_SUFFIX))
#:set RANKS = range(2, 2)
module stdlib_intrinsics
use stdlib_kinds
implicit none
private

interface fsum
#:for rk, rt in REAL_KINDS_TYPES
module procedure :: fsum_1d_${rk}$
module procedure :: fsum_1d_${rk}$_mask
#:endfor
end interface
public :: fsum

interface fsum_kahan
#:for rk, rt in REAL_KINDS_TYPES
module procedure :: fsum_kahan_1d_${rk}$
module procedure :: fsum_kahan_1d_${rk}$_mask
#:endfor
end interface
public :: fsum_kahan

interface vkahan
#:for rk, rt in REAL_KINDS_TYPES
module procedure :: vkahan_${rk}$
module procedure :: vkahan_m_${rk}$
#:endfor
end interface

#:for k1, t1, s1 in (R_KINDS_TYPES)
${t1}$, parameter :: zero_${s1}$ = 0._${k1}$
#:endfor
#:for k1, t1, s1 in (C_KINDS_TYPES)
${t1}$, parameter :: zero_${s1}$ = (0._${k1}$,0._${k1}$)
#:endfor
integer, parameter :: chunk = 64

contains

#:for k1, t1, s1 in R_KINDS_TYPES
pure function fsum_1d_${s1}$(a) result(s)
${t1}$, intent(in) :: a(:)
${t1}$ :: s
${t1}$ :: abatch(chunk)
integer :: i, dr, rr
! -----------------------------
dr = size(a)/chunk
rr = size(a) - dr*chunk

abatch = zero_${s1}$
do i = 1, dr
abatch(1:chunk) = abatch(1:chunk) + a(chunk*i-chunk+1:chunk*i)
end do
abatch(1:rr) = abatch(1:rr) + a(size(a)-rr+1:size(a))

s = zero_${s1}$
do i = 1, chunk/2
s = s + abatch(i)+abatch(chunk/2+i)
end do
end function

pure function fsum_1d_${s1}$_mask(a,mask) result(s)
${t1}$, intent(in) :: a(:)
logical, intent(in) :: mask(:)
${t1}$ :: s
${t1}$ :: abatch(chunk)
integer :: i, dr, rr
! -----------------------------
dr = size(a)/chunk
rr = size(a) - dr*chunk

abatch = zero_${s1}$
do i = 1, dr
abatch(1:chunk) = abatch(1:chunk) + merge( zero_${s1}$ , a(chunk*i-chunk+1:chunk*i) , mask(chunk*i-chunk+1:chunk*i) )
end do
abatch(1:rr) = abatch(1:rr) + merge( zero_${s1}$ , a(size(a)-rr+1:size(a)) , mask(size(a)-rr+1:size(a)) )

s = zero_${s1}$
do i = 1, chunk/2
s = s + abatch(i)+abatch(chunk/2+i)
end do
end function
#:endfor

#:for k1, t1, s1 in R_KINDS_TYPES
pure function fsum_kahan_1d_${s1}$(a) result(s)
${t1}$, intent(in) :: a(:)
${t1}$ :: s
${t1}$ :: sbatch(chunk)
${t1}$ :: cbatch(chunk)
integer :: i, dr, rr
! -----------------------------
dr = size(a)/(chunk)
rr = size(a) - dr*chunk
sbatch = zero_${s1}$
cbatch = zero_${s1}$
do i = 1, dr
call vkahan( a(chunk*i-chunk+1:chunk*i) , sbatch(1:chunk) , cbatch(1:chunk) )
end do
call vkahan( a(size(a)-rr+1:size(a)) , sbatch(1:rr) , cbatch(1:rr) )

s = zero_${s1}$
do i = 1,chunk
call vkahan( sbatch(i) , s , cbatch(i) )
end do
end function

pure function fsum_kahan_1d_${s1}$_mask(a,mask) result(s)
${t1}$, intent(in) :: a(:)
logical, intent(in) :: mask(:)
${t1}$ :: s
${t1}$ :: sbatch(chunk)
${t1}$ :: cbatch(chunk)
integer :: i, dr, rr
! -----------------------------
dr = size(a)/(chunk)
rr = size(a) - dr*chunk
sbatch = zero_${s1}$
cbatch = zero_${s1}$
do i = 1, dr
call vkahan( a(chunk*i-chunk+1:chunk*i) , sbatch(1:chunk) , cbatch(1:chunk) , mask(chunk*i-chunk+1:chunk*i) )
end do
call vkahan( a(size(a)-rr+1:size(a)) , sbatch(1:rr) , cbatch(1:rr) , mask(size(a)-rr+1:size(a)) )

s = zero_${s1}$
do i = 1,chunk
call vkahan( sbatch(i) , s , cbatch(i) )
end do
end function
#:endfor

#:for k1, t1, s1 in R_KINDS_TYPES
elemental subroutine vkahan_${s1}$(a,s,c)
${t1}$, intent(in) :: a
${t1}$, intent(inout) :: s
${t1}$, intent(inout) :: c
${t1}$ :: t, y
y = a - c
t = s + y
c = (t - s) - y
s = t
end subroutine
elemental subroutine vkahan_m_${s1}$(a,s,c,m)
${t1}$, intent(in) :: a
${t1}$, intent(inout) :: s
${t1}$, intent(inout) :: c
logical, intent(in) :: m
${t1}$ :: t, y
y = a - c
t = s + y
c = (t - s) - y
s = merge( s , t , m )
end subroutine
#:endfor

end module stdlib_intrinsics