From 2e71ddb1e52837ace4eb4c5cb83dde1d8551592d Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Wed, 18 Sep 2024 13:48:06 +0200
Subject: [PATCH] lapacke_dlamch: Add a chameleon wrapper to encapsulate and
 refactor the test on CHAMELEON_SIMULATION

---
 compute/CMakeLists.txt |  5 ++--
 control/lamch.c        | 56 ++++++++++++++++++++++++++++++++++++++++++
 include/chameleon.h    |  4 +++
 3 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 control/lamch.c

diff --git a/compute/CMakeLists.txt b/compute/CMakeLists.txt
index cc25fb7d2..3d6a7caf4 100644
--- a/compute/CMakeLists.txt
+++ b/compute/CMakeLists.txt
@@ -40,11 +40,12 @@ set(CHAMELEON_CONTROL
     ../control/context.c
     ../control/control.c
     ../control/descriptor.c
-    ../control/descriptor_rec.c
     ../control/descriptor_helpers.c
     ../control/descriptor_ipiv.c
-    ../control/workspace.c
+    ../control/descriptor_rec.c
+    ../control/lamch.c
     ../control/tile.c
+    ../control/workspace.c
     ../control/chameleon_f77.c
     ../control/chameleon_mf77.c
     map.c
diff --git a/control/lamch.c b/control/lamch.c
new file mode 100644
index 000000000..7dccb23f0
--- /dev/null
+++ b/control/lamch.c
@@ -0,0 +1,56 @@
+/**
+ *
+ * @file lamch.c
+ *
+ * @copyright 2024-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
+ *                      Univ. Bordeaux. All rights reserved.
+ *
+ ***
+ *
+ * @brief Chameleon lamch wrapper to factorize the test with simulation compilations
+ *
+ * @version 1.3.0
+ * @author Mathieu Faverge
+ * @date 2024-09-18
+ *
+ */
+#include "control/common.h"
+#if !defined(CHAMELEON_SIMULATION)
+#include "coreblas/lapacke.h"
+#endif
+
+/**
+ *
+ * Wrapper to the LAPACKE_slamch_work('e') call that returns a pre-defined value
+ * if compile with SimGrid.
+ *
+ * @return The epsilon value for single precision
+ *
+ */
+float
+CHAMELEON_slamch( void )
+{
+#if !defined(CHAMELEON_SIMULATION)
+    return LAPACKE_slamch_work( 'e' );
+#else
+    return 1.e-7;
+#endif
+}
+
+/**
+ *
+ * Wrapper to the LAPACKE_dlamch_work('e') call that returns a pre-defined value
+ * if compile with SimGrid.
+ *
+ * @return The epsilon value for single precision
+ *
+ */
+double
+CHAMELEON_dlamch( void )
+{
+#if !defined(CHAMELEON_SIMULATION)
+    return LAPACKE_dlamch_work( 'e' );
+#else
+    return 1.e-15;
+#endif
+}
diff --git a/include/chameleon.h b/include/chameleon.h
index 7aeaf7d33..cb7e23ded 100644
--- a/include/chameleon.h
+++ b/include/chameleon.h
@@ -227,6 +227,10 @@ int CHAMELEON_Ipiv_Gather( CHAM_ipiv_t *ipivdesc,
                            int          root );
 void CHAMELEON_Ipiv_Print ( const CHAM_ipiv_t *ipiv );
 
+/* Numerical helpers */
+float CHAMELEON_slamch( void );
+double CHAMELEON_dlamch( void );
+
 /**
  *
  * @ingroup Control
-- 
GitLab