From 231566f40b74eca26f14f573a7cfd3824797f6a4 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Mon, 15 Jan 2018 17:31:19 +0100
Subject: [PATCH] Remove asynchronous tile_to_lapack

---
 compute/CMakeLists.txt      |   1 -
 compute/pztile.c            | 128 ---------------------------
 compute/ztile.c             | 169 ++++++++----------------------------
 control/morse_zf77.c        |   8 --
 control/morse_zf90.F90      |  52 -----------
 include/chameleon/morse_z.h |   2 -
 6 files changed, 37 insertions(+), 323 deletions(-)
 delete mode 100644 compute/pztile.c

diff --git a/compute/CMakeLists.txt b/compute/CMakeLists.txt
index 0034ceb13..45700455d 100644
--- a/compute/CMakeLists.txt
+++ b/compute/CMakeLists.txt
@@ -235,7 +235,6 @@ set(ZSRC
     ##################
     #pzshift.c
     #pzpack.c
-    pztile.c
     ztile.c
     ##################
     # BUILD
diff --git a/compute/pztile.c b/compute/pztile.c
deleted file mode 100644
index 55c523c0d..000000000
--- a/compute/pztile.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- *
- * @copyright (c) 2009-2014 The University of Tennessee and The University
- *                          of Tennessee Research Foundation.
- *                          All rights reserved.
- * @copyright (c) 2012-2014 Inria. All rights reserved.
- * @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
- *
- **/
-
-/**
- *
- * @file pztile.c
- *
- *  MORSE auxiliary routines
- *  MORSE is a software package provided by Univ. of Tennessee,
- *  Univ. of California Berkeley and Univ. of Colorado Denver
- *
- * @version 0.9.0
- * @author Jakub Kurzak
- * @author Mathieu Faverge
- * @author Cedric Castagnede
- * @date 2010-11-15
- * @precisions normal z -> c d s
- *
- **/
-#include "control/common.h"
-
-#define A(m, n) A, m, n
-#define B(m, n) &B, m, n
-
-/*******************************************************************************
- *  Conversion from LAPACK F77 matrix layout to tile layout - dynamic scheduling
- **/
-void morse_pzlapack_to_tile(MORSE_Complex64_t *Af77, int ldaf77, MORSE_desc_t *A,
-                            MORSE_sequence_t *sequence, MORSE_request_t *request)
-{
-    MORSE_context_t *morse;
-    MORSE_option_t options;
-    MORSE_desc_t B;
-    int m, n;
-    int ldam;
-    int tempmm, tempnn;
-
-    morse = morse_context_self();
-    if (sequence->status != MORSE_SUCCESS)
-        return;
-    RUNTIME_options_init(&options, morse, sequence, request);
-
-    B = morse_desc_init(
-        MorseComplexDouble, A->mb, A->nb, A->bsiz,
-        ldaf77, A->n, 0, 0, A->m, A->n, 1, 1);
-
-    B.get_blkaddr = morse_getaddr_cm;
-    B.get_blkldd  = morse_getblkldd_cm;
-    B.mat = Af77;
-    B.styp = MorseCM;
-
-    RUNTIME_desc_create( &B );
-
-    for (m = 0; m < A->mt; m++) {
-        tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
-        ldam = BLKLDD(A, m);
-        for (n = 0; n < A->nt; n++) {
-            tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
-            MORSE_TASK_zlacpy(
-                &options,
-                MorseUpperLower,
-                tempmm, tempnn, A->mb,
-                B(m, n), ldaf77,
-                A(m, n), ldam);
-        }
-    }
-
-    RUNTIME_desc_flush( &B, sequence );
-    RUNTIME_sequence_wait( morse, sequence );
-    RUNTIME_options_finalize( &options, morse );
-    RUNTIME_desc_destroy( &B );
-}
-
-/*******************************************************************************
- *  Conversion from LAPACK F77 matrix layout to tile layout - dynamic scheduling
- **/
-void morse_pztile_to_lapack(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int ldaf77,
-                            MORSE_sequence_t *sequence, MORSE_request_t *request)
-{
-    MORSE_context_t *morse;
-    MORSE_option_t options;
-    MORSE_desc_t B;
-    int m, n;
-    int ldam;
-    int tempmm, tempnn;
-
-    morse = morse_context_self();
-    if (sequence->status != MORSE_SUCCESS)
-        return;
-    RUNTIME_options_init(&options, morse, sequence, request);
-
-    B = morse_desc_init(
-        MorseComplexDouble, A->mb, A->nb, A->bsiz,
-        ldaf77, A->n, 0, 0, A->m, A->n, 1, 1);
-
-    B.get_blkaddr = morse_getaddr_cm;
-    B.get_blkldd  = morse_getblkldd_cm;
-    B.mat  = Af77;
-    B.styp = MorseCM;
-
-    RUNTIME_desc_create( &B );
-
-    for (m = 0; m < A->mt; m++) {
-        tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
-        ldam = BLKLDD(A, m);
-        for (n = 0; n < A->nt; n++) {
-            tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
-            MORSE_TASK_zlacpy(
-                &options,
-                MorseUpperLower,
-                tempmm, tempnn, A->mb,
-                A(m, n), ldam,
-                B(m, n), ldaf77);
-        }
-    }
-
-    RUNTIME_desc_flush( &B, sequence );
-    RUNTIME_sequence_wait( morse, sequence );
-    RUNTIME_options_finalize( &options, morse );
-    RUNTIME_desc_destroy( &B );
-}
diff --git a/compute/ztile.c b/compute/ztile.c
index 5377a7864..d23d9b6b8 100644
--- a/compute/ztile.c
+++ b/compute/ztile.c
@@ -55,7 +55,6 @@
  *
  *******************************************************************************
  *
- * @sa MORSE_zLapack_to_Tile_Async
  * @sa MORSE_zTile_to_Lapack
  * @sa MORSE_cLapack_to_Tile
  * @sa MORSE_dLapack_to_Tile
@@ -67,6 +66,7 @@ int MORSE_zLapack_to_Tile(MORSE_Complex64_t *Af77, int LDA, MORSE_desc_t *A)
     MORSE_context_t *morse;
     MORSE_sequence_t *sequence = NULL;
     MORSE_request_t request;
+    MORSE_desc_t B;
     int status;
 
     morse = morse_context_self();
@@ -79,81 +79,33 @@ int MORSE_zLapack_to_Tile(MORSE_Complex64_t *Af77, int LDA, MORSE_desc_t *A)
         morse_error("MORSE_zLapack_to_Tile", "invalid descriptor");
         return MORSE_ERR_ILLEGAL_VALUE;
     }
