From 3870fdd5937856a11d06bc7a92ed67af0bfddc0f Mon Sep 17 00:00:00 2001
From: Alycia Lisito <alycia.lisito@inria.fr>
Date: Wed, 2 Feb 2022 15:35:23 +0100
Subject: [PATCH] testing: poinv

---
 testing/CMakeLists.txt   |   1 +
 testing/CTestLists.cmake |   2 +-
 testing/input/poinv.in   |  17 ++++++
 testing/testing_zpoinv.c | 111 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 130 insertions(+), 1 deletion(-)
 create mode 100644 testing/input/poinv.in
 create mode 100644 testing/testing_zpoinv.c

diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt
index 78f4f507e..75450771b 100644
--- a/testing/CMakeLists.txt
+++ b/testing/CMakeLists.txt
@@ -73,6 +73,7 @@ set(ZSRC
   testing_ztrtri.c
   testing_zlauum.c
   testing_zpotri.c
+  testing_zpoinv.c
   testing_zsytrf.c
   testing_zsytrs.c
   testing_zsysv.c
diff --git a/testing/CTestLists.cmake b/testing/CTestLists.cmake
index a749e7a47..70be7851f 100644
--- a/testing/CTestLists.cmake
+++ b/testing/CTestLists.cmake
@@ -40,7 +40,7 @@ if (NOT CHAMELEON_SIMULATION)
     set( TESTS ${TESTS}
       potrf potrs posv trtri lauum )
     if ( NOT CHAMELEON_SCHED_PARSEC )
-      set( TESTS ${TESTS} potri )
+      set( TESTS ${TESTS} potri poinv)
     endif()
     if ( ${prec} STREQUAL c OR ${prec} STREQUAL z )
       set( TESTS ${TESTS}
diff --git a/testing/input/poinv.in b/testing/input/poinv.in
new file mode 100644
index 000000000..6aeda5d54
--- /dev/null
+++ b/testing/input/poinv.in
@@ -0,0 +1,17 @@
+# You can enumerate each parameter's values as an explicit list separated by commas or by a range start:end[:step]
+# Not given parameters will receive default values
+
+# POINV
+
+# nb: Tile size
+# ib: Inner tile size
+# n: Order of the matrix A
+# lda: Leading dimension of matrix A
+# uplo: Matrix part to be considered (0: Upper, 1: Lower)
+
+op = poinv
+nb = 16, 17
+ib = 8
+n = 15, 19, 37
+lda = 41
+uplo = 0,1
diff --git a/testing/testing_zpoinv.c b/testing/testing_zpoinv.c
new file mode 100644
index 000000000..8abc4e85b
--- /dev/null
+++ b/testing/testing_zpoinv.c
@@ -0,0 +1,111 @@
+/**
+ *
+ * @file testing_zpoinv.c
+ *
+ * @copyright 2019-2022 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
+ *                      Univ. Bordeaux. All rights reserved.
+ *
+ ***
+ *
+ * @brief Chameleon zpoinv testing
+ *
+ * @version 1.1.0
+ * @author Lucas Barros de Assis
+ * @author Florent Pruvost
+ * @author Mathieu Faverge
+ * @author Alycia Lisito
+ * @date 2022-02-02
+ * @precisions normal z -> c d s
+ *
+ */
+#include <chameleon.h>
+#include <assert.h>
+#include "testings.h"
+#include "testing_zcheck.h"
+#include <chameleon/flops.h>
+
+static cham_fixdbl_t
+flops_zpoinv( int N )
+{
+    cham_fixdbl_t flops = flops_zpotrf( N ) + flops_zpotri( N );
+    return flops;
+}
+
+int
+testing_zpoinv( run_arg_list_t *args, int check )
+{
+    testdata_t test_data = { .args = args };
+    int        hres      = 0;
+
+    /* Read arguments */
+    int         async  = parameters_getvalue_int( "async" );
+    intptr_t    mtxfmt = parameters_getvalue_int( "mtxfmt" );
+    int         nb     = run_arg_get_int( args, "nb", 320 );
+    int         P      = parameters_getvalue_int( "P" );
+    cham_uplo_t uplo   = run_arg_get_uplo( args, "uplo", ChamUpper );
+    int         N      = run_arg_get_int( args, "N", 1000 );
+    int         LDA    = run_arg_get_int( args, "LDA", N );
+    int         seedA  = run_arg_get_int( args, "seedA", random() );
+    int         Q      = parameters_compute_q( P );
+
+    /* Descriptors */
+    CHAM_desc_t *descA;
+
+    CHAMELEON_Set( CHAMELEON_TILE_SIZE, nb );
+
+    /* Create the matrices */
+    CHAMELEON_Desc_Create(
+        &descA, (void*)(-mtxfmt), ChamComplexDouble, nb, nb, nb * nb, LDA, N, 0, 0, N, N, P, Q );
+
+    /* Initialise the matrix with the random values */
+    CHAMELEON_zplghe_Tile( (double)N, uplo, descA, seedA );
+
+    /* Calculates the inversed matrix */
+    testing_start( &test_data );
+    if ( async ) {
+        hres = CHAMELEON_zpoinv_Tile_Async( uplo, descA, test_data.sequence, &test_data.request );
+        CHAMELEON_Desc_Flush( descA, test_data.sequence );
+    }
+    else {
+        hres = CHAMELEON_zpoinv_Tile( uplo, descA );
+    }
+    test_data.hres = hres;
+    testing_stop( &test_data, flops_zpoinv( N ) );
+
+    /* Check the inverse */
+    if ( check ) {
+        CHAM_desc_t *descA0 = CHAMELEON_Desc_Copy( descA, NULL );
+        CHAMELEON_zplghe_Tile( (double)N, uplo, descA0, seedA );
+
+        hres += check_ztrtri( args, ChamHermitian, uplo, ChamNonUnit, descA0, descA );
+
+        CHAMELEON_Desc_Destroy( &descA0 );
+    }
+
+    CHAMELEON_Desc_Destroy( &descA );
+
+    return hres;
+}
+
+testing_t   test_zpoinv;
+const char *zpoinv_params[] = { "mtxfmt", "nb", "uplo", "n", "lda", "seedA", NULL };
+const char *zpoinv_output[] = { NULL };
+const char *zpoinv_outchk[] = { "RETURN", NULL };
+
+/**
+ * @brief Testing registration function
+ */
+void testing_zpoinv_init( void ) __attribute__( ( constructor ) );
+void
+testing_zpoinv_init( void )
+{
+    test_zpoinv.name   = "zpoinv";
+    test_zpoinv.helper = "Hermitian positive definite matrix inversion";
+    test_zpoinv.params = zpoinv_params;
+    test_zpoinv.output = zpoinv_output;
+    test_zpoinv.outchk = zpoinv_outchk;
+    test_zpoinv.fptr   = testing_zpoinv;
+    test_zpoinv.next   = NULL;
+
+    testing_register( &test_zpoinv );
+}
-- 
GitLab