From 02b0d9690ff1eeb8ce19fa48d4d83552015e8dec Mon Sep 17 00:00:00 2001 From: Nicklas Larsson Date: Thu, 19 Sep 2024 15:14:48 +0200 Subject: [PATCH 1/5] lib/gis: properly guard BLAS and LAPACK dependent code --- include/grass/defs/la.h | 7 +++++++ include/grass/la.h | 8 -------- lib/gmath/la.c | 14 +++++--------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/include/grass/defs/la.h b/include/grass/defs/la.h index b02eb7fd9c8..9befe6b7076 100644 --- a/include/grass/defs/la.h +++ b/include/grass/defs/la.h @@ -12,11 +12,16 @@ mat_struct *G_matrix_subtract(mat_struct *, mat_struct *); mat_struct *G_matrix_scale(mat_struct *, const double); mat_struct *G__matrix_add(mat_struct *, mat_struct *, const double, const double); + +#if defined(HAVE_LIBBLAS) mat_struct *G_matrix_product(mat_struct *, mat_struct *); +#endif mat_struct *G_matrix_transpose(mat_struct *); +#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) int G_matrix_LU_solve(const mat_struct *, mat_struct **, const mat_struct *, mat_type); mat_struct *G_matrix_inverse(mat_struct *); +#endif void G_matrix_free(mat_struct *); void G_matrix_print(mat_struct *); int G_matrix_set_element(mat_struct *, int, int, double); @@ -34,7 +39,9 @@ int G_matvect_retrieve_matrix(vec_struct *); vec_struct *G_vector_init(int, int, vtype); int G_vector_set(vec_struct *, int, int, vtype, int); +#if defined(HAVE_LIBBLAS) double G_vector_norm_euclid(vec_struct *); +#endif double G_vector_norm_maxval(vec_struct *, int); vec_struct *G_vector_copy(const vec_struct *, int); vec_struct *G_vector_product(vec_struct *, vec_struct *, vec_struct *); diff --git a/include/grass/la.h b/include/grass/la.h index edec847c8e1..b274e8f9e6b 100644 --- a/include/grass/la.h +++ b/include/grass/la.h @@ -12,14 +12,6 @@ * \date 2000-2007 */ -#ifndef HAVE_LIBBLAS -#error GRASS GIS is not configured with BLAS (la.h cannot be included) -#endif - -#ifndef HAVE_LIBLAPACK -#error GRASS GIS is not configured with LAPACK (la.h cannot be included) -#endif - #ifndef GRASS_LA_H #define GRASS_LA_H diff --git a/lib/gmath/la.c b/lib/gmath/la.c index 48a4cbc7817..1e66937f4cd 100644 --- a/lib/gmath/la.c +++ b/lib/gmath/la.c @@ -34,7 +34,7 @@ #else #include #endif -#endif +#endif /* HAVE_LIBLAPACK && HAVE_LIBBLAS */ #include #include @@ -386,7 +386,7 @@ mat_struct *G_matrix_product(mat_struct *mt1, mat_struct *mt2) return mt3; } -#endif /* defined(HAVE_LIBBLAS) */ +#endif /* HAVE_LIBBLAS */ /*! * \fn mat_struct *G_matrix_transpose (mat_struct *mt) @@ -442,7 +442,7 @@ mat_struct *G_matrix_transpose(mat_struct *mt) return mt1; } -#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) +#if defined(HAVE_LIBLAPACK) /*! * \fn int G_matrix_LU_solve (const mat_struct *mt1, mat_struct **xmat0, @@ -578,10 +578,6 @@ int G_matrix_LU_solve(const mat_struct *mt1, mat_struct **xmat0, return 0; } -#endif /* defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) */ - -#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) - /*! * \fn mat_struct *G_matrix_inverse (mat_struct *mt) * @@ -637,7 +633,7 @@ mat_struct *G_matrix_inverse(mat_struct *mt) } } -#endif /* defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) */ +#endif /* HAVE_LIBLAPACK */ /*! * \fn void G_matrix_free (mat_struct *mt) @@ -1192,7 +1188,7 @@ double G_vector_norm_euclid(vec_struct *vc) return cblas_dnrm2(Nval, startpt, incr); } -#endif /* defined(HAVE_LIBBLAS) */ +#endif /* HAVE_LIBBLAS */ /*! * \fn double G_vector_norm_maxval (vec_struct *vc, int vflag) From cefdbef7099a74bd1cfb3177a54ec0f8ee46c09b Mon Sep 17 00:00:00 2001 From: Nicklas Larsson Date: Thu, 19 Sep 2024 15:16:18 +0200 Subject: [PATCH 2/5] CI(mac): test without BLAS/LAPACK --- .github/workflows/macos_install.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/macos_install.sh b/.github/workflows/macos_install.sh index 8a94bc15c6a..041c42937f0 100755 --- a/.github/workflows/macos_install.sh +++ b/.github/workflows/macos_install.sh @@ -47,8 +47,6 @@ CONFIGURE_FLAGS="\ --with-bzlib-libs=${CONDA_PREFIX}/lib \ --with-bzlib-includes=${CONDA_PREFIX}/include \ --with-netcdf=${CONDA_PREFIX}/bin/nc-config \ - --with-blas=openblas \ - --with-lapack=openblas \ --with-netcdf=${CONDA_PREFIX}/bin/nc-config \ --with-nls \ --with-libs=${CONDA_PREFIX}/lib \ From e91d0b0e8ce57bf571a58a9df107a6045c7758fa Mon Sep 17 00:00:00 2001 From: Nicklas Larsson Date: Thu, 19 Sep 2024 16:10:25 +0200 Subject: [PATCH 3/5] Revert "CI(mac): test without BLAS/LAPACK" This reverts commit cefdbef7099a74bd1cfb3177a54ec0f8ee46c09b. --- .github/workflows/macos_install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/macos_install.sh b/.github/workflows/macos_install.sh index 041c42937f0..8a94bc15c6a 100755 --- a/.github/workflows/macos_install.sh +++ b/.github/workflows/macos_install.sh @@ -47,6 +47,8 @@ CONFIGURE_FLAGS="\ --with-bzlib-libs=${CONDA_PREFIX}/lib \ --with-bzlib-includes=${CONDA_PREFIX}/include \ --with-netcdf=${CONDA_PREFIX}/bin/nc-config \ + --with-blas=openblas \ + --with-lapack=openblas \ --with-netcdf=${CONDA_PREFIX}/bin/nc-config \ --with-nls \ --with-libs=${CONDA_PREFIX}/lib \ From c25565bfcac0984951c653fdc060d496a95bd926 Mon Sep 17 00:00:00 2001 From: Nicklas Larsson Date: Fri, 20 Sep 2024 08:46:48 +0200 Subject: [PATCH 4/5] Revert "lib/gis: properly guard BLAS and LAPACK dependent code" This reverts commit 02b0d9690ff1eeb8ce19fa48d4d83552015e8dec. --- include/grass/defs/la.h | 7 ------- include/grass/la.h | 8 ++++++++ lib/gmath/la.c | 14 +++++++++----- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/grass/defs/la.h b/include/grass/defs/la.h index 9befe6b7076..b02eb7fd9c8 100644 --- a/include/grass/defs/la.h +++ b/include/grass/defs/la.h @@ -12,16 +12,11 @@ mat_struct *G_matrix_subtract(mat_struct *, mat_struct *); mat_struct *G_matrix_scale(mat_struct *, const double); mat_struct *G__matrix_add(mat_struct *, mat_struct *, const double, const double); - -#if defined(HAVE_LIBBLAS) mat_struct *G_matrix_product(mat_struct *, mat_struct *); -#endif mat_struct *G_matrix_transpose(mat_struct *); -#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) int G_matrix_LU_solve(const mat_struct *, mat_struct **, const mat_struct *, mat_type); mat_struct *G_matrix_inverse(mat_struct *); -#endif void G_matrix_free(mat_struct *); void G_matrix_print(mat_struct *); int G_matrix_set_element(mat_struct *, int, int, double); @@ -39,9 +34,7 @@ int G_matvect_retrieve_matrix(vec_struct *); vec_struct *G_vector_init(int, int, vtype); int G_vector_set(vec_struct *, int, int, vtype, int); -#if defined(HAVE_LIBBLAS) double G_vector_norm_euclid(vec_struct *); -#endif double G_vector_norm_maxval(vec_struct *, int); vec_struct *G_vector_copy(const vec_struct *, int); vec_struct *G_vector_product(vec_struct *, vec_struct *, vec_struct *); diff --git a/include/grass/la.h b/include/grass/la.h index b274e8f9e6b..edec847c8e1 100644 --- a/include/grass/la.h +++ b/include/grass/la.h @@ -12,6 +12,14 @@ * \date 2000-2007 */ +#ifndef HAVE_LIBBLAS +#error GRASS GIS is not configured with BLAS (la.h cannot be included) +#endif + +#ifndef HAVE_LIBLAPACK +#error GRASS GIS is not configured with LAPACK (la.h cannot be included) +#endif + #ifndef GRASS_LA_H #define GRASS_LA_H diff --git a/lib/gmath/la.c b/lib/gmath/la.c index 1e66937f4cd..48a4cbc7817 100644 --- a/lib/gmath/la.c +++ b/lib/gmath/la.c @@ -34,7 +34,7 @@ #else #include #endif -#endif /* HAVE_LIBLAPACK && HAVE_LIBBLAS */ +#endif #include #include @@ -386,7 +386,7 @@ mat_struct *G_matrix_product(mat_struct *mt1, mat_struct *mt2) return mt3; } -#endif /* HAVE_LIBBLAS */ +#endif /* defined(HAVE_LIBBLAS) */ /*! * \fn mat_struct *G_matrix_transpose (mat_struct *mt) @@ -442,7 +442,7 @@ mat_struct *G_matrix_transpose(mat_struct *mt) return mt1; } -#if defined(HAVE_LIBLAPACK) +#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) /*! * \fn int G_matrix_LU_solve (const mat_struct *mt1, mat_struct **xmat0, @@ -578,6 +578,10 @@ int G_matrix_LU_solve(const mat_struct *mt1, mat_struct **xmat0, return 0; } +#endif /* defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) */ + +#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) + /*! * \fn mat_struct *G_matrix_inverse (mat_struct *mt) * @@ -633,7 +637,7 @@ mat_struct *G_matrix_inverse(mat_struct *mt) } } -#endif /* HAVE_LIBLAPACK */ +#endif /* defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) */ /*! * \fn void G_matrix_free (mat_struct *mt) @@ -1188,7 +1192,7 @@ double G_vector_norm_euclid(vec_struct *vc) return cblas_dnrm2(Nval, startpt, incr); } -#endif /* HAVE_LIBBLAS */ +#endif /* defined(HAVE_LIBBLAS) */ /*! * \fn double G_vector_norm_maxval (vec_struct *vc, int vflag) From 0578d1f28e8064a58ec729a5bda85b469be028bf Mon Sep 17 00:00:00 2001 From: Nicklas Larsson Date: Fri, 20 Sep 2024 09:13:44 +0200 Subject: [PATCH 5/5] lib/gis: properly guard BLAS and LAPACK dependent code (original logic) --- lib/gmath/la.c | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/gmath/la.c b/lib/gmath/la.c index 48a4cbc7817..5696a174bda 100644 --- a/lib/gmath/la.c +++ b/lib/gmath/la.c @@ -23,23 +23,24 @@ ******************************************************************************/ #include -#include -#include -#include -#if defined(HAVE_LIBLAPACK) && defined(HAVE_LIBBLAS) +#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) + +#include +#include +#include +#include + #include #if defined(HAVE_CBLAS_ATLAS_H) #include #else #include -#endif -#endif +#endif // HAVE_CBLAS_ATLAS_H -#include -#include -#include -#include +#include +#include +#include static int egcmp(const void *pa, const void *pb); @@ -335,8 +336,6 @@ mat_struct *G__matrix_add(mat_struct *mt1, mat_struct *mt2, const double c1, return mt3; } -#if defined(HAVE_LIBBLAS) - /*! * \fn mat_struct *G_matrix_product (mat_struct *mt1, mat_struct *mt2) * @@ -386,8 +385,6 @@ mat_struct *G_matrix_product(mat_struct *mt1, mat_struct *mt2) return mt3; } -#endif /* defined(HAVE_LIBBLAS) */ - /*! * \fn mat_struct *G_matrix_transpose (mat_struct *mt) * @@ -442,8 +439,6 @@ mat_struct *G_matrix_transpose(mat_struct *mt) return mt1; } -#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) - /*! * \fn int G_matrix_LU_solve (const mat_struct *mt1, mat_struct **xmat0, * const mat_struct *bmat, mat_type mtype) @@ -578,10 +573,6 @@ int G_matrix_LU_solve(const mat_struct *mt1, mat_struct **xmat0, return 0; } -#endif /* defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) */ - -#if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) - /*! * \fn mat_struct *G_matrix_inverse (mat_struct *mt) * @@ -637,8 +628,6 @@ mat_struct *G_matrix_inverse(mat_struct *mt) } } -#endif /* defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK) */ - /*! * \fn void G_matrix_free (mat_struct *mt) * @@ -1149,8 +1138,6 @@ int G_vector_set(vec_struct *A, int cells, int ldim, vtype vt, int vindx) return 0; } -#if defined(HAVE_LIBBLAS) - /*! * \fn double G_vector_norm_euclid (vec_struct *vc) * @@ -1192,8 +1179,6 @@ double G_vector_norm_euclid(vec_struct *vc) return cblas_dnrm2(Nval, startpt, incr); } -#endif /* defined(HAVE_LIBBLAS) */ - /*! * \fn double G_vector_norm_maxval (vec_struct *vc, int vflag) * @@ -1655,3 +1640,7 @@ static int egcmp(const void *pa, const void *pb) return 0; } + +#endif // HAVE_LIBLAPACK HAVE_LIBBLAS + +typedef int suppress_empty_translation_unit_compiler_warning;