From cf11425187c27cd3c7667af4c8fc6491bcd7ebd7 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Wed, 7 Feb 2018 13:49:29 +0100
Subject: [PATCH] Remove paste_code_allocate_matrix from step examples to
 simplify them and remove the bug in sonarqube about the matrix free not done

---
 example/lapack_to_morse/step0.c | 10 +++++-----
 example/lapack_to_morse/step0.h | 11 -----------
 example/lapack_to_morse/step1.c |  8 ++++----
 example/lapack_to_morse/step1.h | 11 -----------
 example/lapack_to_morse/step2.c |  8 ++++----
 example/lapack_to_morse/step2.h | 11 -----------
 6 files changed, 13 insertions(+), 46 deletions(-)

diff --git a/example/lapack_to_morse/step0.c b/example/lapack_to_morse/step0.c
index f5cbfc344..6879a1ef1 100644
--- a/example/lapack_to_morse/step0.c
+++ b/example/lapack_to_morse/step0.c
@@ -71,9 +71,10 @@ int main(int argc, char *argv[]) {
      *     - set of RHS vectors B       : size N x NRHS
      *     - set of solutions vectors X : size N x NRHS
      */
-    PASTE_CODE_ALLOCATE_MATRIX( A, double, N, N    );
-    PASTE_CODE_ALLOCATE_MATRIX( B, double, N, NRHS );
-    PASTE_CODE_ALLOCATE_MATRIX( X, double, N, NRHS );
+    double *A    = malloc( N * N    * sizeof(double) );
+    double *Acpy = malloc( N * N    * sizeof(double) );
+    double *B    = malloc( N * NRHS * sizeof(double) );
+    double *X    = malloc( N * NRHS * sizeof(double) );
 
     /* generate A matrix with random values such that it is spd */
     CORE_dplgsy( (double)N, N, N, A, N, N, N, N, 51 );
@@ -82,8 +83,7 @@ int main(int argc, char *argv[]) {
     CORE_dplrnt( N, NRHS, B, N, N, N, NRHS, 5673 );
 
     /* copy A before facto. in order to check the result */
-    PASTE_CODE_ALLOCATE_MATRIX( Acpy, double, N, N );
-    memcpy(Acpy, A, N*N*sizeof(double));
+    memcpy(Acpy, A, N * N * sizeof(double));
 
     /* copy B in X before solving */
     memcpy(X, B, N*NRHS*sizeof(double));
diff --git a/example/lapack_to_morse/step0.h b/example/lapack_to_morse/step0.h
index 7ca738891..0f3f87672 100644
--- a/example/lapack_to_morse/step0.h
+++ b/example/lapack_to_morse/step0.h
@@ -120,15 +120,4 @@ static void print_header(char *prog_name, int * iparam) {
     return;
 }
 
-/**
- * Macro to allocate a matrix as a 1D array
- */
-#define PASTE_CODE_ALLOCATE_MATRIX(_name_, _type_, _m_, _n_)    \
-    _type_ *_name_ = NULL;                                      \
-    _name_ = (_type_*)malloc( (_m_) * (_n_) * sizeof(_type_) ); \
-    if ( ! _name_ ) {                                           \
-        fprintf(stderr, "Out of Memory for %s\n", #_name_);     \
-        return -1;                                              \
-    }
-
 #endif /* STEP0_H */
diff --git a/example/lapack_to_morse/step1.c b/example/lapack_to_morse/step1.c
index 930055a76..6099a6f9a 100644
--- a/example/lapack_to_morse/step1.c
+++ b/example/lapack_to_morse/step1.c
@@ -93,10 +93,10 @@ int main(int argc, char *argv[]) {
      *     - set of RHS vectors B       : size N x NRHS
      *     - set of solutions vectors X : size N x NRHS
      */
-    PASTE_CODE_ALLOCATE_MATRIX( A, double, N, N    );
-    PASTE_CODE_ALLOCATE_MATRIX( B, double, N, NRHS );
-    PASTE_CODE_ALLOCATE_MATRIX( X, double, N, NRHS );
-    PASTE_CODE_ALLOCATE_MATRIX( Acpy, double, N, N );
+    double *A    = malloc( N * N    * sizeof(double) );
+    double *Acpy = malloc( N * N    * sizeof(double) );
+    double *B    = malloc( N * NRHS * sizeof(double) );
+    double *X    = malloc( N * NRHS * sizeof(double) );
 
     /* generate A matrix with random values such that it is spd */
     MORSE_dplgsy( (double)N, MorseUpperLower, N, A, N, 51 );
diff --git a/example/lapack_to_morse/step1.h b/example/lapack_to_morse/step1.h
index 0b76f1de5..92a9fb8b0 100644
--- a/example/lapack_to_morse/step1.h
+++ b/example/lapack_to_morse/step1.h
@@ -119,15 +119,4 @@ static void print_header(char *prog_name, int * iparam) {
     return;
 }
 
-/**
- * Macro to allocate a matrix as a 1D array
- */
-#define PASTE_CODE_ALLOCATE_MATRIX(_name_, _type_, _m_, _n_)    \
-    _type_ *_name_ = NULL;                                      \
-    _name_ = (_type_*)malloc( (_m_) * (_n_) * sizeof(_type_) ); \
-    if ( ! _name_ ) {                                           \
-        fprintf(stderr, "Out of Memory for %s\n", #_name_);     \
-        return -1;                                              \
-    }
-
 #endif /* STEP1_H */
diff --git a/example/lapack_to_morse/step2.c b/example/lapack_to_morse/step2.c
index 0a51acd1e..fbb139499 100644
--- a/example/lapack_to_morse/step2.c
+++ b/example/lapack_to_morse/step2.c
@@ -91,10 +91,10 @@ int main(int argc, char *argv[]) {
      *     - set of RHS vectors B       : size N x NRHS
      *     - set of solutions vectors X : size N x NRHS
      */
-    PASTE_CODE_ALLOCATE_MATRIX( A, double, N, N    );
-    PASTE_CODE_ALLOCATE_MATRIX( B, double, N, NRHS );
-    PASTE_CODE_ALLOCATE_MATRIX( X, double, N, NRHS );
-    PASTE_CODE_ALLOCATE_MATRIX( Acpy, double, N, N );
+    double *A    = malloc( N * N    * sizeof(double) );
+    double *Acpy = malloc( N * N    * sizeof(double) );
+    double *B    = malloc( N * NRHS * sizeof(double) );
+    double *X    = malloc( N * NRHS * sizeof(double) );
 
     /*
      * Initialize the structure required for MORSE tile interface
diff --git a/example/lapack_to_morse/step2.h b/example/lapack_to_morse/step2.h
index 86eb985df..2e72b11b0 100644
--- a/example/lapack_to_morse/step2.h
+++ b/example/lapack_to_morse/step2.h
@@ -119,15 +119,4 @@ static void print_header(char *prog_name, int * iparam) {
     return;
 }
 
-/**
- * Macro to allocate a matrix as a 1D array
- */
-#define PASTE_CODE_ALLOCATE_MATRIX(_name_, _type_, _m_, _n_)    \
-    _type_ *_name_ = NULL;                                      \
-    _name_ = (_type_*)malloc( (_m_) * (_n_) * sizeof(_type_) ); \
-    if ( ! _name_ ) {                                           \
-        fprintf(stderr, "Out of Memory for %s\n", #_name_);     \
-        return -1;                                              \
-    }
-
 #endif /* STEP2_H */
-- 
GitLab