From 77f8fe047d2c8c110090332a56f31e43e0490809 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Wed, 7 Feb 2024 17:22:02 +0100
Subject: [PATCH] ipiv: Change the runtime_ipiv interface to always take
 sequence as first argument when needed

---
 compute/zgetrf.c                              |  4 ++--
 control/descriptor_ipiv.c                     | 20 +++++++++++++++----
 include/chameleon/runtime.h                   |  7 ++++---
 .../openmp/control/runtime_descriptor_ipiv.c  |  8 +++++---
 .../parsec/control/runtime_descriptor_ipiv.c  |  8 +++++---
 .../quark/control/runtime_descriptor_ipiv.c   |  8 +++++---
 .../starpu/control/runtime_descriptor_ipiv.c  |  7 ++++---
 7 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/compute/zgetrf.c b/compute/zgetrf.c
index 0a3682b20..a1887f832 100644
--- a/compute/zgetrf.c
+++ b/compute/zgetrf.c
@@ -19,7 +19,7 @@
  * @author Florent Pruvost
  * @author Matthieu Kuhn
  * @author Lionel Eyraud-Dubois
- * @date 2023-09-08
+ * @date 2024-03-16
  *
  * @precisions normal z -> s d c
  *
@@ -280,7 +280,7 @@ CHAMELEON_zgetrf( int M, int N, CHAMELEON_Complex64_t *A, int LDA, int *IPIV )
     if ( ( ws->alg == ChamGetrfPPivPerColumn ) ||
          ( ws->alg == ChamGetrfPPiv ) )
     {
-        RUNTIME_ipiv_gather( &descIPIV, IPIV, 0 );
+        RUNTIME_ipiv_gather( sequence, &descIPIV, IPIV, 0 );
     }
     chameleon_sequence_wait( chamctxt, sequence );
 
diff --git a/control/descriptor_ipiv.c b/control/descriptor_ipiv.c
index 784a0ef7b..e9631909b 100644
--- a/control/descriptor_ipiv.c
+++ b/control/descriptor_ipiv.c
@@ -12,7 +12,7 @@
  * @version 1.3.0
  * @author Mathieu Faverge
  * @author Matthieu Kuhn
- * @date 2023-08-22
+ * @date 2024-03-16
  *
  ***
  *
@@ -210,7 +210,7 @@ int CHAMELEON_Ipiv_Destroy(CHAM_ipiv_t **ipivptr)
 int CHAMELEON_Ipiv_Flush( const CHAM_ipiv_t        *ipiv,
                           const RUNTIME_sequence_t *sequence )
 {
-    RUNTIME_ipiv_flush( ipiv, sequence );
+    RUNTIME_ipiv_flush( sequence, ipiv );
     return CHAMELEON_SUCCESS;
 }
 
