Skip to content

Commit b1d64b9

Browse files
authored
Merge branch 'fortran-lang:master' into activations
2 parents c62110d + 875d94d commit b1d64b9

14 files changed

+310
-42
lines changed

.github/workflows/CI.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,24 @@ jobs:
6161
compiler: ${{ matrix.toolchain.compiler }}
6262
version: ${{ matrix.toolchain.version }}
6363

64+
# Build and test with built-in BLAS and LAPACK
6465
- name: Configure with CMake
6566
if: ${{ contains(matrix.build, 'cmake') }}
6667
run: >-
6768
cmake -Wdev -G Ninja
6869
-DCMAKE_BUILD_TYPE=Release
6970
-DCMAKE_MAXIMUM_RANK:String=4
7071
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
72+
-DFIND_BLAS:STRING=FALSE
7173
-S . -B ${{ env.BUILD_DIR }}
7274
7375
- name: Build and compile
7476
if: ${{ contains(matrix.build, 'cmake') }}
7577
run: cmake --build ${{ env.BUILD_DIR }} --parallel
7678

7779
- name: catch build fail
78-
run: cmake --build ${{ env.BUILD_DIR }} --verbose --parallel 1
7980
if: ${{ failure() && contains(matrix.build, 'cmake') }}
81+
run: cmake --build ${{ env.BUILD_DIR }} --verbose --parallel 1
8082

8183
- name: test
8284
if: ${{ contains(matrix.build, 'cmake') }}

.github/workflows/ci_BLAS.yml

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: CI_BLAS
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
CTEST_TIME_TIMEOUT: "5" # some failures hang forever
7+
CMAKE_GENERATOR: Ninja
8+
9+
jobs:
10+
msys2-build:
11+
runs-on: windows-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include: [{ msystem: UCRT64, arch: x86_64 }]
16+
defaults:
17+
run:
18+
shell: msys2 {0}
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Setup MinGW native environment
23+
uses: msys2/setup-msys2@v2
24+
with:
25+
msystem: ${{ matrix.msystem }}
26+
update: false
27+
install: >-
28+
git
29+
mingw-w64-ucrt-${{ matrix.arch }}-gcc
30+
mingw-w64-ucrt-${{ matrix.arch }}-gcc-fortran
31+
mingw-w64-ucrt-${{ matrix.arch }}-python
32+
mingw-w64-ucrt-${{ matrix.arch }}-python-fypp
33+
mingw-w64-ucrt-${{ matrix.arch }}-cmake
34+
mingw-w64-ucrt-${{ matrix.arch }}-ninja
35+
mingw-w64-ucrt-${{ matrix.arch }}-openblas
36+
37+
# Build and test with external BLAS and LAPACK (OpenBLAS on UCRT64)
38+
- name: Configure with CMake and OpenBLAS
39+
run: >-
40+
PATH=$PATH:/ucrt64/bin/ cmake
41+
-Wdev
42+
-B build
43+
-DCMAKE_BUILD_TYPE=Debug
44+
-DCMAKE_Fortran_FLAGS_DEBUG="-Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all -fbacktrace"
45+
-DCMAKE_MAXIMUM_RANK:String=4
46+
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
47+
-DFIND_BLAS:STRING=TRUE
48+
env:
49+
FC: gfortran
50+
CC: gcc
51+
CXX: g++
52+
53+
- name: CMake build with OpenBLAS
54+
run: PATH=$PATH:/ucrt64/bin/ cmake --build build --parallel
55+
56+
- name: catch build fail
57+
if: failure()
58+
run: PATH=$PATH:/ucrt64/bin/ cmake --build build --verbose --parallel 1
59+
60+
- name: CTest with OpenBLAS
61+
run: PATH=$PATH:/ucrt64/bin/ ctest --test-dir build --output-on-failure --parallel -V -LE quadruple_precision
62+
63+
- uses: actions/upload-artifact@v4
64+
if: failure()
65+
with:
66+
name: WindowsCMakeTestlog_openblas
67+
path: build/Testing/Temporary/LastTest.log
68+
69+
- name: Install project with OpenBLAS
70+
run: PATH=$PATH:/ucrt64/bin/ cmake --install build
71+
72+
Build:
73+
runs-on: ubuntu-latest
74+
strategy:
75+
fail-fast: false
76+
matrix:
77+
toolchain:
78+
- { compiler: intel, version: "2024.1" }
79+
build: [cmake]
80+
env:
81+
BUILD_DIR: ${{ matrix.build == 'cmake' && 'build' || '.' }}
82+
APT_PACKAGES: >-
83+
intel-oneapi-mkl
84+
intel-oneapi-mkl-devel
85+
steps:
86+
- name: Checkout code
87+
uses: actions/checkout@v4
88+
89+
- name: Set up Python 3.x
90+
uses: actions/setup-python@v5 # Use pip to install latest CMake, & FORD/Jin2For, etc.
91+
with:
92+
python-version: 3.x
93+
94+
- name: Install fypp
95+
run: pip install --upgrade fypp ninja
96+
97+
- name: Setup Fortran compiler
98+
uses: fortran-lang/[email protected]
99+
id: setup-fortran
100+
with:
101+
compiler: ${{ matrix.toolchain.compiler }}
102+
version: ${{ matrix.toolchain.version }}
103+
104+
- name: Install Intel oneAPI MKL
105+
run: |
106+
sudo apt-get install ${APT_PACKAGES}
107+
source /opt/intel/oneapi/mkl/latest/env/vars.sh
108+
printenv >> $GITHUB_ENV
109+
110+
# Build and test with external BLAS and LAPACK (MKL on Ubuntu with Intel compilers)
111+
- name: Configure with CMake and MKL
112+
run: >-
113+
cmake -Wdev -G Ninja
114+
-DCMAKE_BUILD_TYPE=Release
115+
-DCMAKE_MAXIMUM_RANK:String=4
116+
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
117+
-DFIND_BLAS:STRING=TRUE
118+
-S . -B ${{ env.BUILD_DIR }}
119+
120+
- name: Build and compile with MKL
121+
run: cmake --build ${{ env.BUILD_DIR }} --parallel
122+
123+
- name: catch build fail with MKL
124+
if: failure()
125+
run: cmake --build ${{ env.BUILD_DIR }} --verbose --parallel 1
126+
127+
- name: test with MKL
128+
run: >-
129+
ctest
130+
--test-dir ${{ env.BUILD_DIR }}
131+
--parallel
132+
--output-on-failure
133+
--no-tests=error
134+
135+
- name: Install project with MKL
136+
run: cmake --install ${{ env.BUILD_DIR }}

