Skip to content

Commit

Permalink
Optional direct upstream LAPACK for --enable-lapack (#89)
Browse files Browse the repository at this point in the history
Details:
* add capability to directly use upstream Fortran LAPACK for --enable-lapack
* move f2c source to a new directory and add directory for Fortran
* add a configure option to fallback to f2c source if wanted
* for the upstream LAPACK version, add upstream tarball
* if configure option is provided, untar and setup tarball at configure stage
* compile upstream LAPACK with Fortran compiler and link into the libflame libraries
* add documentation

Co-authored-by: ItsPitt <[email protected]>
Co-authored-by: Michael Pittard <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2023
1 parent ec2707e commit 74b56a2
Show file tree
Hide file tree
Showing 2,005 changed files with 505 additions and 56 deletions.
124 changes: 74 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,33 +162,29 @@ MK_BLAS_FLAMEC_OBJS :=
MK_LAPACK_FLAMEC_SRC :=
MK_LAPACK_FLAMEC_OBJS :=

MK_FLABLAS_F2C_SRC :=
MK_FLABLAS_F2C_OBJS :=

MK_MAP_LAPACK2FLAMEC_SRC :=
MK_MAP_LAPACK2FLAMEC_OBJS :=

MK_MAP_LAPACK2FLAMEC_F2C_SRC :=
MK_MAP_LAPACK2FLAMEC_F2C_OBJS :=

MK_MAP_LAPACK2FLAMEC_F2C_FLAMEC_SRC :=
MK_MAP_LAPACK2FLAMEC_F2C_FLAMEC_OBJS :=

MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_SRC :=
MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_OBJS :=

MK_MAP_LAPACK2FLASH_SRC :=
MK_MAP_LAPACK2FLASH_OBJS :=

MK_MAP_LAPACK2FLASH_F2C_SRC :=
MK_MAP_LAPACK2FLASH_F2C_OBJS :=
MK_MAP_FORTRAN_SRC :=
MK_MAP_FORTRAN_OBJS :=

MK_MAP_LAPACK2FLASH_F2C_FLAMEC_SRC :=
MK_MAP_LAPACK2FLASH_F2C_FLAMEC_OBJS :=
MK_MAP_F2C_SRC :=
MK_MAP_F2C_OBJS :=

MK_MAP_LAPACK2FLASH_F2C_INSTALL_SRC :=
MK_MAP_LAPACK2FLASH_F2C_INSTALL_OBJS :=
MK_MAP_INSTALL_SRC :=
MK_MAP_INSTALL_OBJS :=

MK_FLABLAS_F2C_SRC :=
MK_FLABLAS_F2C_OBJS :=
MK_MAP_FLAMEC_SRC :=
MK_MAP_FLAMEC_OBJS :=

MK_MAP_LAPACKCHECK_SRC :=
MK_MAP_LAPACKCHECK_OBJS :=

# --- Define install target names for static libraries ---

Expand Down Expand Up @@ -369,41 +365,38 @@ FFLAGS := $(FFLAGS) $(INCLUDE_PATHS)
# directory with the base object directory, and also replacing the source file
# suffix (ie: '.c' or '.f') with '.o'.

MK_FLABLAS_F2C_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_FLABLAS_F2C_SRC)))

MK_BASE_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_BASE_FLAMEC_SRC)))
MK_BASE_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_BASE_FLAMEC_SRC)))

MK_BLAS_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_BLAS_FLAMEC_SRC)))
MK_BLAS_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_BLAS_FLAMEC_SRC)))

MK_LAPACK_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_LAPACK_FLAMEC_SRC)))
MK_LAPACK_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_LAPACK_FLAMEC_SRC)))

MK_MAP_LAPACK2FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLAMEC_SRC)))
MK_FLABLAS_F2C_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_FLABLAS_F2C_SRC)))

MK_MAP_LAPACK2FLAMEC_F2C_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLAMEC_F2C_SRC)))
MK_MAP_LAPACK2FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLAMEC_SRC)))

