From feadc954b839a839a690faad115eaa12aae7fd3d Mon Sep 17 00:00:00 2001
From: Alycia Lisito <alycia.lisito@inria.fr>
Date: Mon, 7 Feb 2022 09:42:41 +0100
Subject: [PATCH] testing: add standard api to potrs

---
 testing/testing_zpotrs.c | 65 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 62 insertions(+), 3 deletions(-)

diff --git a/testing/testing_zpotrs.c b/testing/testing_zpotrs.c
index eff869463..cb7b2715e 100644
--- a/testing/testing_zpotrs.c
+++ b/testing/testing_zpotrs.c
@@ -2,7 +2,7 @@
  *
  * @file testing_zpotrs.c
  *
- * @copyright 2019-2021 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
+ * @copyright 2019-2022 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
  *                      Univ. Bordeaux. All rights reserved.
  *
  ***
@@ -12,7 +12,8 @@
  * @version 1.1.0
  * @author Lucas Barros de Assis
  * @author Mathieu Faverge
- * @date 2020-11-19
+ * @author Alycia Lisito
+ * @date 2022-02-07
  * @precisions normal z -> c d s
  *
  */
@@ -94,6 +95,64 @@ testing_zpotrs_desc( run_arg_list_t *args, int check )
     return hres;
 }
 
+int
+testing_zpotrs_std( run_arg_list_t *args, int check )
+{
+    testdata_t test_data = { .args = args };
+    int        hres      = 0;
+
+    /* Read arguments */
+    int         nb    = run_arg_get_int( args, "nb", 320 );
+    cham_uplo_t uplo  = run_arg_get_uplo( args, "uplo", ChamUpper );
+    int         N     = run_arg_get_int( args, "N", 1000 );
+    int         NRHS  = run_arg_get_int( args, "NRHS", 1 );
+    int         LDA   = run_arg_get_int( args, "LDA", N );
+    int         LDB   = run_arg_get_int( args, "LDB", N );
+    int         seedA = run_arg_get_int( args, "seedA", random() );
+    int         seedB = run_arg_get_int( args, "seedB", random() );
+
+    /* Descriptors */
+    CHAMELEON_Complex64_t *A, *X;
+
+    CHAMELEON_Set( CHAMELEON_TILE_SIZE, nb );
+
+    /* Creates the matrices */
+    A = malloc( LDA*N*sizeof(CHAMELEON_Complex64_t) );
+    X = malloc( LDB*NRHS*sizeof(CHAMELEON_Complex64_t) );
+
+    /* Fills the matrix with random values */
+    CHAMELEON_zplghe( (double)N, uplo, N, A, LDA, seedA );
+    CHAMELEON_zplrnt( N, NRHS, X, LDB, seedB );
+
+    hres = CHAMELEON_zpotrf( uplo, N, A, LDA );
+    assert( hres == 0 );
+
+    /* Calculates the solution */
+    testing_start( &test_data );
+    hres += CHAMELEON_zpotrs( uplo, N, NRHS, A, LDA, X, LDB );
+    test_data.hres = hres;
+    testing_stop( &test_data, flops_zpotrs( N, NRHS ) );
+
+    /* Checks the factorisation and residue */
+    if ( check ) {
+        CHAMELEON_Complex64_t *A0 = malloc( LDA*N*sizeof(CHAMELEON_Complex64_t) );
+        CHAMELEON_Complex64_t *X0  = malloc( LDB*NRHS*sizeof(CHAMELEON_Complex64_t) );
+
+        CHAMELEON_zplghe( (double)N, uplo, N, A0, LDA, seedA );
+        CHAMELEON_zplrnt( N, NRHS, X0, LDB, seedB );
+
+        // hres += check_zsolve( args, ChamHermitian, ChamNoTrans, uplo, descA0, descX, descB );
+
+        free( A0 );
+        free( X0 );
+    }
+
+    free( A );
+    free( X );
+
+    return hres;
+}
+
 testing_t   test_zpotrs;
 const char *zpotrs_params[] = { "mtxfmt", "nb",  "uplo",  "n",     "nrhs",
                                 "lda",    "ldb", "seedA", "seedB", NULL };
@@ -113,7 +172,7 @@ testing_zpotrs_init( void )
     test_zpotrs.output = zpotrs_output;
     test_zpotrs.outchk = zpotrs_outchk;
     test_zpotrs.fptr_desc = testing_zpotrs_desc;
-    test_zpotrs.fptr_std  = NULL;
+    test_zpotrs.fptr_std  = testing_zpotrs_std;
     test_zpotrs.next   = NULL;
 
     testing_register( &test_zpotrs );
-- 
GitLab