From b05273471117b75fc79ed03988e3a2704f1f5b2f Mon Sep 17 00:00:00 2001 From: Carl Pearson Date: Wed, 16 Oct 2024 13:15:50 -0600 Subject: [PATCH] Blas1 asum: work around for openblas error with short vectors (#2384) Signed-off-by: Carl William Pearson --- blas/tpls/KokkosBlas_Host_tpl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/blas/tpls/KokkosBlas_Host_tpl.cpp b/blas/tpls/KokkosBlas_Host_tpl.cpp index 6989aea34d..c163dc726d 100644 --- a/blas/tpls/KokkosBlas_Host_tpl.cpp +++ b/blas/tpls/KokkosBlas_Host_tpl.cpp @@ -790,6 +790,18 @@ double HostBlas >::nrm2(KK_INT n, const std::complex double HostBlas >::asum(KK_INT n, const std::complex* x, KK_INT x_inc) { + // see issue 2005 + // On some platforms with OpenBLAS < 0.3.26, dzasum on vectors less than 16 entries is producing 0. + // this has been observed on some (not all) systems with: + // clang 14.0.6 / 15.0.7 AND OpenBLAS 0.3.23 AND Sapphire Rapids CPU + // unfortunately, it's not clear exactly what the trigger is + if (n > 0 && n < 16) { + double ret = 0.0; + for (int i = 0; i < n; ++i) { + ret += Kokkos::abs(x[i].real()) + Kokkos::abs(x[i].imag()); + } + return ret; + } return F77_FUNC_DZASUM(&n, x, &x_inc); } template <>