Skip to content

Commit

Permalink
Use f2c translations of LAPACK when no Fortran compiler is available (O…
Browse files Browse the repository at this point in the history
…penMathLib#3539)

* Add C equivalents of the Fortran routines from Reference-LAPACK as fallbacks, and C_LAPACK variable to trigger their use
  • Loading branch information
martin-frbg authored and ioraff committed May 12, 2022
1 parent 3d4b6fa commit 4238951
Show file tree
Hide file tree
Showing 2,130 changed files with 1,872,454 additions and 33 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ option(BUILD_WITHOUT_LAPACK "Do not build LAPACK and LAPACKE (Only BLAS or CBLAS

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

option(C_LAPACK "Build LAPACK from C sources instead of the original Fortran" OFF)

option(BUILD_WITHOUT_CBLAS "Do not build the C interface (CBLAS) to the BLAS functions" OFF)

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

# 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.
# Not using add_subdirectory here because lapack-netlib already has its own CMakeLists.txt. Instead include a cmake script with the sources we want.
if (NOT NOFORTRAN AND NOT NO_LAPACK)
if (NOT NO_LAPACK)
include("${PROJECT_SOURCE_DIR}/cmake/lapack.cmake")
if (NOT NO_LAPACKE)
include("${PROJECT_SOURCE_DIR}/cmake/lapacke.cmake")
Expand Down
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ ifeq ($(NO_FORTRAN), 1)
define NOFORTRAN
1
endef
define NO_LAPACK
ifneq ($(NO_LAPACK), 1)
define C_LAPACK
1
endef
endif
export NOFORTRAN
export NO_LAPACK
export C_LAPACK
endif

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

ifeq ($(NO_LAPACK), 1)
netlib :

else
netlib : lapack_prebuild
ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN)))
ifneq ($(NO_LAPACK), 1)
@$(MAKE) -C $(NETLIB_LAPACK_DIR) lapacklib
@$(MAKE) -C $(NETLIB_LAPACK_DIR) tmglib
endif
ifneq ($(NO_LAPACKE), 1)
@$(MAKE) -C $(NETLIB_LAPACK_DIR) lapackelib
endif
endif

ifeq ($(NO_LAPACK), 1)
re_lapack :
Expand All @@ -267,7 +265,7 @@ prof_lapack : lapack_prebuild
@$(MAKE) -C $(NETLIB_LAPACK_DIR) lapack_prof

lapack_prebuild :
ifeq ($(NOFORTRAN), $(filter 0,$(NOFORTRAN)))
ifeq ($(NO_LAPACK), $(filter 0,$(NO_LAPACK)))
-@echo "FC = $(FC)" > $(NETLIB_LAPACK_DIR)/make.inc
-@echo "override FFLAGS = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
-@echo "FFLAGS_DRV = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
Expand Down
7 changes: 6 additions & 1 deletion Makefile.system
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ OBJCONV = $(CROSS_SUFFIX)objconv

# When fortran support was either not detected or actively deselected, only build BLAS.
ifeq ($(NOFORTRAN), 1)
NO_LAPACK = 1
C_LAPACK = 1
override FEXTRALIB =
endif

Expand Down Expand Up @@ -1303,6 +1303,10 @@ ifeq ($(DYNAMIC_OLDER), 1)
CCOMMON_OPT += -DDYNAMIC_OLDER
endif

ifeq ($(C_LAPACK), 1)
CCOMMON_OPT += -DC_LAPACK
endif

ifeq ($(NO_LAPACK), 1)
CCOMMON_OPT += -DNO_LAPACK
#Disable LAPACK C interface
Expand Down Expand Up @@ -1661,6 +1665,7 @@ export USE_OPENMP
export CROSS
export CROSS_SUFFIX
export NOFORTRAN
export C_LAPACK
export NO_FBLAS
export EXTRALIB
export CEXTRALIB
Expand Down
14 changes: 11 additions & 3 deletions cmake/f_check.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
enable_language(Fortran)
else()
set (NOFORTRAN 1)
if (NOT NO_LAPACK)
message(STATUS "No Fortran compiler found, can build only BLAS but not LAPACK")
if (NOT MSVC)
message(STATUS "No Fortran compiler found, can build only BLAS and f2c-converted LAPACK")
set(C_LAPACK 1)
if (INTERFACE64)
set (CCOMMON_OPT "${CCOMMON_OPT} -DLAPACK_ILP64")
endif ()
set(TIMER "NONE")
else ()
message(STATUS "No Fortran compiler found, can build only BLAS")
endif()
endif()
set (NOFORTRAN 1)
set (NO_LAPACK 1)
endif()

if (NOT ONLY_CBLAS)
Expand Down
Loading

0 comments on commit 4238951

Please sign in to comment.