Skip to content

Commit 3848d2d

Browse files
Fix the build, fix tests
1 parent 43976fb commit 3848d2d

71 files changed

Lines changed: 1076 additions & 1136 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BLAS/Makefile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
# Compilers and flags
55
FC = gfortran
66
CC = gcc
7-
FFLAGS = -O2 -fPIC -ffree-line-length-none -Wuninitialized -Wmaybe-uninitialized -Iinclude
8-
FFLAGS_F77 = -O2 -fPIC -ffixed-line-length-none -Wuninitialized -Wmaybe-uninitialized -Iinclude
7+
# Ensure .mod files are written to (and read from) build/
8+
# Defaults: gfortran -> -J, ifort/ifx -> -module. You can still override MODFLAG on the make command line.
9+
MODDIR = $(BUILD_DIR)
10+
ifeq ($(findstring ifort,$(FC)),ifort)
11+
MODFLAG ?= -module $(MODDIR)
12+
else ifeq ($(findstring ifx,$(FC)),ifx)
13+
MODFLAG ?= -module $(MODDIR)
14+
else
15+
MODFLAG ?= -J$(MODDIR)
16+
endif
17+
FFLAGS = -O2 -fPIC -ffree-line-length-none -Wuninitialized -Wmaybe-uninitialized -Iinclude -I$(MODDIR) $(MODFLAG)
18+
FFLAGS_F77 = -O2 -fPIC -ffixed-line-length-none -Wuninitialized -Wmaybe-uninitialized -Iinclude -I$(MODDIR)
919
CFLAGS = -O2 -fPIC
1020

1121
# Directory structure
@@ -172,7 +182,8 @@ $(BUILD_DIR)/%_dep2.o: $(SRC_DIR)/%_dep2.f
172182
# DIFFSIZES_access - F77 .f or F90 .f90 (generator picks based on COMMON line length)
173183
# When .f90 exists: compile to produce .o and .mod; wrappers depend on .mod explicitly (avoids stale .o from .f)
174184
$(BUILD_DIR)/diffsizes_access.mod: $(SRC_DIR)/DIFFSIZES_access.f90
175-
$(FC) $(FFLAGS) -J$(BUILD_DIR) -c $< -o $(BUILD_DIR)/DIFFSIZES_access.o
185+
@mkdir -p $(BUILD_DIR)
186+
$(FC) $(FFLAGS) -c $< -o $(BUILD_DIR)/DIFFSIZES_access.o
176187

177188
# When .f90 exists: DIFFSIZES_access.o is produced as byproduct of diffsizes_access.mod (do not compile .f)
178189
ifeq ($(wildcard $(SRC_DIR)/DIFFSIZES_access.f90),)
@@ -184,7 +195,7 @@ endif
184195

185196
# DIFFSIZES_access_wrappers.f - external symbols for F90 module (set_*, get_*, check_*)
186197
$(BUILD_DIR)/DIFFSIZES_access_wrappers.o: $(SRC_DIR)/DIFFSIZES_access_wrappers.f $(BUILD_DIR)/diffsizes_access.mod
187-
$(FC) $(FFLAGS) -J$(BUILD_DIR) -c $(SRC_DIR)/DIFFSIZES_access_wrappers.f -o $@
198+
$(FC) $(FFLAGS) -c $(SRC_DIR)/DIFFSIZES_access_wrappers.f -o $@
188199

