From 2e09db0d604755ab18a1f8cd3d8f89fadff44372 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Wed, 12 May 2021 16:30:33 +0200
Subject: [PATCH] starpu/descriptor: fix unregister/flush

---
 runtime/starpu/control/runtime_descriptor.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/runtime/starpu/control/runtime_descriptor.c b/runtime/starpu/control/runtime_descriptor.c
index 2ed7183a7..cca1e2dc3 100644
--- a/runtime/starpu/control/runtime_descriptor.c
+++ b/runtime/starpu/control/runtime_descriptor.c
@@ -241,8 +241,8 @@ void RUNTIME_desc_destroy( CHAM_desc_t *desc )
         for (n = 0; n < lnt; n++) {
             for (m = 0; m < lmt; m++)
             {
-                if (*handle != NULL) {
-                    starpu_data_unregister(*handle);
+                if ( *handle != NULL ) {
+                    starpu_data_unregister_submit(*handle);
                     *handle = NULL;
                 }
                 handle++;
@@ -384,14 +384,25 @@ void RUNTIME_data_flush( const RUNTIME_sequence_t *sequence,
 {
     int64_t mm = m + (A->i / A->mb);
     int64_t nn = n + (A->j / A->nb);
-
-    starpu_data_handle_t *handle = A->schedopt;
-    handle += ((int64_t)A->lmt) * nn + mm;
+    int64_t shift = ((int64_t)A->lmt) * nn + mm;
+    starpu_data_handle_t *handle = A->schedopt + shift;
+    CHAM_tile_t          *tile   = A->tiles    + shift;
 
     if (*handle == NULL) {
         return;
     }
 
+    /*
+     * TODO: check later, a better check would be to check if we
+     * partitionned the handle or not
+     *
+     * Right now, we can't flush a partitionned handle, we would need to
+     * unpartition first, so we flush only the children.
+     */
+    if ( tile->format & CHAMELEON_TILE_DESC ) {
+        CHAMELEON_Desc_Flush( tile->mat, sequence );
+    }
+
 #if defined(CHAMELEON_USE_MPI)
     starpu_mpi_cache_flush( MPI_COMM_WORLD, *handle );
 #endif
-- 
GitLab