@@ -240,6 +240,18 @@ int CHAMELEON_Ipiv_Flush( const CHAM_ipiv_t        *ipiv,
  */
 int CHAMELEON_Ipiv_Gather( CHAM_ipiv_t *ipivdesc, int *ipiv, int root )
 {
-    RUNTIME_ipiv_gather( ipivdesc, ipiv, root );
-    return CHAMELEON_SUCCESS;
+    CHAM_context_t     *chamctxt = chameleon_context_self();
+    RUNTIME_sequence_t *sequence = NULL;
+    int                 status;
+
+    chameleon_sequence_create( chamctxt, &sequence );
+
+    /* Submit the tasks to collect the ipiv array on root */
+    RUNTIME_ipiv_gather( sequence, ipivdesc, ipiv, root );
+
+    /* Wait for the end */
+    chameleon_sequence_wait( chamctxt, sequence );
+    status = sequence->status;
+    chameleon_sequence_destroy( chamctxt, sequence );
+    return status;
 }
diff --git a/include/chameleon/runtime.h b/include/chameleon/runtime.h
index 1ee2e2b0b..9b2239c1b 100644
--- a/include/chameleon/runtime.h
+++ b/include/chameleon/runtime.h
@@ -707,12 +707,13 @@ void RUNTIME_sdisplay_oneprofile (cham_tasktype_t task);
 
 void RUNTIME_ipiv_create ( CHAM_ipiv_t *ipiv );
 void RUNTIME_ipiv_destroy( CHAM_ipiv_t *ipiv );
-void RUNTIME_ipiv_gather ( CHAM_ipiv_t *desc, int *ipiv, int node );
+void RUNTIME_ipiv_gather ( const RUNTIME_sequence_t *sequence,
+                           CHAM_ipiv_t *desc, int *ipiv, int node );
 
 void RUNTIME_ipiv_flushk( const RUNTIME_sequence_t *sequence,
                           const CHAM_ipiv_t *ipiv, int m );
-void RUNTIME_ipiv_flush ( const CHAM_ipiv_t *ipiv,
-                          const RUNTIME_sequence_t *sequence );
+void RUNTIME_ipiv_flush ( const RUNTIME_sequence_t *sequence,
+                          const CHAM_ipiv_t *ipiv );
 void RUNTIME_perm_flushk( const RUNTIME_sequence_t *sequence,
                           const CHAM_ipiv_t *ipiv, int m );
 
diff --git a/runtime/openmp/control/runtime_descriptor_ipiv.c b/runtime/openmp/control/runtime_descriptor_ipiv.c
index 32b74e450..9514b6fd0 100644
--- a/runtime/openmp/control/runtime_descriptor_ipiv.c
+++ b/runtime/openmp/control/runtime_descriptor_ipiv.c
@@ -80,8 +80,8 @@ void RUNTIME_ipiv_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_flush( const CHAM_ipiv_t        *ipiv,
-                         const RUNTIME_sequence_t *sequence )
+void RUNTIME_ipiv_flush( const RUNTIME_sequence_t *sequence,
+                         const CHAM_ipiv_t        *ipiv )
 {
     assert( 0 );
     (void)ipiv;
@@ -97,9 +97,11 @@ void RUNTIME_perm_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_gather( CHAM_ipiv_t *desc, int *ipiv, int node )
+void RUNTIME_ipiv_gather( const RUNTIME_sequence_t *sequence,
+                          CHAM_ipiv_t *desc, int *ipiv, int node )
 {
     assert( 0 );
+    (void)sequence;
     (void)desc;
     (void)ipiv;
     (void)node;
diff --git a/runtime/parsec/control/runtime_descriptor_ipiv.c b/runtime/parsec/control/runtime_descriptor_ipiv.c
index b286df9d2..53621950f 100644
--- a/runtime/parsec/control/runtime_descriptor_ipiv.c
+++ b/runtime/parsec/control/runtime_descriptor_ipiv.c
@@ -80,8 +80,8 @@ void RUNTIME_ipiv_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_flush( const CHAM_ipiv_t        *ipiv,
-                         const RUNTIME_sequence_t *sequence )
+void RUNTIME_ipiv_flush( const RUNTIME_sequence_t *sequence,
+                         const CHAM_ipiv_t        *ipiv )
 {
     assert( 0 );
     (void)ipiv;
@@ -97,9 +97,11 @@ void RUNTIME_perm_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_gather( CHAM_ipiv_t *desc, int *ipiv, int node )
+void RUNTIME_ipiv_gather( const RUNTIME_sequence_t *sequence,
+                          CHAM_ipiv_t *desc, int *ipiv, int node )
 {
     assert( 0 );
+    (void)sequence;
     (void)desc;
     (void)ipiv;
     (void)node;
diff --git a/runtime/quark/control/runtime_descriptor_ipiv.c b/runtime/quark/control/runtime_descriptor_ipiv.c
index 6d5208fa2..9edd6f041 100644
--- a/runtime/quark/control/runtime_descriptor_ipiv.c
+++ b/runtime/quark/control/runtime_descriptor_ipiv.c
@@ -80,8 +80,8 @@ void RUNTIME_ipiv_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_flush( const CHAM_ipiv_t        *ipiv,
-                         const RUNTIME_sequence_t *sequence )
+void RUNTIME_ipiv_flush( const RUNTIME_sequence_t *sequence,
+                         const CHAM_ipiv_t        *ipiv )
 {
     assert( 0 );
     (void)ipiv;
@@ -97,9 +97,11 @@ void RUNTIME_perm_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_gather( CHAM_ipiv_t *desc, int *ipiv, int node )
+void RUNTIME_ipiv_gather( const RUNTIME_sequence_t *sequence,
+                          CHAM_ipiv_t *desc, int *ipiv, int node )
 {
     assert( 0 );
+    (void)sequence;
     (void)desc;
     (void)ipiv;
     (void)node;
diff --git a/runtime/starpu/control/runtime_descriptor_ipiv.c b/runtime/starpu/control/runtime_descriptor_ipiv.c
index ae4a6f24f..640ffa83e 100644
--- a/runtime/starpu/control/runtime_descriptor_ipiv.c
+++ b/runtime/starpu/control/runtime_descriptor_ipiv.c
@@ -249,8 +249,8 @@ void RUNTIME_ipiv_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_flush( const CHAM_ipiv_t        *ipiv,
-                         const RUNTIME_sequence_t *sequence )
+void RUNTIME_ipiv_flush( const RUNTIME_sequence_t *sequence,
+                         const CHAM_ipiv_t        *ipiv )
 {
     int m;
 
@@ -298,7 +298,8 @@ void RUNTIME_perm_flushk( const RUNTIME_sequence_t *sequence,
     (void)m;
 }
 
-void RUNTIME_ipiv_gather( CHAM_ipiv_t *desc, int *ipiv, int node )
+void RUNTIME_ipiv_gather( const RUNTIME_sequence_t *sequence,
+                          CHAM_ipiv_t *desc, int *ipiv, int node )
 {
     int64_t mt   = desc->mt;
     int64_t mb   = desc->mb;
-- 
GitLab