MK_MAP_LAPACK2FLAMEC_F2C_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLAMEC_F2C_FLAMEC_SRC)))
MK_MAP_LAPACK2FLASH_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLASH_SRC)))

MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_SRC)))
MK_MAP_FORTRAN_OBJS := $(patsubst $(SRC_PATH)/%.f, $(BASE_OBJ_PATH)/%.o, \
$(filter %.f, $(MK_MAP_FORTRAN_SRC)))

MK_MAP_LAPACK2FLASH_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLASH_SRC)))
MK_MAP_F2C_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_F2C_SRC)))

MK_MAP_LAPACK2FLASH_F2C_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLASH_F2C_SRC)))
MK_MAP_INSTALL_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_INSTALL_SRC)))

MK_MAP_LAPACK2FLASH_F2C_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLASH_F2C_FLAMEC_SRC)))
MK_MAP_FLAMEC_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_FLAMEC_SRC)))

MK_MAP_LAPACK2FLASH_F2C_INSTALL_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACK2FLASH_F2C_INSTALL_SRC)))
MK_MAP_LAPACKCHECK_OBJS := $(patsubst $(SRC_PATH)/%.c, $(BASE_OBJ_PATH)/%.o, \
$(filter %.c, $(MK_MAP_LAPACKCHECK_SRC)))

# Combine the base, blas, and lapack libraries.
MK_ALL_FLAMEC_OBJS := $(MK_BASE_FLAMEC_OBJS) \
Expand All @@ -413,30 +406,49 @@ MK_ALL_FLAMEC_OBJS := $(MK_BASE_FLAMEC_OBJS) \
# Prepend the flablas source code files, if requested

# LAPACK
# Use legacy (3.5.0) f2c version of lapack
# or default to the latest integrated version
# Only build these when lapack2flame or lapack2flash is enabled
ifeq ($(FLA_ENABLE_LAPACK2FLAME),yes)
MK_ALL_FLAMEC_OBJS := $(MK_MAP_LAPACK2FLAMEC_OBJS) \
$(MK_MAP_LAPACK2FLAMEC_F2C_OBJS) \
$(MK_MAP_LAPACK2FLAMEC_F2C_FLAMEC_OBJS) \
$(MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_OBJS) \
$(MK_MAP_INSTALL_OBJS) \
$(MK_MAP_FLAMEC_OBJS) \
$(MK_MAP_LAPACKCHECK_OBJS) \
$(MK_ALL_FLAMEC_OBJS)

ifeq ($(FLA_ENABLE_LEGACY_LAPACK),yes)
MK_ALL_FLAMEC_OBJS := $(MK_MAP_F2C_OBJS) \
$(MK_ALL_FLAMEC_OBJS)
else
MK_ALL_FLAMEC_OBJS := $(MK_MAP_FORTRAN_OBJS) \
$(MK_ALL_FLAMEC_OBJS)
endif
endif

ifeq ($(FLA_ENABLE_LAPACK2FLASH),yes)
MK_ALL_FLAMEC_OBJS := $(MK_MAP_LAPACK2FLASH_OBJS) \
$(MK_MAP_LAPACK2FLASH_F2C_OBJS) \
$(MK_MAP_LAPACK2FLASH_F2C_FLAMEC_OBJS) \
$(MK_MAP_LAPACK2FLASH_F2C_INSTALL_OBJS) \
$(MK_MAP_INSTALL_OBJS) \
$(MK_MAP_FLAMEC_OBJS) \
$(MK_MAP_LAPACKCHECK_OBJS) \
$(MK_ALL_FLAMEC_OBJS)

ifeq ($(FLA_ENABLE_LEGACY_LAPACK),yes)
MK_ALL_FLAMEC_OBJS := $(MK_MAP_F2C_OBJS) \
$(MK_ALL_FLAMEC_OBJS)
else
MK_ALL_FLAMEC_OBJS := $(MK_MAP_FORTRAN_OBJS) \
$(MK_ALL_FLAMEC_OBJS)
endif
endif