+
+    /* Create the B descriptor to handle the Lapack format matrix */
+    B = morse_desc_init_user(
+        MorseComplexDouble, A->mb, A->nb, A->bsiz,
+        LDA, A->n, 0, 0, A->m, A->n, 1, 1,
+        morse_getaddr_cm, morse_getblkldd_cm, NULL );
+    B.mat  = Af77;
+    B.styp = MorseCM;
+
+    RUNTIME_desc_create( &B );
+
+    /* Start the computation */
     morse_sequence_create(morse, &sequence);
 
-    morse_pzlapack_to_tile( Af77, LDA, A, sequence, &request);
+    morse_pzlacpy( MorseUpperLower, &B, A, sequence, &request );
 
-    RUNTIME_desc_flush( A, sequence );
+    RUNTIME_desc_flush( &B, sequence );
+    RUNTIME_desc_flush(  A, sequence );
     RUNTIME_sequence_wait( morse, sequence );
 
+    RUNTIME_desc_destroy( &B );
+
     status = sequence->status;
     morse_sequence_destroy(morse, sequence);
     return status;
 }
 
-/**
- ********************************************************************************
- *
- * @ingroup MORSE_Complex64_t_Tile_Async
- *
- *  MORSE_zLapack_to_Tile_Async - Conversion from LAPACK layout to tile layout.
- *  Non-blocking equivalent of MORSE_zLapack_to_Tile().
- *  May return before the computation is finished.
- *  Allows for pipelining of operations ar runtime.
- *
- *
- *******************************************************************************
- *
- * @param[in] Af77
- *          LAPACK matrix.
- *
- * @param[in] LDA
- *          The leading dimension of the matrix Af77.
- *
- * @param[in,out] A
- *          Descriptor of the MORSE matrix in tile layout.
- *          If MORSE_TRANSLATION_MODE is set to MORSE_INPLACE,
- *          A->mat is not used and set to Af77 when returns, else if
- *          MORSE_TRANSLATION_MODE is set to MORSE_OUTOFPLACE,
- *          A->mat has to be allocated before.
- *
- * @param[in] sequence
- *          Identifies the sequence of function calls that this call belongs to
- *          (for completion checks and exception handling purposes).
- *
- * @param[out] request
- *          Identifies this function call (for exception handling purposes).
- *
- *******************************************************************************
- *
- * @sa MORSE_zTile_to_Lapack_Async
- * @sa MORSE_zLapack_to_Tile
- * @sa MORSE_cLapack_to_Tile_Async
- * @sa MORSE_dLapack_to_Tile_Async
- * @sa MORSE_sLapack_to_Tile_Async
- *
- ******************************************************************************/
-int MORSE_zLapack_to_Tile_Async(MORSE_Complex64_t *Af77, int LDA, MORSE_desc_t *A,
-                                  MORSE_sequence_t *sequence, MORSE_request_t *request)
-{
-    MORSE_context_t *morse;
-
-    morse = morse_context_self();
-    if (morse == NULL) {
-        morse_fatal_error("MORSE_zLapack_to_Tile", "MORSE not initialized");
-        return MORSE_ERR_NOT_INITIALIZED;
-    }
-    /* Check descriptor for correctness */
-    if (morse_desc_check( A ) != MORSE_SUCCESS) {
-        morse_error("MORSE_zLapack_to_Tile", "invalid descriptor");
-        return MORSE_ERR_ILLEGAL_VALUE;
-    }
-
-    morse_pzlapack_to_tile( Af77, LDA, A, sequence, request);
-
-    return MORSE_SUCCESS;
-}
-
 /**
  ********************************************************************************
  *
@@ -183,7 +135,6 @@ int MORSE_zLapack_to_Tile_Async(MORSE_Complex64_t *Af77, int LDA, MORSE_desc_t *
  *
  *******************************************************************************
  *
- * @sa MORSE_zTile_to_Lapack_Async
  * @sa MORSE_zLapack_to_Tile
  * @sa MORSE_cTile_to_Lapack
  * @sa MORSE_dTile_to_Lapack
@@ -195,6 +146,7 @@ int MORSE_zTile_to_Lapack(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int LDA)
     MORSE_context_t *morse;
     MORSE_sequence_t *sequence = NULL;
     MORSE_request_t request;
+    MORSE_desc_t B;
     int status;
 
     morse = morse_context_self();
@@ -207,76 +159,29 @@ int MORSE_zTile_to_Lapack(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int LDA)
         morse_error("MORSE_zTile_to_Lapack", "invalid descriptor");
         return MORSE_ERR_ILLEGAL_VALUE;
     }
+
+    /* Create the B descriptor to handle the Lapack format matrix */
+    B = morse_desc_init_user(
+        MorseComplexDouble, A->mb, A->nb, A->bsiz,
+        LDA, A->n, 0, 0, A->m, A->n, 1, 1,
+        morse_getaddr_cm, morse_getblkldd_cm, NULL );
+    B.mat  = Af77;
+    B.styp = MorseCM;
+
+    RUNTIME_desc_create( &B );
+
+    /* Start the computation */
     morse_sequence_create(morse, &sequence);
 
