Skip to content

Commit b787360

Browse files
authored
Use f2c translations of LAPACK when no Fortran compiler is available (#3539)
* Add C equivalents of the Fortran routines from Reference-LAPACK as fallbacks, and C_LAPACK variable to trigger their use
1 parent 2edcd9b commit b787360

File tree

2,130 files changed

+1872454
-33
lines changed

Some content is hidden

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

2,130 files changed

+1872454
-33
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ option(BUILD_WITHOUT_LAPACK "Do not build LAPACK and LAPACKE (Only BLAS or CBLAS
2222

2323
option(BUILD_TESTING "Build LAPACK testsuite when building LAPACK" ON)
2424

25+
option(C_LAPACK "Build LAPACK from C sources instead of the original Fortran" OFF)
26+
2527
option(BUILD_WITHOUT_CBLAS "Do not build the C interface (CBLAS) to the BLAS functions" OFF)
2628

2729
option(DYNAMIC_ARCH "Include support for multiple CPU targets, with automatic selection at runtime (x86/x86_64, aarch64 or ppc only)" OFF)
@@ -175,7 +177,7 @@ endforeach ()
175177

176178
# Can't just use lapack-netlib's CMake files, since they are set up to search for BLAS, build and install a binary. We just want to build a couple of lib files out of lapack and lapacke.
177179
# Not using add_subdirectory here because lapack-netlib already has its own CMakeLists.txt. Instead include a cmake script with the sources we want.
178-
if (NOT NOFORTRAN AND NOT NO_LAPACK)
180+
if (NOT NO_LAPACK)
179181
include("${PROJECT_SOURCE_DIR}/cmake/lapack.cmake")
180182
if (NOT NO_LAPACKE)
181183
include("${PROJECT_SOURCE_DIR}/cmake/lapacke.cmake")

Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ ifeq ($(NO_FORTRAN), 1)
2525
define NOFORTRAN
2626
1
2727
endef
28-
define NO_LAPACK
28+
ifneq ($(NO_LAPACK), 1)
29+
define C_LAPACK
2930
1
3031
endef
32+
endif
3133
export NOFORTRAN
3234
export NO_LAPACK
35+
export C_LAPACK
3336
endif
3437

3538
LAPACK_NOOPT := $(filter-out -O0 -O1 -O2 -O3 -Ofast -O -Og -Os,$(LAPACK_FFLAGS))
@@ -241,19 +244,14 @@ hpl_p :
241244
fi; \
242245
done
243246

244-
ifeq ($(NO_LAPACK), 1)
245-
netlib :
246-
247-
else
248247
netlib : lapack_prebuild
249-
ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN)))
248+
ifneq ($(NO_LAPACK), 1)
250249
@$(MAKE) -C $(NETLIB_LAPACK_DIR) lapacklib
251250
@$(MAKE) -C $(NETLIB_LAPACK_DIR) tmglib
252251
endif
253252
ifneq ($(NO_LAPACKE), 1)
254253
@$(MAKE) -C $(NETLIB_LAPACK_DIR) lapackelib
255254
endif
256-
endif
257255

258256
ifeq ($(NO_LAPACK), 1)
259257
re_lapack :
@@ -267,7 +265,7 @@ prof_lapack : lapack_prebuild
267265
@$(MAKE) -C $(NETLIB_LAPACK_DIR) lapack_prof
268266

269267
lapack_prebuild :
270-
ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN)))
268+
ifeq ($(NO_LAPACK), $(filter 0,$(NO_LAPACK)))
271269
-@echo "FC = $(FC)" > $(NETLIB_LAPACK_DIR)/make.inc
272270
-@echo "override FFLAGS = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
273271
-@echo "FFLAGS_DRV = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc

Makefile.system

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ OBJCONV = $(CROSS_SUFFIX)objconv
352352

353353
# When fortran support was either not detected or actively deselected, only build BLAS.
354354
ifeq ($(NOFORTRAN), 1)
355-
NO_LAPACK = 1
355+
C_LAPACK = 1
356356
override FEXTRALIB =
357357
endif
358358

@@ -1303,6 +1303,10 @@ ifeq ($(DYNAMIC_OLDER), 1)
13031303
CCOMMON_OPT += -DDYNAMIC_OLDER
13041304
endif
13051305

1306+
ifeq ($(C_LAPACK), 1)
1307+
CCOMMON_OPT += -DC_LAPACK
1308+
endif
1309+
13061310
ifeq ($(NO_LAPACK), 1)
13071311
CCOMMON_OPT += -DNO_LAPACK
13081312
#Disable LAPACK C interface
@@ -1661,6 +1665,7 @@ export USE_OPENMP
16611665
export CROSS
16621666
export CROSS_SUFFIX
16631667
export NOFORTRAN
1668+
export C_LAPACK
16641669
export NO_FBLAS
16651670
export EXTRALIB
16661671
export CEXTRALIB

cmake/f_check.cmake

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ check_language(Fortran)
2525
if(CMAKE_Fortran_COMPILER)
2626
enable_language(Fortran)
2727
else()
28+
set (NOFORTRAN 1)
2829
if (NOT NO_LAPACK)
29-
message(STATUS "No Fortran compiler found, can build only BLAS but not LAPACK")
30+
if (NOT MSVC)
31+
message(STATUS "No Fortran compiler found, can build only BLAS and f2c-converted LAPACK")
32+
set(C_LAPACK 1)
33+
if (INTERFACE64)
34+
set (CCOMMON_OPT "${CCOMMON_OPT} -DLAPACK_ILP64")
35+
endif ()
36+
set(TIMER "NONE")
37+
else ()
38+
message(STATUS "No Fortran compiler found, can build only BLAS")
39+
endif()
3040
endif()
31-
set (NOFORTRAN 1)
32-
set (NO_LAPACK 1)
3341
endif()
3442

3543
if (NOT ONLY_CBLAS)

0 commit comments

Comments
 (0)