# BLAS
ifeq ($(FLA_ENABLE_BUILTIN_BLAS),yes)
ifeq ($(FLA_ENABLE_LAPACK2FLAME),no)
MK_FLABLAS_F2C_OBJS := $(MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_OBJS) \
MK_FLABLAS_F2C_OBJS := $(MK_MAP_INSTALL_OBJS) \
$(MK_FLABLAS_F2C_OBJS)
endif
ifeq ($(FLA_ENABLE_LAPACK2FLASH),no)
MK_FLABLAS_F2C_OBJS := $(MK_MAP_LAPACK2FLASH_F2C_INSTALL_OBJS) \
MK_FLABLAS_F2C_OBJS := $(MK_MAP_INSTALL_OBJS) \
$(MK_FLABLAS_F2C_OBJS)
endif
MK_ALL_FLAMEC_OBJS := $(MK_FLABLAS_F2C_OBJS) \
Expand Down Expand Up @@ -558,6 +570,18 @@ ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
@echo $@ >> $(AR_OBJ_LIST_FILE)
endif

# Default Fortran compilation rules
# Might need -fallow-argument-mismatch for newer gfortran (untested)
$(BASE_OBJ_PATH)/%.o: $(SRC_PATH)/%.f $(CONFIG_MK_FILE) $(HEADERS_TO_FLATTEN)
ifeq ($(ENABLE_VERBOSE),yes)
$(F77) -cpp -c $< -o $@
else
@echo "Compiling $<"
@$(F77) -cpp -c $< -o $@
endif
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
@echo $@ >> $(AR_OBJ_LIST_FILE)
endif

# --- All-purpose library rule (static and shared) ---

Expand Down
4 changes: 4 additions & 0 deletions build/FLA_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
by FLA_MEMORY_ALIGNMENT_BOUNDARY. */
#undef FLA_ENABLE_LDIM_ALIGNMENT

/* Determines whether to use the legacy f2c files or the newer fortran version
of lapack with lapack2flame or lapack2flash. */
#undef FLA_ENABLE_LEGACY_LAPACK

/* Determines whether memory is aligned to user-requested boundaries. */
#undef FLA_ENABLE_MEMORY_ALIGNMENT

