From 7fb824a5744fcd9ed8012d5e7ef1df230489ff5d Mon Sep 17 00:00:00 2001
From: "Mulas, Giacomo" <gmulas@oa-cagliari.inaf.it>
Date: Thu, 23 Jan 2025 10:51:51 +0100
Subject: [PATCH] add support for alternative magma inversion routines and fix
 more than one debug option

---
 build/configure.sh | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/build/configure.sh b/build/configure.sh
index d079c125..4e2b9a40 100755
--- a/build/configure.sh
+++ b/build/configure.sh
@@ -16,6 +16,7 @@ LAPACK="auto"
 LDFLAGS=""
 LIBMODE="static"
 MAGMA="auto"
+MAGMA_INVERT_FLAGS=""
 NVTXFLAGS=""
 OMPMODE="auto"
 OFFLOAD="auto"
@@ -98,6 +99,7 @@ function print_help {
     echo "                          than once).                                     "
     echo "--with-magma=[MAGMA]      Use specified MAGMA distribution (DEFAULT).     "
     echo "--without-magma           Disable MAGMA.                                  "
+    echo "--enable-magma-invert=OPTION      Use specified MAGMA matrix inversion function (options = auto|getri|gesv|rbt, default getri).     "
     echo "                                                                          "
     echo "Some influential environment variables are:                               "
     echo "                                                                          "
@@ -162,7 +164,7 @@ do
 	    if [ "x$DEBUGFLAGS" = "x" ]; then
 		DEBUGFLAGS=" -DDEBUG_${dbg_feature}"
 	    else
-		DEBUGFLAGS="${DEBUGFLAGS} -DDEBUG_{dbg_feature}"
+		DEBUGFLAGS="${DEBUGFLAGS} -DDEBUG_${dbg_feature}"
 	    fi
 	fi
     elif [ "x$cut_arg" = "x--enable-fortran" ]; then
@@ -220,6 +222,18 @@ do
 	MAGMA_HOME=$(echo $arg | cut -d '=' -f2)
     elif [ "x$cut_arg" = "x--without-magma" ]; then
 	MAGMA="no"
+    elif [ "x$cut_arg" = "x--enable-magma-invert" ]; then
+	MAGMA_INVERT_CHOICE=$(echo $arg | cut -d '=' -f2)
+	if [ "x$MAGMA_INVERT_CHOICE" = "xgetri" -o "x$MAGMA_INVERT_CHOICE" = "xauto" ]; then
+	    MAGMA_INVERT_FLAGS=""
+	elif [ "x$MAGMA_INVERT_CHOICE" = "xgesv" ]; then
+	    MAGMA_INVERT_FLAGS=" -DUSE_ZGESV_GPU"
+	elif [ "x$MAGMA_INVERT_CHOICE" = "xrbt" ]; then
+	    MAGMA_INVERT_FLAGS=" -DUSE_ZGESV_RBT"
+	else
+	    echo "ERROR: unrecognized --enable-magma-invert option \"$MAGMA_INVERT_CHOICE\""
+	    exit 1
+	fi
     else
 	echo "ERROR: unrecognized argument \"$arg\""
 	exit 1
@@ -732,6 +746,11 @@ if [ "x$MAGMA" != "xno" ]; then
 	    exit 2
 	fi
     else
+	if [ "x$MAGMAFLAGS" = "x" ]; then
+	    MAGMAFLAGS="$MAGMA_INVERT_FLAGS"
+	else
+	    MAGMAFLAGS="$MAGMAFLAGS$MAGMA_INVERT_FLAGS"
+	fi
 	echo "yes"
     fi
 else
@@ -832,6 +851,13 @@ if [ "x${MAGMAFLAGS}" = "x" ]; then
     echo "INFO: MAGMA is disabled."
 else
     echo "INFO: MAGMA is enabled."
+    if [ "x${MAGMA_INVERT_FLAGS}" = "x" ]; then
+	echo "INFO: using LU factorisation for matrix inversion."
+    elif [ "x${MAGMA_INVERT_FLAGS}" = "x -DUSE_ZGESV_GPU" ]; then
+	echo "INFO: using MAGMA zgesv_gpu function for matrix inversion."
+    elif [ "x${MAGMA_INVERT_FLAGS}" = "x -DUSE_ZGESV_RBT" ]; then
+	echo "INFO: using MAGMA zgesv_rbt function for matrix inversion."
+    fi
 fi
 if [ "x${NVTXFLAGS}" = "x" ]; then
     echo "INFO: NVTX profiling is disabled."
-- 
GitLab