-    morse_pztile_to_lapack( A, Af77, LDA, sequence, &request);
-    RUNTIME_desc_flush( A, sequence );
+    morse_pzlacpy( MorseUpperLower, A, &B, sequence, &request );
+
+    RUNTIME_desc_flush(  A, sequence );
+    RUNTIME_desc_flush( &B, sequence );
     RUNTIME_sequence_wait( morse, sequence );
 
+    RUNTIME_desc_destroy( &B );
+
     status = sequence->status;
     morse_sequence_destroy(morse, sequence);
     return status;
 }
-
-/**
- ********************************************************************************
- *
- * @ingroup MORSE_Complex64_t_Tile_Async
- *
- *  MORSE_zTile_to_Lapack_Async - Conversion from LAPACK layout to tile layout.
- *  Non-blocking equivalent of MORSE_zTile_to_Lapack().
- *  May return before the computation is finished.
- *  Allows for pipelining of operations ar runtime.
- *
- *
- *******************************************************************************
- *
- * @param[in] A
- *          Descriptor of the MORSE matrix in tile layout.
- *
- * @param[in,out] Af77
- *          LAPACK matrix.
- *          If MORSE_TRANSLATION_MODE is set to MORSE_INPLACE,
- *          Af77 has to be A->mat, else if
- *          MORSE_TRANSLATION_MODE is set to MORSE_OUTOFPLACE,
- *          Af77 has to be allocated before.
- *
- * @param[in] LDA
- *          The leading dimension of the matrix Af77.
- *
- * @param[in] sequence
- *          Identifies the sequence of function calls that this call belongs to
- *          (for completion checks and exception handling purposes).
- *
- * @param[out] request
- *          Identifies this function call (for exception handling purposes).
- *
- *******************************************************************************
- *
- * @sa MORSE_zLapack_to_Tile_Async
- * @sa MORSE_zTile_to_Lapack
- * @sa MORSE_cTile_to_Lapack_Async
- * @sa MORSE_dTile_to_Lapack_Async
- * @sa MORSE_sTile_to_Lapack_Async
- *
- ******************************************************************************/
-int MORSE_zTile_to_Lapack_Async(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int LDA,
-                                MORSE_sequence_t *sequence, MORSE_request_t *request)
-{
-    MORSE_context_t *morse;
-
-    morse = morse_context_self();
-    if (morse == NULL) {
-        morse_fatal_error("MORSE_zTile_to_Lapack", "MORSE not initialized");
-        return MORSE_ERR_NOT_INITIALIZED;
-    }
-    /* Check descriptor for correctness */
-    if (morse_desc_check( A ) != MORSE_SUCCESS) {
-        morse_error("MORSE_zTile_to_Lapack", "invalid descriptor");
-        return MORSE_ERR_ILLEGAL_VALUE;
-    }
-
-    morse_pztile_to_lapack( A, Af77, LDA, sequence, request );
-
-    return MORSE_SUCCESS;
-}
diff --git a/control/morse_zf77.c b/control/morse_zf77.c
index 8ea877f35..c9013dcc4 100644
--- a/control/morse_zf77.c
+++ b/control/morse_zf77.c
@@ -40,9 +40,7 @@
  *  FORTRAN API - math functions (simple interface)
  **/
 #define MORSE_ZLAPACK_TO_TILE MORSE_FNAME(zlapack_to_tile, ZLAPACK_TO_TILE)