.github/workflows/ci_windows.yml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
-DCMAKE_Fortran_FLAGS_DEBUG="-Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all -fbacktrace"
4444
-DCMAKE_MAXIMUM_RANK:String=4
4545
-DCMAKE_INSTALL_PREFIX=$PWD/_dist
46+
-DFIND_BLAS:STRING=FALSE
4647
env:
4748
FC: gfortran
4849
CC: gcc

CMakeLists.txt

+52
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,58 @@ if(NOT DEFINED CMAKE_MAXIMUM_RANK)
4242
set(CMAKE_MAXIMUM_RANK 4 CACHE STRING "Maximum array rank for generated procedures")
4343
endif()
4444

45+
option(FIND_BLAS "Find external BLAS and LAPACK" ON)
46+
47+
# --- find external BLAS and LAPACK
48+
if(FIND_BLAS)
49+
50+
message(STATUS "Searching for external BLAS/LAPACK")
51+
52+
# Common MKL setup
53+
if(DEFINED ENV{MKLROOT} OR "${BLA_VENDOR}" MATCHES "^(Intel|Intel10_64)")
54+
enable_language("C")
55+
message(STATUS "Detected Intel MKL environment")
56+
endif()
57+
58+
find_package(BLAS)
59+
find_package(LAPACK)
60+
61+
if(BLAS_FOUND AND LAPACK_FOUND)
62+
message(STATUS "Found external BLAS: ${BLAS_LIBRARIES}")
63+
message(STATUS "Found external LAPACK: ${LAPACK_LIBRARIES}")
64+
65+
# Detect ILP64 (common function)
66+
function(detect_ilp64 lib_name)
67+
set(${lib_name}_ILP64 False PARENT_SCOPE)
68+
# Prefer checking BLA_SIZEOF_INTEGER (available in CMake >= 3.22)
69+
if(DEFINED BLA_SIZEOF_INTEGER AND BLA_SIZEOF_INTEGER EQUAL 8)
70+
set(${lib_name}_ILP64 True PARENT_SCOPE)
71+
# Fallback: Check BLA_VENDOR manually for signs of ILP64
72+
elseif("${BLA_VENDOR}" MATCHES ".*(_ilp|ILP64).*")
73+
set(${lib_name}_ILP64 True PARENT_SCOPE)
74+
endif()
75+
endfunction()
76+
77+
detect_ilp64(BLAS)
78+
detect_ilp64(LAPACK)
79+
80+
# Set compile definitions
81+
if(BLAS_ILP64 OR LAPACK_ILP64)
82+
message(STATUS "Enabling 64-bit integer support (ILP64)")
83+
add_compile_definitions(STDLIB_EXTERNAL_BLAS_I64 STDLIB_EXTERNAL_LAPACK_I64)
84+
set(WITH_ILP64 True CACHE BOOL "Use 64-bit integer BLAS/LAPACK" FORCE)
85+
else()
86+
message(STATUS "Using standard 32-bit integer interface")
87+
add_compile_definitions(STDLIB_EXTERNAL_BLAS STDLIB_EXTERNAL_LAPACK)
88+
endif()
89+
90+
else()
91+
message(WARNING "External BLAS/LAPACK not found - "
92+
"Using built-in reference BLAS")
93+
endif()
94+
95+
endif()
96+
4597
# --- find preprocessor
4698
find_program(FYPP fypp)
4799
if(NOT FYPP)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Important options are
135135
- `-DBUILD_TESTING` set to `off` in case you want to disable the stdlib tests (default: `on`).
136136
- `-DCMAKE_VERBOSE_MAKEFILE` is by default set to `Off`, but if set to `On` will show commands used to compile the code.
137137
- `-DCMAKE_BUILD_TYPE` is by default set to `RelWithDebInfo`, which uses compiler flags suitable for code development (but with only `-O2` optimization). Beware the compiler flags set this way will override any compiler flags specified via `FFLAGS`. To prevent this, use `-DCMAKE_BUILD_TYPE=NoConfig` in conjunction with `FFLAGS`.
138+
- `-DFIND_BLAS` set to `off` in case you want to disable finding the external BLAS/LAPACK dependency (default: `on`).
138139

