From 7637327ded2430814fdbefa07843d10458e84fab Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Thu, 11 Jul 2024 16:16:56 +0200
Subject: [PATCH] Modify configuration to work with pipeline

---
 .gitlab-ci.yml     | 90 +++++++++++++++++++++++++++++++++++-----------
 build/Makefile.am  |  5 ++-
 build/configure    | 73 +++++++++++++++++++++++++++++++++++--
 build/configure.ac | 44 +++++++++++++++++++++--
 4 files changed, 184 insertions(+), 28 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c33ca543..a8b51015 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -29,11 +29,9 @@ compatibility_stage:
    allow_failure: true
    artifacts:
       paths:
-         - build/cluster/*
-         - build/sphere/*
-         - build/testing/*
-         - build/trapping/*
-         - build/libnptm/*
+         - build_*
+         - build_*/*
+	 - build_*/*/*
       exclude:
          - ".git*"
          - ".git/**/*"
@@ -46,25 +44,71 @@ compatibility_stage:
       - echo $CI_COMMIT_BRANCH
       - echo "Getting system info ..."
       - cat /etc/os-release
-      - cd src
       - echo "Running make with gnu compilers version 11..."
-      - make clean && BUILDDIR=$PWD/../build_gnu11 CXX=g++-11 FC=gfortran-11 make -j
+      - mkdir build_gnu11
+      - cd build_gnu11
+      - cp -r ../build/* .
+      - CXX=g++-11 F77=gfortran-11 ./configure
+      - make clean
+      - make -j
       - echo "Running make with gnu compilers version 12..."
-      - make clean && BUILDDIR=$PWD/../build_gnu12 CXX=g++-12 FC=gfortran-12 make -j
+      - cd ..
+      - mkdir build_gnu12
+      - cd build_gnu12
+      - cp -r ../build/* .
+      - CXX=g++-12 F77=gfortran-12 ./configure
+      - make clean
+      - make -j
       - echo "Running make with gnu compilers version 13..."
-      - make clean && BUILDDIR=$PWD/../build_gnu13 CXX=g++-13 FC=gfortran-13 make -j
+      - cd ..
+      - mkdir build_gnu13
+      - cd build_gnu13
+      - cp -r ../build/* .
+      - CXX=g++-13 F77=gfortran-13 ./configure
+      - make clean
+      - make -j
       - echo "Running make with gnu compilers version 14..."
-      - make clean && BUILDDIR=$PWD/../build_gnu14 CXX=g++-14 FC=gfortran-14 make -j
+      - cd ..
+      - mkdir build_gnu14
+      - cd build_gnu14
+      - cp -r ../build/* .
+      - CXX=g++-14 F77=gfortran-14 ./configure
+      - make clean
+      - make -j
       - echo "Running make with flang version 16 and clang version 16..."
-      - make clean && BUILDDIR=$PWD/../build_clang16 CXX="clang++-16 -stdlib=libstdc++ -I/usr/include/c++/13 -I/usr/include/x86_64-linux-gnu/c++/13" FC=flang-new-16 FCFLAGS=-O3 LDFLAGS="-L/usr/lib/llvm-16/lib -L/usr/lib/gcc/x86_64-linux-gnu/13" make -j
+      - cd ..
+      - mkdir build_clang16
+      - cd build_clang16
+      - cp -r ../build/* .
+      - CXX=clang++-16 F77=flang-new-16 ./configure --with-fflags="-O3" --with-include="-I/usr/include/c++/13 -I/usr/include/x86_64-linux-gnu/c++/13" --with-ldflags="-L/usr/lib/llvm-16/lib -L/usr/lib/gcc/x86_64-linux-gnu/13"
+      - make clean
+      - make -j
       - echo "Running make with flang version 17 and clang version 17..."
-      - make clean && BUILDDIR=$PWD/../build_clang17 CXX="clang++-17 -stdlib=libstdc++ -I/usr/include/c++/13 -I/usr/include/x86_64-linux-gnu/c++/13" FC=flang-new-17 FCFLAGS=-O3 LDFLAGS="-L/usr/lib/llvm-17/lib -L/usr/lib/gcc/x86_64-linux-gnu/13" make -j
+      - cd ..
+      - mkdir build_clang17
+      - cd build_clang17
+      - cp -r ../build/* .
+      - CXX=clang++-17 F77=flang-new-17 ./configure --with-fflags="-O3" --with-include="-I/usr/include/c++/13 -I/usr/include/x86_64-linux-gnu/c++/13" --with-ldflags="-L/usr/lib/llvm-17/lib -L/usr/lib/gcc/x86_64-linux-gnu/13"
+      - make clean
+      - make -j
       - echo "Running make with Intel ifort and Intel icpx..."
-      - make clean && LD_LIBRARY_PATH=/opt/intel/oneapi/compiler/2024.2/lib PATH=/opt/intel/oneapi/compiler/2024.2/bin:$PATH BUILDDIR=$PWD/../build_ifort-icpx CXX=icpx FC=ifort FCFLAGS="-O3 -diag-disable=10448" make -j
+      - cd ..
+      - mkdir build_ifort_icpx
+      - cd build_ifort_icpx
+      - cp -r ../build/* .
+      - LD_LIBRARY_PATH=/opt/intel/oneapi/compiler/2024.2/lib PATH=/opt/intel/oneapi/compiler/2024.2/bin:$PATH CXX=icpx F77=ifort ./configure --with-fflags="-O3 -diag-disable=10448"
+      - make clean
+      - make -j
       - echo "Running make with Intel ifx and Intel icpx..."
-      - make clean && LD_LIBRARY_PATH=/opt/intel/oneapi/compiler/2024.2/lib PATH=/opt/intel/oneapi/compiler/2024.2/bin:$PATH BUILDDIR=$PWD/../build_ifx-icpx CXX=icpx FC=ifx FCFLAGS=-O3 make -j
-      - echo "Running make with default MPI compilers"
-      - make clean && BUILDDIR=$PWD/../build_mpi CXX=mpicxx FC=mpif90 USE_MPI=1 make -j
+      - cd ..
+      - mkdir build_ifx_icpx
+      - cd build_ifx_icpx
+      - cp -r ../build/* .
+      - LD_LIBRARY_PATH=/opt/intel/oneapi/compiler/2024.2/lib PATH=/opt/intel/oneapi/compiler/2024.2/bin:$PATH CXX=icpx F77=ifx ./configure --with-fflags="-O3"
+      - make clean
+      - make -j
+      #- echo "Running make with default MPI compilers"
+      #- make clean && BUILDDIR=$PWD/../build_mpi CXX=mpicxx FC=mpif90 USE_MPI=1 make -j
    
 building_stage:
    stage: build
@@ -90,9 +134,13 @@ building_stage:
       - echo $CI_COMMIT_BRANCH
       - echo "Getting system info ..."
       - cat /etc/os-release
-      - cd src
-      - echo "Running make with default compilers..."
-      - make clean && USE_LAPACK=1 USE_ILP64=1 make -j
+      - cd build
+      - echo "Configuring with default compilers (MAGMA disabled)..."
+      - ./configure --without-magma
+      - make clean
+      - echo "Building default configuration..."
+      - make -j
+      - echo "Building documentation..."
       - make docs -j && make -C ../doc/build/latex -j
 
 running_stage:
@@ -125,7 +173,7 @@ running_stage:
       - cd ../cluster
       - echo "Running np_cluster"
       - chmod +x np_cluster
-      - ./np_cluster
+      - OMP_NUM_THREADS=1 ./np_cluster
       
 testing_stage:
    stage: test
@@ -162,7 +210,7 @@ testing_stage:
       - export FFILE=../../test_data/cluster/OCLU
       - python3 ../../src/scripts/pycompare.py --no-progress --ffile=$FFILE --cfile=c_OCLU --html
       - echo "Testing cluster with 24 spheres"
-      - ./np_cluster ../../test_data/cluster/DEDFB_24 ../../test_data/cluster/DCLU_24 .
+      - OMP_NUM_THREADS=1 mpirun -n 2 ./np_cluster ../../test_data/cluster/DEDFB_24 ../../test_data/cluster/DCLU_24 .
       - echo "Comparing output of CLUSTER with 24 spheres"
       - export FFILE=../../test_data/cluster/OCLU_24
       - python3 ../../src/scripts/pycompare.py --no-progress --ffile=$FFILE --cfile=c_OCLU --html
diff --git a/build/Makefile.am b/build/Makefile.am
index 70a7bffc..dcb4cfcf 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -1,8 +1,8 @@
 AUTOMAKE_OPTIONS=subdir-objects
-LDADD=libnptm/libnptm.la -L/usr/lib64 ${HDF5_LDFLAGS} ${LAPACKLDFLAGS} ${MAGMALDFLAGS}
+LDADD=libnptm/libnptm.la -L/usr/lib64 ${USER_LDFLAGS} ${HDF5_LDFLAGS} ${LAPACKLDFLAGS} ${MAGMALDFLAGS}
 lib_LTLIBRARIES=libnptm/libnptm.la
 libnptm_libnptm_la_SOURCES=../src/libnptm/algebraic.cpp ../src/libnptm/clu_subs.cpp ../src/libnptm/Commons.cpp ../src/libnptm/Configuration.cpp ../src/libnptm/file_io.cpp ../src/libnptm/lapack_calls.cpp ../src/libnptm/logging.cpp ../src/libnptm/magma_calls.cpp ../src/libnptm/Parsers.cpp ../src/libnptm/sph_subs.cpp ../src/libnptm/tfrfme.cpp ../src/libnptm/TransitionMatrix.cpp ../src/libnptm/tra_subs.cpp ../src/libnptm/types.cpp
-bin_PROGRAMS=cluster/edfb_clu cluster/clu cluster/np_cluster sphere/edfb_sph sphere/sph sphere/np_sphere trapping/frfme trapping/lffft trapping/np_trapping
+bin_PROGRAMS=cluster/edfb_clu cluster/clu cluster/np_cluster sphere/edfb_sph sphere/sph sphere/np_sphere trapping/frfme trapping/lffft trapping/np_trapping testing/test_TEDF testing/test_TTMS
 cluster_edfb_clu_SOURCES=../src/cluster/edfb_clu.f
 cluster_clu_SOURCES=../src/cluster/clu.f
 cluster_np_cluster_SOURCES=../src/cluster/np_cluster.cpp ../src/cluster/cluster.cpp
@@ -12,6 +12,5 @@ sphere_np_sphere_SOURCES=../src/sphere/np_sphere.cpp ../src/sphere/sphere.cpp
 trapping_frfme_SOURCES=../src/trapping/frfme.f
 trapping_lffft_SOURCES=../src/trapping/lffft.f
 trapping_np_trapping_SOURCES=../src/trapping/np_trapping.cpp ../src/trapping/cfrfme.cpp ../src/trapping/clffft.cpp
-check_PROGRAMS=testing/test_TEDF testing/test_TTMS
 testing_test_TEDF_SOURCES=../src/testing/test_TEDF.cpp
 testing_test_TTMS_SOURCES=../src/testing/test_TTMS.cpp
diff --git a/build/configure b/build/configure
index 446b5abc..d6291c94 100755
--- a/build/configure
+++ b/build/configure
@@ -656,6 +656,8 @@ ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
+USER_LDFLAGS
+USER_INCLUDE
 NVTXFLAGS
 MAGMALDFLAGS
 MAGMAFLAGS
@@ -812,6 +814,9 @@ enable_openmp
 with_lapack
 with_magma
 enable_nvtx
+with_include
+with_fflags
+with_ldflags
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1483,6 +1488,9 @@ Optional Packages:
                           compiler's sysroot if not specified).
   --with-lapack           use LAPACK [default=check]
   --with-magma            use MAGMA [default=check]
+  --with-include          additional include folders [default=none]
+  --with-fflags=flags     FORTRAN compiler flags [default="-std=legacy -O3"]
+  --with-ldflags=flags    custom linker flags [default=none]
 
 Some influential environment variables:
   CC          C compiler command
@@ -24388,8 +24396,69 @@ esac
 fi
 
 
-FFLAGS="-std=legacy -O3"
-CXXFLAGS="$CLANGFLAGS -O3 -ggdb -I$HDF5_INCLUDE $OMPFLAGS $MPIFLAGS $LAPACKFLAGS $MAGMAFLAGS $NVTXFLAGS"
+# Test for additional user configurations
+# Test for specific include folders
+
+# Check whether --with-include was given.
+if test ${with_include+y}
+then :
+  withval=$with_include;
+    if test "x$with_val" != "x"; then
+      USER_INCLUDE=$with_val
+
+    fi
+
+else case e in #(
+  e) USER_INCLUDE=""
+
+ ;;
+esac
+fi
+
+
+# Test for special FORTRAN compiler flags
+
+# Check whether --with-fflags was given.
+if test ${with_fflags+y}
+then :
+  withval=$with_fflags;
+    if test "x$with_val" != "x"; then
+      FFLAGS=$with_val
+
+    fi
+
+else case e in #(
+  e)
+    FFLAGS="-std=legacy -O3"
+
+
+ ;;
+esac
+fi
+
+
+# Test for special linker flags
+
+# Check whether --with-ldflags was given.
+if test ${with_ldflags+y}
+then :
+  withval=$with_ldflags;
+    if test "x$with_val" != "x"; then
+      USER_LDFLAGS=$with_val
+
+    fi
+
+else case e in #(
+  e)
+    USER_LDFLAGS=""
+
+
+ ;;
+esac
+fi
+
+
+CXXFLAGS="$CLANGFLAGS -O3 -ggdb $USER_INCLUDE -I$HDF5_INCLUDE $OMPFLAGS $MPIFLAGS $LAPACKFLAGS $MAGMAFLAGS $NVTXFLAGS"
 SUBDIRS="cluster libnptm sphere testing trapping"
 
 # Send output to Makefiles
diff --git a/build/configure.ac b/build/configure.ac
index 9bdce89f..f4397d36 100644
--- a/build/configure.ac
+++ b/build/configure.ac
@@ -247,8 +247,48 @@ AC_ARG_ENABLE(
   ]
 )
 
-FFLAGS="-std=legacy -O3"
-CXXFLAGS="$CLANGFLAGS -O3 -ggdb -I$HDF5_INCLUDE $OMPFLAGS $MPIFLAGS $LAPACKFLAGS $MAGMAFLAGS $NVTXFLAGS"
+# Test for additional user configurations
+# Test for specific include folders
+AC_ARG_WITH(
+  [include],
+  [AS_HELP_STRING([--with-include], [additional include folders @<:@default=none@:>@])],
+  [
+    if test "x$with_val" != "x"; then
+      AC_SUBST([USER_INCLUDE], [$with_val])
+    fi
+  ],
+  [AC_SUBST([USER_INCLUDE], [""])]
+)
+
+# Test for special FORTRAN compiler flags
+AC_ARG_WITH(
+  [fflags],
+  [AS_HELP_STRING([--with-fflags=flags], [FORTRAN compiler flags @<:@default="-std=legacy -O3"@:>@])],
+  [
+    if test "x$with_val" != "x"; then
+      AC_SUBST([FFLAGS], [$with_val])
+    fi
+  ],
+  [
+    AC_SUBST([FFLAGS], ["-std=legacy -O3"])
+  ]
+)
+
+# Test for special linker flags
+AC_ARG_WITH(
+  [ldflags],
+  [AS_HELP_STRING([--with-ldflags=flags], [custom linker flags @<:@default=none@:>@])],
+  [
+    if test "x$with_val" != "x"; then
+      AC_SUBST([USER_LDFLAGS], [$with_val])
+    fi
+  ],
+  [
+    AC_SUBST([USER_LDFLAGS], [""])
+  ]
+)
+
+CXXFLAGS="$CLANGFLAGS -O3 -ggdb $USER_INCLUDE -I$HDF5_INCLUDE $OMPFLAGS $MPIFLAGS $LAPACKFLAGS $MAGMAFLAGS $NVTXFLAGS"
 SUBDIRS="cluster libnptm sphere testing trapping"
 
 # Send output to Makefiles
-- 
GitLab