From e91a37f91ea4d5e61067506da7e69b38dafeda11 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Tue, 18 May 2021 19:22:30 +0200
Subject: [PATCH] control/desc: modify descriport internal creation to
 correctly handle descriptor naming

---
 control/descriptor.c     | 29 ++++++++++-------------------
 control/descriptor.h     | 24 ++++++++++++++++++++----
 control/descriptor_rec.c | 10 +++++-----
 3 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/control/descriptor.c b/control/descriptor.c
index 5af45af7f..2a23650bb 100644
--- a/control/descriptor.c
+++ b/control/descriptor.c
@@ -142,6 +142,9 @@ int chameleon_getrankof_2d_diag( const CHAM_desc_t *A, int m, int n )
  *
  ******************************************************************************
  *
+ * @param[in] name
+ *          Name of the descriptor for debug purpose.
+ *
  * @param[in] dtyp
  *          Data type of the matrix:
  *          @arg ChamRealFloat:     single precision real (S),
@@ -155,21 +158,12 @@ int chameleon_getrankof_2d_diag( const CHAM_desc_t *A, int m, int n )
  * @param[in] nb
  *          Number of columns in a tile.
  *
- * @param[in] bsiz
- *          Size in number of elements of each tile, including internal padding.
- *
  * @param[in] lm
  *          Number of rows of the entire matrix.
  *
  * @param[in] ln
  *          Number of columns of the entire matrix.
  *
- * @param[in] i
- *          Row index to the beginning of the submatrix.
- *
- * @param[in] j
- *          Column indes to the beginning of the submatrix.
- *
  * @param[in] m
  *          Number of rows of the submatrix.
  *
@@ -197,22 +191,19 @@ int chameleon_getrankof_2d_diag( const CHAM_desc_t *A, int m, int n )
  * @return  The descriptor with the matrix description parameters set.
  *
  */
-int chameleon_desc_init( CHAM_desc_t *desc, void *mat,
-                         cham_flttype_t dtyp, int mb, int nb, int bsiz,
-                         int lm, int ln, int i, int j,
-                         int m,  int n,  int p, int q,
-                         blkaddr_fct_t   get_blkaddr,
-                         blkldd_fct_t    get_blkldd,
-                         blkrankof_fct_t get_rankof)
+int chameleon_desc_init_internal( CHAM_desc_t *desc, const char *name, void *mat,
+                                  cham_flttype_t dtyp, int mb, int nb,
+                                  int lm, int ln, int m, int n, int p, int q,
+                                  blkaddr_fct_t   get_blkaddr,
+                                  blkldd_fct_t    get_blkldd,
+                                  blkrankof_fct_t get_rankof )
 {
     CHAM_context_t *chamctxt;
     int rc = CHAMELEON_SUCCESS;
 
     memset( desc, 0, sizeof(CHAM_desc_t) );
 
-    assert( i == 0 );
-    assert( j == 0 );
-    assert( bsiz == (mb * nb) );
+    desc->name = name;
 
     chamctxt = chameleon_context_self();
     if (chamctxt == NULL) {
diff --git a/control/descriptor.h b/control/descriptor.h
index 7042fe9f2..fc239a569 100644
--- a/control/descriptor.h
+++ b/control/descriptor.h
@@ -48,16 +48,32 @@ inline static int   chameleon_getblkldd_ccrb(const CHAM_desc_t *A, int m);
 /**
  *  Data distributions
  */
-int          chameleon_getrankof_2d(const CHAM_desc_t *desc, int m, int n);
-int          chameleon_getrankof_2d_diag(const CHAM_desc_t *desc, int m, int n);
+int chameleon_getrankof_2d(const CHAM_desc_t *desc, int m, int n);
+int chameleon_getrankof_2d_diag(const CHAM_desc_t *desc, int m, int n);
 
-int          chameleon_desc_init     ( CHAM_desc_t *desc, void *mat,
+int chameleon_desc_init_internal( CHAM_desc_t *desc, const char *name, void *mat,
+                                  cham_flttype_t dtyp, int mb, int nb,
+                                  int lm, int ln, int m, int n, int p, int q,
+                                  void* (*get_blkaddr)( const CHAM_desc_t*, int, int ),
+                                  int   (*get_blkldd) ( const CHAM_desc_t*, int      ),
+                                  int   (*get_rankof) ( const CHAM_desc_t*, int, int ) );
+
+
+static inline int chameleon_desc_init( CHAM_desc_t *desc, void *mat,
                                        cham_flttype_t dtyp, int mb, int nb, int bsiz,
                                        int lm, int ln, int i, int j,
                                        int m,  int n,  int p, int q,
                                        void* (*get_blkaddr)( const CHAM_desc_t*, int, int ),
                                        int   (*get_blkldd) ( const CHAM_desc_t*, int      ),
-                                       int   (*get_rankof) ( const CHAM_desc_t*, int, int ) );
+                                       int   (*get_rankof) ( const CHAM_desc_t*, int, int ) )
+{
+    assert( i == 0 );
+    assert( j == 0 );
+    assert( mb * nb == bsiz );
+    return chameleon_desc_init_internal( desc, NULL, mat, dtyp, mb, nb, lm, ln, m, n, p, q,
+                                         get_blkaddr, get_blkldd, get_rankof );
+}
+
 CHAM_desc_t* chameleon_desc_submatrix( CHAM_desc_t *descA, int i, int j, int m, int n );
 void         chameleon_desc_destroy  ( CHAM_desc_t *desc );
 int          chameleon_desc_check    ( const CHAM_desc_t *desc );
diff --git a/control/descriptor_rec.c b/control/descriptor_rec.c
index 6820b46ed..496a4f4a0 100644
--- a/control/descriptor_rec.c
+++ b/control/descriptor_rec.c
@@ -36,11 +36,11 @@ chameleon_recdesc_create( const char *name, CHAM_desc_t **descptr, void *mat, ch
     assert( (mb[0] > 0) && (nb[0] > 0) );
 
     /* Create the current layer descriptor */
-    rc = CHAMELEON_Desc_Create_User( descptr, mat, dtyp, mb[0], nb[0], mb[0] * nb[0],
-                                     lm, ln, 0, 0, m, n, 1, 1,
-                                     get_blkaddr, get_blkldd, get_rankof );
-    desc = *descptr;
-    desc->name = name;
+    desc = (CHAM_desc_t*)malloc(sizeof(CHAM_desc_t));
+    rc = chameleon_desc_init_internal( desc, name, mat, dtyp, mb[0], nb[0],
+                                       lm, ln, m, n, 1, 1,
+                                       get_blkaddr, get_blkldd, get_rankof );
+    *descptr = desc;
 
     if ( rc != CHAMELEON_SUCCESS ) {
         return rc;
-- 
GitLab