From d802647b58758dbff68622a22590a3d39cbbe778 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Mon, 12 Feb 2024 10:53:18 +0100
Subject: [PATCH] Separate the chameleon context struct declaration
 (CHAM_context_t) from others to avoid adding an unnecessary dependency to MPI
 in libs coreblas, gpucublas, gpuhipblas.

---
 coreblas/compute/CMakeLists.txt    |  3 --
 include/CMakeLists.txt             |  1 +
 include/chameleon.h                |  1 +
 include/chameleon/runtime_struct.h |  9 ++++-
 include/chameleon/struct.h         | 43 ---------------------
 include/chameleon/struct_context.h | 62 ++++++++++++++++++++++++++++++
 6 files changed, 71 insertions(+), 48 deletions(-)
 create mode 100644 include/chameleon/struct_context.h

diff --git a/coreblas/compute/CMakeLists.txt b/coreblas/compute/CMakeLists.txt
index bd4ad9f21..137adfbba 100644
--- a/coreblas/compute/CMakeLists.txt
+++ b/coreblas/compute/CMakeLists.txt
@@ -164,9 +164,6 @@ endif()
 target_link_libraries(coreblas PRIVATE MORSE::LAPACKE)
 target_link_libraries(coreblas PRIVATE MORSE::CBLAS)
 target_link_libraries(coreblas PUBLIC MORSE::M)