-#define MORSE_ZLAPACK_TO_TILE_ASYNC MORSE_FNAME(zlapack_to_tile_async, ZLAPACK_TO_TILE_ASYNC)
 #define MORSE_ZTILE_TO_LAPACK MORSE_FNAME(ztile_to_lapack, ZTILE_TO_LAPACK)
-#define MORSE_ZTILE_TO_LAPACK_ASYNC MORSE_FNAME(ztile_to_lapack_async, ZTILE_TO_LAPACK_ASYNC)
 //#define MORSE_ZGEBRD          MORSE_FNAME(zgebrd       , ZGEBRD       )
 //#define MORSE_ZGECFI          MORSE_FNAME(zgecfi       , ZGECFI       )
 //#define MORSE_ZGECFI_ASYNC    MORSE_FNAME(zgecfi_async , ZGECFI_ASYNC )
@@ -293,15 +291,9 @@
 void MORSE_ZLAPACK_TO_TILE(MORSE_Complex64_t *Af77, int *LDA, MORSE_desc_t *A, int *info)
 { *info = MORSE_zLapack_to_Tile(Af77, *LDA, A); }
 
-void MORSE_ZLAPACK_TO_TILE_ASYNC(MORSE_Complex64_t *Af77, int *LDA, MORSE_desc_t *A, MORSE_sequence_t *sequence, MORSE_request_t *request, int *info)
-{ *info = MORSE_zLapack_to_Tile_Async(Af77, *LDA, A, sequence, request); }
-
 void MORSE_ZTILE_TO_LAPACK(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int *LDA, int *info)
 { *info = MORSE_zTile_to_Lapack(A, Af77, *LDA); }
 
-void MORSE_ZTILE_TO_LAPACK_ASYNC(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int *LDA, MORSE_sequence_t *sequence, MORSE_request_t *request, int *info)
-{ *info = MORSE_zTile_to_Lapack_Async(A, Af77, *LDA, sequence, request); }
-
 //void MORSE_ZGEBRD(int *M, int *N, MORSE_Complex64_t *A, int *LDA, double *D, double *E, MORSE_desc_t **descT, int *info)
 //{ *info = MORSE_zgebrd(*M, *N, A, *LDA, D, E, *descT); }
 //
diff --git a/control/morse_zf90.F90 b/control/morse_zf90.F90
index 78c4631dd..c9bf4035a 100644
--- a/control/morse_zf90.F90
+++ b/control/morse_zf90.F90
@@ -96,20 +96,6 @@ module morse_z
           end function MORSE_zLapack_to_Tile_c
       end interface
 