139140
For example, to configure a build using the Ninja backend while specifying compiler optimization via `FFLAGS`, generating procedures up to rank 7, installing to your home directory, using the `NoConfig` compiler flags, and printing the compiler commands, use
140141

config/fypp_deployment.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,8 @@
66
C_PREPROCESSED = (
77
"stdlib_linalg_constants" ,
88
"stdlib_linalg_blas" ,
9-
"stdlib_linalg_blas_aux",
10-
"stdlib_linalg_blas_s",
11-
"stdlib_linalg_blas_d",
12-
"stdlib_linalg_blas_q",
13-
"stdlib_linalg_blas_c",
14-
"stdlib_linalg_blas_z",
15-
"stdlib_linalg_blas_w",
169
"stdlib_linalg_lapack",
17-
"stdlib_linalg_lapack_aux",
18-
"stdlib_linalg_lapack_s",
19-
"stdlib_linalg_lapack_d",
20-
"stdlib_linalg_lapack_q",
21-
"stdlib_linalg_lapack_c",
22-
"stdlib_linalg_lapack_z",
23-
"stdlib_linalg_lapack_w"
10+
"test_blas_lapack"
2411
)
2512

2613
def pre_process_fypp(args):
@@ -105,7 +92,7 @@ def recursive_copy(folder):
10592
for root, _, files in os.walk(folder):
10693
for file in files:
10794
if file not in prune:
108-
if file.endswith((".f90", ".F90", ".dat", ".npy", ".c")):
95+
if file.endswith((".f90", ".F90", ".dat", ".npy", ".c", ".h")):
10996
shutil.copy2(os.path.join(root, file), base_folder+os.sep+folder+os.sep+file)
11097
recursive_copy('src')
11198
recursive_copy('test')

