From 3a4dda56122dba3cd69aed12f559b3386f13ba7c Mon Sep 17 00:00:00 2001
From: MARAIT Gilles <gilles.marait@inria.fr>
Date: Fri, 26 Jan 2024 17:35:13 +0100
Subject: [PATCH] Redefine macros for C++ compatibility

---
 include/util.h      |  9 ++++++
 src/help.c          |  4 +++
 src/testCOMPOSE.cpp | 76 ++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 81 insertions(+), 8 deletions(-)

diff --git a/include/util.h b/include/util.h
index 6753c5c..98de84f 100644
--- a/include/util.h
+++ b/include/util.h
@@ -33,6 +33,11 @@
 #endif
 #include <stdbool.h>
 
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
 typedef enum { MPF_FALSE, MPF_TRUE } Logical;
 
 /**************************************************************************************/
@@ -440,3 +445,7 @@ void simpleToDouble(void *data, size_t n) ;
 void doubleToSimple(void *data, size_t n) ;
 int SCAB_Init(int* argc, char*** argv) ;
 int SCAB_Exit(int* argc, char** argv) ;
+
+#if defined __cplusplus
+} // extern "C"
+#endif
diff --git a/src/help.c b/src/help.c
index 6d273d1..1ff6e60 100644
--- a/src/help.c
+++ b/src/help.c
@@ -128,6 +128,10 @@ int printHelp() {
          "     --hlibpro-leaf-size: Maximum leaf size.\n"
          "     --hlibpro-ncpus: Number of CPUs (default is OMP_NUM_THREADS if it is set, 12 otherwise)\n"
          "\n"
+       #endif
+       #ifdef HAVE_COMPOSE
+	 // Options for compose
+	 //"\n"
        #endif
          "     -h/--help: Display this help\n\n");
 
diff --git a/src/testCOMPOSE.cpp b/src/testCOMPOSE.cpp
index 7eaab1c..b03ee76 100644
--- a/src/testCOMPOSE.cpp
+++ b/src/testCOMPOSE.cpp
@@ -3,17 +3,50 @@
 /*! \brief Runs the test using COMPOSE solver
  */
 #if defined(HAVE_COMPOSE)
+
+char * C_PACKAGE_NAME = const_cast<char *>(PACKAGE_NAME) ;
+char * C_FILE = const_cast<char *>(__FILE__);
+
+/*! \brief Displays an error message and that's all. */
+#define C_SETWARN(n,s, ...)   {MpfWarning(__LINE__,C_PACKAGE_NAME,C_FILE,__func__,n,s, ## __VA_ARGS__);}
+/*! \brief Displays an error message and quits the current routine. */
+#define C_SETERRQ(n,s, ...)   {int _ierr = MpfError(__LINE__,C_PACKAGE_NAME,C_FILE,__func__,n,s, ## __VA_ARGS__); debug_break(); return _ierr;}
+/*! \brief Displays an error message and aborts the code. */
+#define C_SETERRA(n,s, ...)   {int _ierr = MpfError(__LINE__,C_PACKAGE_NAME,C_FILE,__func__,n,s, ## __VA_ARGS__);mpf_backtrace();debug_break();MPI_Abort(MPI_COMM_WORLD,_ierr);}
+/*! \brief Checks the integer n, if not zero then it displays an error message and quits the current routine. */
+#define C_CHKERRQ(n)     {if (n) C_SETERRQ(n,(char *)0);}
+/*! \brief Checks the integer n, if not zero then it displays an error message and aborts the code. */
+#define C_CHKERRA(n)     {if (n) C_SETERRA(n,(char *)0);}
+/*! \brief Checks the pointer p, if it is NULL then it displays an error message and quits the current routine. */
+#define C_CHKPTRQ(p)     {if (!(p)) C_SETERRQ(1,"Unable to allocate requested memory");}
+/*! \brief Checks the pointer p, if it is NULL then it displays an error message and aborts the code. */
+#define C_CHKPTRA(p)     {if (!(p)) C_SETERRA(1,"Unable to allocate requested memory");}
+/*! \brief Evaluates the expression x, if it is false then it displays an error message and quits the current routine. */
+#define C_ASSERTQ(x) { if (!(x)) { C_SETERRQ(1, "Assert failure %s", #x); }}
+/*! \brief Evaluates the expression x, if it is false then it displays an error message and aborts the code. */
+#define C_ASSERTA(x) { if (!(x)) { C_SETERRA(1, "Assert failure %s", #x); }}
+
+
 #include <maphys.hpp>
 #include <memory>
 #include <cstring>