-      interface
-         function MORSE_zLapack_to_Tile_Async_c(Af77,LDA,A,sequence,request) &
-          & bind(c, name='MORSE_zLapack_to_Tile_Async')
-            use iso_c_binding
-            implicit none
-            integer(kind=c_int) :: MORSE_zLapack_to_Tile_Async_c
-            type(c_ptr), value :: Af77
-            integer(kind=c_int), value :: LDA
-            type(c_ptr), value :: A
-            type(c_ptr), value :: sequence
-            type(c_ptr), value :: request
-          end function MORSE_zLapack_to_Tile_Async_c
-      end interface
-
       interface
          function MORSE_zTile_to_Lapack_c(A,Af77,LDA) &
           & bind(c, name='MORSE_zTile_to_Lapack')
@@ -122,20 +108,6 @@ module morse_z
           end function MORSE_zTile_to_Lapack_c
       end interface
 
-      interface
-         function MORSE_zTile_to_Lapack_Async_c(A,Af77,LDA,sequence,request) &
-          & bind(c, name='MORSE_zTile_to_Lapack_Async')
-            use iso_c_binding
-            implicit none
-            integer(kind=c_int) :: MORSE_zTile_to_Lapack_Async_c
-            type(c_ptr), value :: A
-            type(c_ptr), value :: Af77
-            integer(kind=c_int), value :: LDA
-            type(c_ptr), value :: sequence
-            type(c_ptr), value :: request
-          end function MORSE_zTile_to_Lapack_Async_c
-      end interface
-
       interface
          function MORSE_zgebrd_c(M,N,A,LDA,D,E,descT) &
           & bind(c, name='MORSE_zgebrd')
@@ -5507,28 +5479,4 @@ module morse_z
          info = MORSE_zTile_to_Lapack_c(A,c_loc(Af77),LDA)
       end subroutine MORSE_zTile_to_Lapack
 
-      subroutine MORSE_zLapack_to_Tile_Async(Af77,LDA,A,sequence,request,info)
-         use iso_c_binding
-         implicit none
-         integer(kind=c_int), intent(out) :: info
-         integer(kind=c_int), intent(in) :: LDA
-         complex(kind=c_double_complex), intent(in), target :: Af77(LDA,*)
-         type(c_ptr), value :: A ! Arg managed by MORSE: opaque to Fortran
-         type(c_ptr), value :: request ! Arg managed by MORSE: opaque to Fortran
-         type(c_ptr), value :: sequence ! Arg managed by MORSE: opaque to Fortran
-         info = MORSE_zLapack_to_Tile_Async_c(c_loc(Af77),LDA,A,sequence,request)
-      end subroutine MORSE_zLapack_to_Tile_Async
-
-      subroutine MORSE_zTile_to_Lapack_Async(A,Af77,LDA,sequence,request,info)
-         use iso_c_binding
-         implicit none
-         integer(kind=c_int), intent(out) :: info
-         integer(kind=c_int), intent(in) :: LDA
-         complex(kind=c_double_complex), intent(out), target :: Af77(LDA,*)
-         type(c_ptr), value :: A ! Arg managed by MORSE: opaque to Fortran
-         type(c_ptr), value :: request ! Arg managed by MORSE: opaque to Fortran
-         type(c_ptr), value :: sequence ! Arg managed by MORSE: opaque to Fortran
-         info = MORSE_zTile_to_Lapack_Async_c(A,c_loc(Af77),LDA,sequence,request)
-      end subroutine MORSE_zTile_to_Lapack_Async
-
 end module morse_z
diff --git a/include/chameleon/morse_z.h b/include/chameleon/morse_z.h
index 89e0be9c8..2c504d544 100644
--- a/include/chameleon/morse_z.h
+++ b/include/chameleon/morse_z.h
@@ -349,8 +349,6 @@ int MORSE_Alloc_Workspace_zgetrf_incpiv_Tile(int N, MORSE_desc_t **descL, int **
  **/
 int MORSE_zLapack_to_Tile(MORSE_Complex64_t *Af77, int LDA, MORSE_desc_t *A);
 int MORSE_zTile_to_Lapack(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int LDA);
-int MORSE_zLapack_to_Tile_Async(MORSE_Complex64_t *Af77, int LDA, MORSE_desc_t *A, MORSE_sequence_t *sequence, MORSE_request_t *request);
-int MORSE_zTile_to_Lapack_Async(MORSE_desc_t *A, MORSE_Complex64_t *Af77, int LDA, MORSE_sequence_t *sequence, MORSE_request_t *request);
 
 /** ****************************************************************************
  *  User Builder function prototypes
-- 
GitLab