src/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ set(SRC
127127

128128
add_library(${PROJECT_NAME} ${SRC})
129129

130+
# Link to BLAS and LAPACK
131+
if(BLAS_FOUND AND LAPACK_FOUND)
132+
target_link_libraries(${PROJECT_NAME} "BLAS::BLAS")
133+
target_link_libraries(${PROJECT_NAME} "LAPACK::LAPACK")
134+
endif()
135+
130136
set_target_properties(
131137
${PROJECT_NAME}
132138
PROPERTIES

src/blas/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ set(dir "${CMAKE_CURRENT_SOURCE_DIR}")
44

55
list(APPEND fppFiles
66
blas/stdlib_blas_constants.fypp
7-
)
8-
9-
list(APPEND cppFiles
107
blas/stdlib_blas.fypp
118
blas/stdlib_blas_level1.fypp
129
blas/stdlib_blas_level2_ban.fypp
@@ -21,4 +18,3 @@ list(APPEND cppFiles
2118
)
2219

2320
set(fppFiles "${fppFiles}" PARENT_SCOPE)
24-
set(cppFiles "${cppFiles}" PARENT_SCOPE)

src/lapack/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
list(APPEND cppFiles
1+
list(APPEND fppFiles
22
lapack/stdlib_lapack_base.fypp
33
lapack/stdlib_lapack_solve.fypp
44
lapack/stdlib_lapack_others.fypp
@@ -55,4 +55,4 @@ list(APPEND cppFiles
5555
lapack/stdlib_lapack_svd_comp2.fypp
5656
)
5757

58-
set(cppFiles "${cppFiles}" PARENT_SCOPE)
58+
set(fppFiles "${fppFiles}" PARENT_SCOPE)

test/CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ macro(ADDTEST name)
1010
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
1111
endmacro(ADDTEST)
1212

13+
macro(ADDTESTPP name)
14+
add_executable(test_${name} test_${name}.F90)
15+
target_link_libraries(test_${name} "${PROJECT_NAME}" "test-drive::test-drive")
16+
add_test(NAME ${name}
17+
COMMAND $<TARGET_FILE:test_${name}> ${CMAKE_CURRENT_BINARY_DIR}
18+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
19+
endmacro(ADDTESTPP)
20+
21+
1322
add_subdirectory(array)
1423
add_subdirectory(ascii)
1524
add_subdirectory(bitsets)
@@ -31,4 +40,4 @@ add_subdirectory(system)
3140
add_subdirectory(quadrature)
3241
add_subdirectory(math)
3342
add_subdirectory(stringlist)
34-
add_subdirectory(terminal)
43+
add_subdirectory(terminal)

test/linalg/CMakeLists.txt

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
set(
22
fppFiles
33
"test_linalg.fypp"
4-
"test_blas_lapack.fypp"
5-
"test_linalg_cholesky.fypp"
64
"test_linalg_eigenvalues.fypp"
75
"test_linalg_solve.fypp"
86
"test_linalg_inverse.fypp"
@@ -16,8 +14,17 @@ set(
1614
"test_linalg_svd.fypp"
1715
"test_linalg_matrix_property_checks.fypp"
1816
"test_linalg_sparse.fypp"
17+
"test_linalg_cholesky.fypp"
18+
)
19+
20+
# Preprocessed files to contain preprocessor directives -> .F90
21+
set(
22+
cppFiles
23+
"test_blas_lapack.fypp"
1924
)
25+
2026
fypp_f90("${fyppFlags}" "${fppFiles}" outFiles)
27+
fypp_f90pp("${fyppFlags}" "${cppFiles}" outPreprocFiles)
2128

2229
ADDTEST(linalg)
2330
ADDTEST(linalg_cholesky)
@@ -33,5 +40,5 @@ ADDTEST(linalg_lstsq)
3340
ADDTEST(linalg_qr)
3441
ADDTEST(linalg_schur)
3542
ADDTEST(linalg_svd)
36-
ADDTEST(blas_lapack)
3743
ADDTEST(linalg_sparse)
44+
ADDTESTPP(blas_lapack)

0 commit comments

Comments
 (0)