+#include <string>
 
 using namespace maphys;
 
-int testCOMPOSE(double * relative_error){
+template<typename Scalar>
+int testCOMPOSE_Scalar(double * relative_error){
 
-  const int N = nbPts;
+  int ierr = 0;
 
-  DenseMatrix<std::complex<double>> A(N, N);
+  /* Realise le produit matrice vecteur classique : A.rhs -> solCLA */
+
+  Mpf_printf(MPI_COMM_WORLD, "\n**** Computing Classical product...\n") ;
+  void *solCLA=NULL;
+  ierr = produitClassique(&solCLA, MPI_COMM_WORLD) ; C_CHKERRQ(ierr) ;
+
+  const int N = nbPts;
+  DenseMatrix<Scalar> A(N, N);
 
   auto myCtx = std::make_unique<contextTestFEMBEM>();
   std::memset(myCtx.get(), 0, sizeof(contextTestFEMBEM));
@@ -26,17 +59,44 @@ int testCOMPOSE(double * relative_error){
   int size_of_buffer = N * N;
   int ld = A.get_leading_dim();
 
-  computeDenseBlockFEMBEM(&row_min, &row_max, &col_min, &col_max,
-                          &Mpf_i_zero, &Mpf_i_one, &Mpf_i_one, &Mpf_i_one,
-                          &size_of_buffer, &ld, (void *) get_ptr(A), (void *) myCtx.get());
+  (simplePrec ?
+   computeDenseBlockFEMBEM_Cprec :
+   computeDenseBlockFEMBEM_Cprec)(&row_min, &row_max, &col_min, &col_max,
+				  &Mpf_i_zero, &Mpf_i_one, &Mpf_i_one, &Mpf_i_one,
+				  &size_of_buffer, &ld, (void *) get_ptr(A), (void *) myCtx.get());
 
-  auto A_first_block = A.get_block_view(0, 0, 6, 6);
-  A_first_block.display("A first block 6x6");
+  const int nrows_show = std::min(N, 5);
+  auto A_first_block = A.get_block_view(0, 0, nrows_show, nrows_show);
+  A_first_block.display("First block");
 
   *relative_error = 1e-15;
   return 0;
 }
 
+int testCOMPOSE(double * relative_error){
+
+  int ierr = 0;
+  switch(stype) {
+  case (SIMPLE_PRECISION) :
+    ierr = testCOMPOSE_Scalar<float>(relative_error);
+    break ;
+  case (DOUBLE_PRECISION) :
+    ierr = testCOMPOSE_Scalar<double>(relative_error);
+    break ;
+  case (SIMPLE_COMPLEX) :
+    ierr = testCOMPOSE_Scalar<std::complex<float>>(relative_error);
+    break ;
+  case (DOUBLE_COMPLEX) :
+    ierr = testCOMPOSE_Scalar<std::complex<double>>(relative_error);
+    break ;
+  default :
+    C_SETERRQ(1, "testHCHAMELEON : unknown scalar type\n") ;
+    break ;
+  }
+
+  return 0;
+}
+
 #else // HAVE_COMPOSE not defined
   int testCOMPOSE(double *){ return 0; }
 #endif // defined(HAVE_COMPOSE)
-- 
GitLab