189200
# DIFFSIZES handling (supports both Fortran 90 module and Fortran 77 include)
190201
# For F90: DIFFSIZES.f90 is compiled to produce DIFFSIZES.o and DIFFSIZES.mod
@@ -371,6 +382,7 @@ $(BUILD_DIR)/test_%_vector_reverse.o: $(TEST_DIR)/test_%_vector_reverse.f90 $(BU
371382
clean:
372383
@echo "Cleaning build directory..."
373384
rm -rf $(BUILD_DIR)
385+
rm -f *.mod
374386
@echo "Clean complete."
375387

376388
# Rebuild everything

BLAS/test/test_caxpy.f90

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ subroutine run_test_for_size(n, passed)
4747
integer :: incy
4848

4949
! Derivative variables
50-
complex(4), dimension(n) :: cx_d
5150
complex(4) :: ca_d
5251
complex(4), dimension(n) :: cy_d
52+
complex(4), dimension(n) :: cx_d
5353

5454
! Array restoration and derivative storage
55-
complex(4), dimension(n) :: cx_orig, cx_d_orig
5655
complex(4) :: ca_orig, ca_d_orig
5756
complex(4), dimension(n) :: cy_orig, cy_d_orig
57+
complex(4), dimension(n) :: cx_orig, cx_d_orig
5858
real(4) :: temp_re, temp_im ! For complex random init
5959
integer :: i, j
6060

@@ -77,11 +77,6 @@ subroutine run_test_for_size(n, passed)
7777
end do
7878

7979
! Initialize input derivatives
80-
do i = 1, n
81-
call random_number(temp_re)
82-
call random_number(temp_im)
83-
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
84-
end do
8580
call random_number(temp_re)
8681
call random_number(temp_im)
8782
ca_d = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
@@ -90,37 +85,42 @@ subroutine run_test_for_size(n, passed)
9085
call random_number(temp_im)
9186
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
9287
end do
88+
do i = 1, n
89+
call random_number(temp_re)
90+
call random_number(temp_im)
91+
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
92+
end do
9393

9494
! Store _orig and _d_orig
95-
cx_d_orig = cx_d
9695
ca_d_orig = ca_d
9796
cy_d_orig = cy_d
98-
cx_orig = cx
97+
cx_d_orig = cx_d
9998
ca_orig = ca
10099
cy_orig = cy
100+
cx_orig = cx
101101

102102
write(*,*) 'Testing CAXPY (n =', n, ')'
103103
cy_orig = cy
104104

105105
! Call the differentiated function
106106
call caxpy_d(nsize, ca, ca_d, cx, cx_d, 1, cy, cy_d, 1)
107-
cx_d = cx_d_orig
108107
ca_d = ca_d_orig
108+
cx_d = cx_d_orig
109109

110110
write(*,*) 'Function calls completed successfully'
111111

112112
! Numerical differentiation check
113-
call check_derivatives_numerically(n, nsize, cy_orig, cx_orig, ca_orig, cy_d_orig, cx_d_orig, ca_d_orig, cy_d, passed)
113+
call check_derivatives_numerically(n, nsize, ca_orig, cy_orig, cx_orig, ca_d_orig, cy_d_orig, cx_d_orig, cy_d, passed)
114114

115115
end subroutine run_test_for_size
116116

117-
subroutine check_derivatives_numerically(n, nsize, cy_orig, cx_orig, ca_orig, cy_d_orig, cx_d_orig, ca_d_orig, cy_d, passed)
117+
subroutine check_derivatives_numerically(n, nsize, ca_orig, cy_orig, cx_orig, ca_d_orig, cy_d_orig, cx_d_orig, cy_d, passed)
118118
implicit none
119119
integer, intent(in) :: n
120120
integer, intent(in) :: nsize
121+
complex(4), intent(in) :: ca_orig, ca_d_orig
121122
complex(4), intent(in) :: cy_orig(n), cy_d_orig(n)
122123
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
123-
complex(4), intent(in) :: ca_orig, ca_d_orig
124124
complex(4), intent(in) :: cy_d(n)
125125
logical, intent(out) :: passed
126126

@@ -131,9 +131,9 @@ subroutine check_derivatives_numerically(n, nsize, cy_orig, cx_orig, ca_orig, cy
131131
logical :: has_large_errors
132132
complex(4), dimension(n) :: cy_forward, cy_backward
133133
integer :: i, j
134+
complex(4) :: ca
134135
complex(4), dimension(n) :: cy
135136
complex(4), dimension(n) :: cx
136-
complex(4) :: ca
137137

138138
max_error = 0.0e0
139139
has_large_errors = .false.
@@ -142,16 +142,16 @@ subroutine check_derivatives_numerically(n, nsize, cy_orig, cx_orig, ca_orig, cy
142142
write(*,*) 'Step size h =', h
143143

144144
! Forward perturbation: f(x + h)
145+
ca = ca_orig + h * ca_d_orig
145146
cy = cy_orig + h * cy_d_orig
146147
cx = cx_orig + h * cx_d_orig
147-
ca = ca_orig + h * ca_d_orig
148148
call caxpy(nsize, ca, cx, 1, cy, 1)
149149
cy_forward = cy
150150

151151
! Backward perturbation: f(x - h)
152+
ca = ca_orig - h * ca_d_orig
152153
cy = cy_orig - h * cy_d_orig
153154
cx = cx_orig - h * cx_d_orig
154-
ca = ca_orig - h * ca_d_orig
155155
call caxpy(nsize, ca, cx, 1, cy, 1)
156156
cy_backward = cy
157157

BLAS/test/test_ccopy.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ subroutine run_test_for_size(n, passed)
4646
integer :: incy
4747

4848
! Derivative variables
49-
complex(4), dimension(n) :: cx_d
5049
complex(4), dimension(n) :: cy_d
50+
complex(4), dimension(n) :: cx_d
5151

5252
! Array restoration and derivative storage
53-
complex(4), dimension(n) :: cx_orig, cx_d_orig
5453
complex(4), dimension(n) :: cy_orig, cy_d_orig
54+
complex(4), dimension(n) :: cx_orig, cx_d_orig
5555
real(4) :: temp_re, temp_im ! For complex random init
5656
integer :: i, j
5757

@@ -74,19 +74,19 @@ subroutine run_test_for_size(n, passed)
7474
do i = 1, n
7575
call random_number(temp_re)
7676
call random_number(temp_im)
77-
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
77+
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
7878
end do
7979
do i = 1, n
8080
call random_number(temp_re)
8181
call random_number(temp_im)
82-
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
82+
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8383
end do
8484

8585
! Store _orig and _d_orig
86-
cx_d_orig = cx_d
8786
cy_d_orig = cy_d
88-
cx_orig = cx
87+
cx_d_orig = cx_d
8988
cy_orig = cy
89+
cx_orig = cx
9090

9191
write(*,*) 'Testing CCOPY (n =', n, ')'
9292

BLAS/test/test_cdotc.f90

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ subroutine run_test_for_size(n, passed)
4646
integer :: incy
4747

4848
! Derivative variables
49-
complex(4), dimension(n) :: cx_d
50-
complex(4) :: cdotc_d_result ! Derivative of function result (avoid name clash with func_d)
5149
complex(4), dimension(n) :: cy_d
50+
complex(4) :: cdotc_d_result ! Derivative of function result (avoid name clash with func_d)
51+
complex(4), dimension(n) :: cx_d
5252

5353
! Array restoration and derivative storage
54-
complex(4), dimension(n) :: cx_orig, cx_d_orig
55-
complex(4) :: cdotc_orig ! Function result (no _d_orig - use _d_result)
5654
complex(4), dimension(n) :: cy_orig, cy_d_orig
55+
complex(4) :: cdotc_orig ! Function result (no _d_orig - use _d_result)
56+
complex(4), dimension(n) :: cx_orig, cx_d_orig
5757
real(4) :: temp_re, temp_im ! For complex random init
5858
integer :: i, j
5959

@@ -76,41 +76,41 @@ subroutine run_test_for_size(n, passed)
7676
do i = 1, n
7777
call random_number(temp_re)
7878
call random_number(temp_im)
79-
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
79+
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8080
end do
8181
do i = 1, n
8282
call random_number(temp_re)
8383
call random_number(temp_im)
84-
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
84+
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8585
end do
8686

8787
! Store _orig and _d_orig
88-
cx_d_orig = cx_d
8988
cy_d_orig = cy_d
90-
cx_orig = cx
91-
cdotc_orig = cdotc(nsize, cx, 1, cy, 1)
89+
cx_d_orig = cx_d
9290
cy_orig = cy
91+
cdotc_orig = cdotc(nsize, cx, 1, cy, 1)
92+
cx_orig = cx
9393

9494
write(*,*) 'Testing CDOTC (n =', n, ')'
9595

9696
! Call the differentiated function
9797
cdotc_d_result = cdotc_d(nsize, cx, cx_d, 1, cy, cy_d, 1, cdotc_orig)
98-
cx_d = cx_d_orig
9998
cy_d = cy_d_orig
99+
cx_d = cx_d_orig
100100

101101
write(*,*) 'Function calls completed successfully'
102102

103103
! Numerical differentiation check
104-
call check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotc_orig, cx_d_orig, cy_d_orig, cdotc_d_result, passed)
104+
call check_derivatives_numerically(n, nsize, cy_orig, cx_orig, cdotc_orig, cy_d_orig, cx_d_orig, cdotc_d_result, passed)
105105

106106
end subroutine run_test_for_size
107107

108-
subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotc_orig, cx_d_orig, cy_d_orig, cdotc_d_result, passed)
108+
subroutine check_derivatives_numerically(n, nsize, cy_orig, cx_orig, cdotc_orig, cy_d_orig, cx_d_orig, cdotc_d_result, passed)
109109
implicit none
110110
integer, intent(in) :: n
111111
integer, intent(in) :: nsize
112-
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
113112
complex(4), intent(in) :: cy_orig(n), cy_d_orig(n)
113+
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
114114
complex(4), intent(in) :: cdotc_orig
115115
complex(4), intent(in) :: cdotc_d_result
116116
logical, intent(out) :: passed
@@ -122,8 +122,8 @@ subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotc_orig,
122122
logical :: has_large_errors
123123
complex(4) :: cdotc_forward, cdotc_backward ! Function result for FD check
124124
integer :: i, j
125-
complex(4), dimension(n) :: cx
126125
complex(4), dimension(n) :: cy
126+
complex(4), dimension(n) :: cx
127127

128128
max_error = 0.0e0
129129
has_large_errors = .false.
@@ -132,13 +132,13 @@ subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotc_orig,
132132
write(*,*) 'Step size h =', h
133133

134134
! Forward perturbation: f(x + h)
135-
cx = cx_orig + h * cx_d_orig
136135
cy = cy_orig + h * cy_d_orig
136+
cx = cx_orig + h * cx_d_orig
137137
cdotc_forward = cdotc(nsize, cx, 1, cy, 1)
138138

139139
! Backward perturbation: f(x - h)
140-
cx = cx_orig - h * cx_d_orig
141140
cy = cy_orig - h * cy_d_orig
141+
cx = cx_orig - h * cx_d_orig
142142
cdotc_backward = cdotc(nsize, cx, 1, cy, 1)
143143

144144
! Compute central differences and compare with AD results

BLAS/test/test_cdotu.f90

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ subroutine run_test_for_size(n, passed)
4646
integer :: incy
4747

4848
! Derivative variables
49-
complex(4), dimension(n) :: cx_d
50-
complex(4) :: cdotu_d_result ! Derivative of function result (avoid name clash with func_d)
5149
complex(4), dimension(n) :: cy_d
50+
complex(4) :: cdotu_d_result ! Derivative of function result (avoid name clash with func_d)
51+
complex(4), dimension(n) :: cx_d
5252

5353
! Array restoration and derivative storage
54-
complex(4), dimension(n) :: cx_orig, cx_d_orig
55-
complex(4) :: cdotu_orig ! Function result (no _d_orig - use _d_result)
5654
complex(4), dimension(n) :: cy_orig, cy_d_orig
55+
complex(4) :: cdotu_orig ! Function result (no _d_orig - use _d_result)
56+
complex(4), dimension(n) :: cx_orig, cx_d_orig
5757
real(4) :: temp_re, temp_im ! For complex random init
5858
integer :: i, j
5959

@@ -76,41 +76,41 @@ subroutine run_test_for_size(n, passed)
7676
do i = 1, n
7777
call random_number(temp_re)
7878
call random_number(temp_im)
79-
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
79+
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8080
end do
8181
do i = 1, n
8282
call random_number(temp_re)
8383
call random_number(temp_im)
84-
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
84+
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8585
end do
8686

8787
! Store _orig and _d_orig
88-
cx_d_orig = cx_d
8988
cy_d_orig = cy_d
90-
cx_orig = cx
91-
cdotu_orig = cdotu(nsize, cx, 1, cy, 1)
89+
cx_d_orig = cx_d
9290
cy_orig = cy
91+
cdotu_orig = cdotu(nsize, cx, 1, cy, 1)
92+
cx_orig = cx
9393

9494
write(*,*) 'Testing CDOTU (n =', n, ')'
9595

9696
! Call the differentiated function
9797
cdotu_d_result = cdotu_d(nsize, cx, cx_d, 1, cy, cy_d, 1, cdotu_orig)
98-
cx_d = cx_d_orig
9998
cy_d = cy_d_orig
99+
cx_d = cx_d_orig
100100

101101
write(*,*) 'Function calls completed successfully'
102102

103103
! Numerical differentiation check
104-
call check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotu_orig, cx_d_orig, cy_d_orig, cdotu_d_result, passed)
104+
call check_derivatives_numerically(n, nsize, cy_orig, cx_orig, cdotu_orig, cy_d_orig, cx_d_orig, cdotu_d_result, passed)
105105

