From 496a1092415867911f50d18359ada0cc348e8047 Mon Sep 17 00:00:00 2001
From: "Mulas, Giacomo" <gmulas@oa-cagliari.inaf.it>
Date: Thu, 16 May 2024 12:13:08 +0200
Subject: [PATCH] update env variable compilation flags to allow for optional
 ilp64 interfaces

---
 src/include/types.h | 10 +++++++++
 src/make.inc        | 55 +++++++++++++++++++++++++++++++++++++++------
 2 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/src/include/types.h b/src/include/types.h
index 4ed9a11c..f6fb68ab 100644
--- a/src/include/types.h
+++ b/src/include/types.h
@@ -27,9 +27,15 @@ typedef __complex__ double dcomplex;
 
 #ifdef USE_LAPACK
 #ifdef USE_MKL
+#ifdef USE_ILP64
 #ifndef MKL_INT 
 #define MKL_INT int64_t
 #endif // MKL_INT
+#else
+#ifndef MKL_INT 
+#define MKL_INT int32_t
+#endif // MKL_INT
+#endif
 #include <mkl_lapacke.h>
 #else
 #include <lapacke.h>
@@ -44,7 +50,11 @@ typedef __complex__ double dcomplex;
 #ifdef lapack_int
 #define np_int lapack_int
 #else
+#ifdef USE_ILP64
 #define np_int int64_t
+#else
+#define np_int int32_t
+#endif // USE_ILP64
 #endif // lapack_int
 #endif // np_int
 
diff --git a/src/make.inc b/src/make.inc
index 3fadc9a8..748256b1 100644
--- a/src/make.inc
+++ b/src/make.inc
@@ -48,32 +48,47 @@ endif
 
 # define (outside) USE_LAPACK for lapacke support, LAPACK_ILP64 for ilp64 interface, MKL_ILP64 the same if using MKL implementation
 ifdef USE_LAPACK
+# define (outside) USE_ILP64 for long long int support in lapack/mkl/magma interfaces
+ifdef USE_ILP64
 ifndef LAPACK_ILP64
 override LAPACK_ILP64=1
+endif #LAPACK_ILP64
 endif
 # define (outside) USE_MKL to use the MKL implementation of lapacke
 ifdef USE_MKL
+# define (outside) USE_ILP64 for long long int support in lapack/mkl/magma interfaces
+ifdef USE_ILP64
 ifndef MKL_ILP64
 override MKL_ILP64=1
+endif #MKL_ILP64
 endif
 ifndef LAPACK_INCLUDE
 # this is for the MKL implementation
 override LAPACK_INCLUDE=$(MKLROOT)/include
-endif
+endif #LAPACK_INCLUDE
 ifndef LAPACK_LDFLAGS
 # this is for the MKL implementation
+# define (outside) USE_ILP64 for long long int support in lapack/mkl/magma interfaces
+ifdef USE_ILP64
 override LAPACK_LDFLAGS=-L$(MKLROOT)/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
+else
+override LAPACK_LDFLAGS=-L$(MKLROOT)/lib -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
 endif
+endif LAPACK_LDFLAGS
 # the next else refers to USE_MKL
-else
+else #this is for when USE_MKL is _not_ defined
 ifndef LAPACK_INCLUDE
 # this is for standard "vanilla" lapacke64
 override LAPACK_INCLUDE=/usr/include
-endif
+endif # LAPACK_INCLUDE
 ifndef LAPACK_LDFLAGS
+ifdef USE_ILP64
 # this is for standard "vanilla" lapacke64
 override LAPACK_LDFLAGS=-llapacke64
+else
+override LAPACK_LDFLAGS=-llapacke
 endif
+endif LAPACK_LDFLAGS
 # the next endif is for USE_MKL
 endif
 #the next endif is for USE_LAPACK
@@ -81,7 +96,11 @@ endif
 
 # define (outside) USE_MAGMA for magma support
 ifdef USE_MAGMA
+ifdef MAGMA_LIB
+MAGMA_LDFLAGS= -L$MAGMA_LIB -lmagma -lcudart
+else
 MAGMA_LDFLAGS= -lmagma -lcudart
+endif
 #the next endif is for USE_MAGMA
 endif
 
@@ -92,25 +111,47 @@ ifdef USE_OPENMP
 override CXXFLAGS+= -fopenmp
 # closes USE_OPENMP
 endif
+
+ifdef USE_ILP64
+override CXXFLAGS+= -DUSE_ILP64
+endif
+
 ifdef USE_LAPACK
-override CXXFLAGS+= -DUSE_LAPACK -DLAPACK_ILP64 
+override CXXFLAGS+= -DUSE_LAPACK
+ifdef USE_ILP64
+override CXXFLAGS+= -DLAPACK_ILP64
+endif
+# closes USE_LAPACK
+endif
+
 ifdef USE_MKL
-override CXXFLAGS+= -DMKL_ILP64 -DUSE_MKL -I$(MKLROOT)/include
+override CXXFLAGS+= -DUSE_MKL -I$(MKLROOT)/include
+ifdef USE_ILP64
+override CXXFLAGS+= -DMKL_ILP64
+endif
 # closes USE_MKL
 endif
+
 ifdef USE_OPENMP
 override CXXFLAGS+= -fopenmp
 # closes USE_OPENMP
 endif
-# closes USE_LAPACK
-endif
+
 ifdef USE_MAGMA
 override CXXFLAGS+= -DUSE_MAGMA
+ifdef MAGMA_INCLUDE
+override CXXFLAGS+= -I$MAGMA_INCLUDE
+endif
+ifdef USE_ILP64
+override CXXFLAGS+= -DMAGMA_ILP64
+endif
 # closes USE_MAGMA
 endif
+
 # closes CXXFLAGS
 endif
 
+
 # HDF5_LIB defines the default path to the HDF5 libraries to use
 # CXXLDFLAGS defines the default linker flags to use for C++ codes
 ifndef CXXLDFLAGS
-- 
GitLab