Skip to content

Commit 232610a

Browse files
committed
Merge PR #143 (Replace WDOT with DOT_PRODUCT)
This merge brings PR #143 (Replace BLAS function WDOT with the Fortran DOT_PRODUCT intrinsic function, by @yantosca) into the KPP 3.4.0 development stream. This PR replaces the BLAS WDOT function from util/blas.F90 with the Fortran90 intrinsic function DOT_PRODUCT, which does the same thing, and probably more efficiently. We have also updated a couple of calls in BLAS routine WGESL accordingly. Signed-off-by: Bob Yantosca <[email protected]>
2 parents 08d2326 + 1499c34 commit 232610a

File tree

2 files changed

+4
-63
lines changed

2 files changed

+4
-63
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929

3030
### Removed
3131
- Removed C-I tests on Microsoft Azure Dev Pipelines
32-
- Replaced BLAS functions (`WAXPY`, `WCOPY`, `WSCAL`, `WADD`, `WLAMCH`) with pure F90 code from `int/*.f90` integrators (thanks to AI for the help)
32+
- Replaced BLAS functions (`WAXPY`, `WCOPY`, `WSCAL`, `WADD`, `WLAMCH`, `WDOT`) with pure F90 code from `int/*.f90` integrators (thanks to AI for the help)
3333

3434
## [3.3.0] - 2025-07-17
3535
### Added

util/blas.f90

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,70 +20,11 @@
2020
!%%% (5) WLAMCH_ADD %%%
2121
!%%% (6) SET2ZERO %%%
2222
!%%% (7) WADD %%%
23+
!%%% (8) WDOT %%%
2324
!%%% %%%
2425
!%%% @yantosca, 17 Oct 2025 %%%
2526
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2627

27-
!--------------------------------------------------------------
28-
KPP_REAL FUNCTION WDOT (N, DX, incX, DY, incY)
29-
!--------------------------------------------------------------
30-
! dot produce: wdot = x(1:N)*y(1:N)
31-
! only for incX=incY=1
32-
! after BLAS
33-
! replace this by the function from the optimized BLAS implementation:
34-
! CALL SDOT(N,X,1,Y,1) or CALL DDOT(N,X,1,Y,1)
35-
!--------------------------------------------------------------
36-
! USE messy_mecca_kpp_Precision
37-
!--------------------------------------------------------------
38-
IMPLICIT NONE
39-
INTEGER :: N, incX, incY
40-
KPP_REAL :: DX(N), DY(N)
41-
42-
INTEGER :: i, IX, IY, M, MP1, NS
43-
44-
WDOT = 0.0D0
45-
IF (N .LE. 0) RETURN
46-
IF (incX .EQ. incY) IF (incX-1) 5,20,60
47-
!
48-
! Code for unequal or nonpositive increments.
49-
!
50-
5 IX = 1
51-
IY = 1
52-
IF (incX .LT. 0) IX = (-N+1)*incX + 1
53-
IF (incY .LT. 0) IY = (-N+1)*incY + 1
54-
DO i = 1,N
55-
WDOT = WDOT + DX(IX)*DY(IY)
56-
IX = IX + incX
57-
IY = IY + incY
58-
END DO
59-
RETURN
60-
!
61-
! Code for both increments equal to 1.
62-
!
63-
! Clean-up loop so remaining vector length is a multiple of 5.
64-
!
65-
20 M = MOD(N,5)
66-
IF (M .EQ. 0) GO TO 40
67-
DO i = 1,M
68-
WDOT = WDOT + DX(i)*DY(i)
69-
END DO
70-
IF (N .LT. 5) RETURN
71-
40 MP1 = M + 1
72-
DO i = MP1,N,5
73-
WDOT = WDOT + DX(i)*DY(i) + DX(i+1)*DY(i+1) + DX(i+2)*DY(i+2) + &
74-
DX(i+3)*DY(i+3) + DX(i+4)*DY(i+4)
75-
END DO
76-
RETURN
77-
!
78-
! Code for equal, positive, non-unit increments.
79-
!
80-
60 NS = N*incX
81-
DO i = 1,NS,incX
82-
WDOT = WDOT + DX(i)*DY(i)
83-
END DO
84-
85-
END FUNCTION WDOT
86-
8728
!--------------------------------------------------------------
8829
SUBROUTINE WGEFA(N,A,Ipvt,info)
8930
!--------------------------------------------------------------
@@ -203,14 +144,14 @@ SUBROUTINE WGESL(Trans,N,A,Ipvt,b)
203144

204145
! first solve trans(U)*y = b
205146
DO k = 1, n
206-
t = WDOT(k-1,a(1,k),1,b(1),1)
147+
t = DOT_PRODUCT( a(1:k-1, k), b(1:k-1) )
207148
b(k) = (b(k) - t)/a(k,k)
208149
END DO
209150
! now solve trans(L)*x = y
210151
IF (n >= 2) THEN
211152
DO kb = 1, n-1
212153
k = n - kb
213-
b(k) = b(k) + WDOT(n-k,a(k+1,k),1,b(k+1),1)
154+
b(k) = b(k) + DOT_PRODUCT( a(k+1:n, k), b(k+1:n) )
214155
l = Ipvt(k)
215156
IF (l /= k) THEN
216157
t = b(l); b(l) = b(k); b(k) = t

0 commit comments

Comments
 (0)