-if (CHAMELEON_USE_MPI)
-  target_link_libraries(coreblas PUBLIC MPI::MPI_C)
-endif()
 
 # export target coreblas
 install(EXPORT coreblasTargets
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index d65ef6a75..3196000d3 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -54,6 +54,7 @@ set(CHAMELEON_HDRS
   chameleon/runtime_struct.h
   chameleon/simulate.h
   chameleon/struct.h
+  chameleon/struct_context.h
   chameleon/tasks.h
   chameleon/timer.h
   chameleon/types.h
diff --git a/include/chameleon.h b/include/chameleon.h
index 649103772..6db91f76e 100644
--- a/include/chameleon.h
+++ b/include/chameleon.h
@@ -33,6 +33,7 @@
 #include "chameleon/constants.h"
 #include "chameleon/types.h"
 #include "chameleon/struct.h"
+#include "chameleon/struct_context.h"
 #include "chameleon/descriptor_helpers.h"
 
 #if defined(CHAMELEON_USE_MPI)
diff --git a/include/chameleon/runtime_struct.h b/include/chameleon/runtime_struct.h
index e0282d6ae..362af6e86 100644
--- a/include/chameleon/runtime_struct.h
+++ b/include/chameleon/runtime_struct.h
@@ -23,6 +23,13 @@
 #ifndef _chameleon_runtime_struct_h_
 #define _chameleon_runtime_struct_h_
 
+#include "chameleon/types.h"
+
+BEGIN_C_DECLS
+
+/**
+ * Datatype for distributed version
+ */
 #if defined(CHAMELEON_USE_MPI)
 #include <mpi.h>
 #else
@@ -34,8 +41,6 @@ typedef uintptr_t MPI_Comm;
 #endif
 #endif
 
-BEGIN_C_DECLS
-
 /**
  * @brief Ids of the runtime supported by the RUNTIME API
  */
diff --git a/include/chameleon/struct.h b/include/chameleon/struct.h
index 539049e3c..053cddd61 100644
--- a/include/chameleon/struct.h
+++ b/include/chameleon/struct.h
@@ -28,18 +28,6 @@
 #include "chameleon/config.h"
 #include "chameleon/types.h"
 #include "chameleon/constants.h"
-#include "chameleon/runtime_struct.h"
-
-#if defined(CHAMELEON_USE_MPI)
-#include <mpi.h>
-#else
-#ifndef MPI_Comm
-typedef uintptr_t MPI_Comm;
-#endif
-#ifndef MPI_COMM_WORLD
-#define MPI_COMM_WORLD 0
-#endif
-#endif
 
 BEGIN_C_DECLS
 
@@ -174,37 +162,6 @@ typedef struct chameleon_piv_s {
     int     n;              /**> The number of column considered (must be updated for each panel) */
 } CHAM_ipiv_t;
 
-/**
- *  CHAMELEON request uniquely identifies each asynchronous function call.
- */
-typedef struct chameleon_context_s {
-    RUNTIME_id_t       scheduler;
-    int                nworkers;
-    int                ncudas;
-    int                nthreads_per_worker;
-
-    /* Boolean flags */
-    cham_bool_t        warnings_enabled;
-    cham_bool_t        autotuning_enabled;
-    cham_bool_t        parallel_enabled;
-    cham_bool_t        statistics_enabled;
-    cham_bool_t        progress_enabled;
-    cham_bool_t        generic_enabled;
-    cham_bool_t        autominmax_enabled;
-    cham_bool_t        runtime_paused;
-
-    cham_householder_t householder;        // "domino" (flat) or tree-based (reduction) Householder
-    cham_translation_t translation;        // In place or Out of place layout conversion
-
-    int                nb;
-    int                ib;
-    int                rhblock;            // block size for tree-based (reduction) Householder
-    int                lookahead;          // depth of the look ahead in algorithms
-    void              *schedopt;           // structure for runtimes
-    int                mpi_outer_init;     // MPI has been initialized outside our functions
-    MPI_Comm           comm;               // MPI communicator
-} CHAM_context_t;
-
 static inline void *
 CHAM_tile_get_ptr( const CHAM_tile_t *tile )
 {
diff --git a/include/chameleon/struct_context.h b/include/chameleon/struct_context.h
new file mode 100644
index 000000000..8c655d921
--- /dev/null
+++ b/include/chameleon/struct_context.h
@@ -0,0 +1,62 @@
+/**
+ *
+ * @file struct_context.h
+ *
+ * @copyright 2009-2014 The University of Tennessee and The University of
+ *                      Tennessee Research Foundation. All rights reserved.
+ * @copyright 2012-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
+ *                      Univ. Bordeaux. All rights reserved.
+ *
+ ***
+ *
+ * @brief Chameleon context structure
+ *
+ * @version 1.3.0
+ * @author Mathieu Faverge
+ * @author Florent Pruvost
+ * @date 2024-02-12
+ *
+ */
+#ifndef _struct_context_h_
+#define _struct_context_h_
+
+#include "chameleon/types.h"
+#include "chameleon/constants.h"
+#include "chameleon/runtime_struct.h"
+
+BEGIN_C_DECLS
+
+/**
+ *  @brief Chameleon context structure
+ */
+typedef struct chameleon_context_s {
+    RUNTIME_id_t       scheduler;
+    int                nworkers;
+    int                ncudas;
+    int                nthreads_per_worker;
+
+    /* Boolean flags */
+    cham_bool_t        warnings_enabled;
+    cham_bool_t        autotuning_enabled;
+    cham_bool_t        parallel_enabled;
+    cham_bool_t        statistics_enabled;
+    cham_bool_t        progress_enabled;
+    cham_bool_t        generic_enabled;
+    cham_bool_t        autominmax_enabled;
+    cham_bool_t        runtime_paused;
+
+    cham_householder_t householder;        /**> "domino" (flat) or tree-based (reduction) Householder */
+    cham_translation_t translation;        /**> In place or Out of place layout conversion            */
+
+    int                nb;
+    int                ib;
+    int                rhblock;            /**> block size for tree-based (reduction) Householder     */
+    int                lookahead;          /**> depth of the look ahead in algorithms                 */
+    void              *schedopt;           /**> structure for runtimes                                */
+    int                mpi_outer_init;     /**> MPI has been initialized outside our functions        */
+    MPI_Comm           comm;               /**> MPI communicator                                      */
+} CHAM_context_t;
+
+END_C_DECLS
+
+#endif /* _struct_context_h_ */
-- 
GitLab