106106
end subroutine run_test_for_size
107107

108-
subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotu_orig, cx_d_orig, cy_d_orig, cdotu_d_result, passed)
108+
subroutine check_derivatives_numerically(n, nsize, cy_orig, cx_orig, cdotu_orig, cy_d_orig, cx_d_orig, cdotu_d_result, passed)
109109
implicit none
110110
integer, intent(in) :: n
111111
integer, intent(in) :: nsize
112-
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
113112
complex(4), intent(in) :: cy_orig(n), cy_d_orig(n)
113+
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
114114
complex(4), intent(in) :: cdotu_orig
115115
complex(4), intent(in) :: cdotu_d_result
116116
logical, intent(out) :: passed
@@ -122,8 +122,8 @@ subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotu_orig,
122122
logical :: has_large_errors
123123
complex(4) :: cdotu_forward, cdotu_backward ! Function result for FD check
124124
integer :: i, j
125-
complex(4), dimension(n) :: cx
126125
complex(4), dimension(n) :: cy
126+
complex(4), dimension(n) :: cx
127127

128128
max_error = 0.0e0
129129
has_large_errors = .false.
@@ -132,13 +132,13 @@ subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, cdotu_orig,
132132
write(*,*) 'Step size h =', h
133133

134134
! Forward perturbation: f(x + h)
135-
cx = cx_orig + h * cx_d_orig
136135
cy = cy_orig + h * cy_d_orig
136+
cx = cx_orig + h * cx_d_orig
137137
cdotu_forward = cdotu(nsize, cx, 1, cy, 1)
138138

139139
! Backward perturbation: f(x - h)
140-
cx = cx_orig - h * cx_d_orig
141140
cy = cy_orig - h * cy_d_orig
141+
cx = cx_orig - h * cx_d_orig
142142
cdotu_backward = cdotu(nsize, cx, 1, cy, 1)
143143

144144
! Compute central differences and compare with AD results

0 commit comments

Comments
 (0)