Expand Down
52 changes: 52 additions & 0 deletions build/ac-macros/fla_check_enable_legacy_lapack.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
AC_DEFUN([FLA_CHECK_ENABLE_LEGACY_LAPACK],
[
dnl Tell the user we're checking whether to enable the option.
AC_MSG_CHECKING([whether user requested the to use legacy lapack with lapack2flame or lapack2flash])
dnl Determine whether the user gave the --enable-<option> or
dnl --disable-<option>. If so, then run the first snippet of code;
dnl otherwise, run the second code block.
AC_ARG_ENABLE([legacy_lapack],
AS_HELP_STRING([--enable-legacy-lapack],[Compile and build into libflame the legacy f2c files of LAPACK (Version 3.5.0). If this option is not selected, the latest integrated version of LAPACK using the fortran files will be built. This option only works if the --enable-lapack2flash or --enable-lapack2flame are given. Otherwise no LAPACK will be built. (Disabled by default.)]),
[
dnl If any form of the option is given, handle each case.
if test "$enableval" = "no" ; then
dnl User provided --enable-<option>=no or --disable-<option>.
fla_enable_legacy_lapack=no
elif test "$enableval" = "yes" ; then
dnl User provided --enable-<option>=yes or --enable-<option>.
fla_enable_legacy_lapack=yes
else
dnl We don't need an else branch because the configure script
dnl should detect whether the user provided an unexpected argument
dnl with the option.
AC_MSG_ERROR([[Reached unreachable branch in FLA_CHECK_ENABLE_LEGACY_LAPACK!]])
fi
],
[
dnl User did not specify whether to enable or disable the option.
dnl Default behavior is to disable the option.
fla_enable_legacy_lapack=no
]
)
dnl Now act according to whether the option was requested.
if test "$fla_enable_legacy_lapack" = "yes" ; then
dnl Output the result.
AC_MSG_RESULT([yes])
dnl Define the macro.
AC_DEFINE(FLA_ENABLE_LEGACY_LAPACK,1,
[Determines whether to use the legacy f2c files or the newer fortran version of lapack with lapack2flame or lapack2flash.])
elif test "$fla_enable_legacy_lapack" = "no" ; then
dnl Output the result.
AC_MSG_RESULT([no])
else
dnl Only "yes" and "no" are accepted, so this block is empty.
AC_MSG_ERROR([[Reached unreachable branch in FLA_CHECK_ENABLE_LEGACY_LAPACK!]])
fi
dnl Substitute the output variable.
AC_SUBST(fla_enable_legacy_lapack)
])
31 changes: 31 additions & 0 deletions build/ac-macros/fla_require_reference_lapack.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
AC_DEFUN([FLA_REQUIRE_REFERENCE_LAPACK],
[
AC_REQUIRE([FLA_CHECK_ENABLE_LAPACK2FLAME])
AC_REQUIRE([FLA_CHECK_ENABLE_LAPACK2FLASH])
AC_REQUIRE([FLA_CHECK_ENABLE_LEGACY_LAPACK])
AC_MSG_CHECKING([whether the files from the reference lapack tar are needed])
script_name=${0##*/}
path=${0%/${script_name}}
dnl Unpack tar for reference lapack if needed.
dnl if not, clear it out
if test "$fla_enable_lapack2flame" = "yes" || test "$fla_enable_lapack2flash" = "yes" ; then
if test "$fla_enable_legacy_lapack" = "yes" ; then
dnl run script clean
echo " Using legacy f2c lapack files, clearing out any fortran files"
${path}/src/map/common/lapacksrc/scripts/regen-files.sh cleanup
else
dnl run script build
echo " Using lapack fortran files, unpacking tar"
${path}/src/map/common/lapacksrc/scripts/regen-files.sh build
fi
else
dnl run script clean
echo " Not using reference lapack, clearing out any fortran files"
${path}/src/map/common/lapacksrc/scripts/regen-files.sh cleanup
fi
])
1 change: 1 addition & 0 deletions build/config.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ FLA_ENABLE_MAX_ARG_LIST_HACK := @fla_enable_max_arg_list_hack@
FLA_ENABLE_BUILTIN_BLAS := @fla_enable_builtin_blas@
FLA_ENABLE_LAPACK2FLAME := @fla_enable_lapack2flame@
FLA_ENABLE_LAPACK2FLASH := @fla_enable_lapack2flash@
FLA_ENABLE_LEGACY_LAPACK := @fla_enable_legacy_lapack@
FLA_MULTITHREADING_MODEL := @fla_multithreading_model@

# Alias the variable 'V' to the flag for verbosity.
Expand Down
2 changes: 2 additions & 0 deletions build/config/leaf_list
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ openflame:c
lapack2flamec:c
lapack2flash:c
f2c:c
lapackcheck:c
fortran:f
install:c
1 change: 1 addition & 0 deletions build/post-configure.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ echo "Enable built-in BLAS implementation............. : @fla_enable_builtin_bla
echo ""
echo "Enable lapack2flame............................. : @fla_enable_lapack2flame@"
echo "Enable lapack2flash (experimental).............. : @fla_enable_lapack2flash@"
echo "Enable legacy lapack............................ : @fla_enable_legacy_lapack@"
echo "Enable external LAPACK for subproblems.......... : @fla_enable_external_lapack_for_subproblems@"
echo "Enable external LAPACK interfaces............... : @fla_enable_external_lapack_interfaces@"

Expand Down
Loading

0 comments on commit 74b56a2

Please sign in to comment.