From 43dacad04394a4f6d56ae4e2668dff31baec0adc Mon Sep 17 00:00:00 2001
From: Alban Bellot <alban.bellot@inria.fr>
Date: Tue, 26 Jul 2016 14:26:29 +0200
Subject: [PATCH] Fix bugs

---
 spm.h                  |   2 +
 z_spm_2dense.c         | 191 +++++++++++++++++++++++++++++++++++++++++
 z_spm_convert_to_csc.c |  24 +++---
 z_spm_convert_to_csr.c |  33 +++----
 z_spm_convert_to_ijv.c |  22 ++---
 z_spm_dofs2flat.c      |  64 +++++++-------
 z_spm_matrixvector.c   |  25 +-----
 z_spm_norm.c           |  48 ++---------
 z_spm_print.c          | 129 ++++++++++++++++++++++++++++
 9 files changed, 407 insertions(+), 131 deletions(-)
 create mode 100644 z_spm_2dense.c
 create mode 100644 z_spm_print.c

diff --git a/spm.h b/spm.h
index cb18f6d3..46b80c3a 100644
--- a/spm.h
+++ b/spm.h
@@ -89,4 +89,6 @@ pastix_int_t  spmSymmetrize( pastix_spm_t *spm );
 
 pastix_spm_t *spmCheckAndCorrect( pastix_spm_t *spm );
 
+void dofVar(pastix_spm_t* spm);//tmp
+
 #endif /* _SPM_H_ */
diff --git a/z_spm_2dense.c b/z_spm_2dense.c
new file mode 100644
index 00000000..ff3dddfa
--- /dev/null
+++ b/z_spm_2dense.c
@@ -0,0 +1,191 @@
+/**
+ *
+ * @file z_spm_2dense.c
+ *
+ * Convert a sparse matrix into a dense matrix.
+ *
+ * @version 5.1.0
+ * @author Mathieu Faverge
+ * @author Theophile Terraz
+ * @author Alban Bellot
+ * @date 2015-01-01
+ *
+ * @precisions normal z -> c d s
+ *
+ **/
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+#include "pastix.h"
+#include "common.h"
+#include "spm.h"
+#include "z_spm.h"
+
+pastix_complex64_t *
+z_spm2dense( const pastix_spm_t *spm )
+{
+    pastix_int_t i, j, lda, baseval;
+    pastix_complex64_t *A, *valptr;
+    pastix_int_t *colptr, *rowptr;
+
+    assert( spm->fmttype == PastixCSC );
+    assert( spm->flttype == PastixComplex64 );
+
+    lda = spm->gNexp;
+    A = (pastix_complex64_t*)malloc(lda * lda * sizeof(pastix_complex64_t));
+    memset( A, 0, lda * lda * sizeof(pastix_complex64_t));
+
+    baseval = spmFindBase( spm );
+    i = 0; j = 0;
+
+    colptr = spm->colptr;
+    rowptr = spm->rowptr;
+    valptr = (pastix_complex64_t*)(spm->values);
+
+    /**
+     * Constant degree of fredom of 1
+     */
+    if ( spm->dof == 1 ) {
+        switch( spm->mtxtype ){
+#if defined(PRECISION_z) || defined(PRECISION_c)
+        case PastixHermitian:
+            for(i=0; i<spm->n; i++, colptr++)
+            {
+                for(j=colptr[0]; j<colptr[1]; j++, rowptr++, valptr++)
+                {
+                    A[ i * lda + (*rowptr - baseval) ] = *valptr;
+                    A[ (*rowptr - baseval) * lda + i ] = conj(*valptr);
+                }
+            }
+            break;
+#endif
+        case PastixSymmetric:
+            for(i=0; i<spm->n; i++, colptr++)
+            {
+                for(j=colptr[0]; j<colptr[1]; j++, rowptr++, valptr++)
+                {
+                    A[ i * lda + (*rowptr - baseval) ] = *valptr;
+                    A[ (*rowptr - baseval) * lda + i ] = *valptr;
+                }
+            }
+            break;
+        case PastixGeneral:
+        default:
+            for(i=0; i<spm->n; i++, colptr++)
+            {
+                for(j=colptr[0]; j<colptr[1]; j++, rowptr++, valptr++)
+                {
+                    A[ i * lda + (*rowptr - baseval) ] = *valptr;
+                }
+            }
+        }
+    }
+    /**
+     * General degree of freedom (constant or variable)
+     */
+    else {
+        pastix_int_t  k, ii, jj, dofi, dofj, col, row;
+        pastix_int_t *dofs = spm->dofs;
+
+        switch( spm->mtxtype ){
+#if defined(PRECISION_z) || defined(PRECISION_c)
+        case PastixHermitian:
+            for(i=0; i<spm->n; i++, colptr++)
+            {
+                dofi = ( spm->dof > 1 ) ? spm->dof : dofs[i+1] - dofs[i];
+                col = dofs[i];
+
+                for(k=colptr[0]; k<colptr[1]; k++, rowptr++)
+                {
+                    j = (*rowptr - baseval);
+                    dofj = ( spm->dof > 1 ) ? spm->dof : dofs[j+1] - dofs[j];
+                    row = dofs[j];
+
+                    for(ii=0; ii<dofi; ii++)
+                    {
+                        for(jj=0; jj<dofj; jj++, valptr++)
+                        {
+                            A[ (col + ii) * lda + (row + jj) ] = *valptr;
+                            A[ (row + jj) * lda + (col + ii) ] = conj(*valptr);
+                        }
+                    }
+                }
+            }
+            break;
+#endif
+        case PastixSymmetric:
+            for(i=0; i<spm->n; i++, colptr++)
+            {
+                dofi = ( spm->dof > 1 ) ? spm->dof : dofs[i+1] - dofs[i];
+                col = dofs[i];
+
+                for(k=colptr[0]; k<colptr[1]; k++, rowptr++)
+                {
+                    j = (*rowptr - baseval);
+                    dofj = ( spm->dof > 1 ) ? spm->dof : dofs[j+1] - dofs[j];
+                    row = dofs[j];
+
+                    for(ii=0; ii<dofi; ii++)
+                    {
+                        for(jj=0; jj<dofj; jj++, valptr++)
+                        {
+                            A[ (col + ii) * lda + (row + jj) ] = *valptr;
+                            A[ (row + jj) * lda + (col + ii) ] = *valptr;
+                        }
+                    }
+                }
+            }
+            break;
+        case PastixGeneral:
+        default:
+            for(i=0; i<spm->n; i++, colptr++)
+            {
+                dofi = ( spm->dof > 1 ) ? spm->dof : dofs[i+1] - dofs[i];
+                col = dofs[i];
+
+                for(k=colptr[0]; k<colptr[1]; k++, rowptr++)
+                {
+                    j = (*rowptr - baseval);
+                    dofj = ( spm->dof > 1 ) ? spm->dof : dofs[j+1] - dofs[j];
+                    row = dofs[j];
+
+                    for(ii=0; ii<dofi; ii++)
+                    {
+                        for(jj=0; jj<dofj; jj++, valptr++)
+                        {
+                            A[ (col + ii) * lda + (row + jj) ] = *valptr;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return A;
+}
+
+void
+z_spmDensePrint( pastix_int_t m, pastix_int_t n, pastix_complex64_t *A, pastix_int_t lda )
+{
+    pastix_int_t i, j;
+
+    for(i=0; i<m; i++)
+    {
+        for(j=0; j<n; j++)
+        {
+            if ( cabs( A[ lda *j + i] ) != 0. ) {
+#if defined(PRECISION_z) || defined(PRECISION_c)
+                fprintf( stderr, "%ld %ld (%e, %e)\n",
+                         i, j, creal(A[lda * j + i]), cimag(A[lda * j + i]) );
+#else
+                fprintf( stderr, "%ld %ld %e\n",
+                         i, j, A[lda * j + i] );
+#endif
+            }
+        }
+    }
+    return;
+}
+
diff --git a/z_spm_convert_to_csc.c b/z_spm_convert_to_csc.c
index 43f8367f..435ecc50 100644
--- a/z_spm_convert_to_csc.c
+++ b/z_spm_convert_to_csc.c
@@ -9,6 +9,7 @@
  * @version 5.1.0
  * @author Mathieu Faverge
  * @author Theophile Terraz
+ * @author Alban Bellot
  * @date 2015-01-01
  *
  * @precisions normal z -> c d s p
@@ -80,11 +81,10 @@ z_spmConvertIJV2CSC( pastix_spm_t *spm )
 
     /* Sort the rows and avals arrays by column */
     spm->rowptr = malloc(spm->nnz * sizeof(pastix_int_t));
-    pastix_int_t* node = calloc(spm->nnz+1,sizeof(pastix_int_t));
-    pastix_int_t* old_node = calloc(spm->nnz+1,sizeof(pastix_int_t));
+    pastix_int_t *node     = calloc(spm->nnz+1,sizeof(pastix_int_t));
+    pastix_int_t *old_node = calloc(spm->nnz+1,sizeof(pastix_int_t));
+    pastix_int_t *dofs     = spm->dofs;
     pastix_int_t row, col, dofi, dofj;
-    pastix_int_t *dofs=spm->dofs;
-
 
     for(i=0; i<spm->nnz; i++)
     {
@@ -127,13 +127,11 @@ z_spmConvertIJV2CSC( pastix_spm_t *spm )
     for (j=0; j<spm->nnz; j++)
     {
         i = oldspm.colptr[j] - baseval;
-
         spm->rowptr[ spm->colptr[i] ] = oldspm.rowptr[j];
 
 #if !defined(PRECISION_p)
         dofi = ( spm->dof > 0 ) ? spm->dof : dofs[i+1] - dofs[i];
         dofj = ( spm->dof > 0 ) ? spm->dof : dofs[oldspm.rowptr[j]-baseval+1] - dofs[oldspm.rowptr[j]-baseval];
-
         for(ii=0; ii<dofi; ii++)
         {
             for(jj=0; jj<dofj; jj++)
@@ -152,7 +150,6 @@ z_spmConvertIJV2CSC( pastix_spm_t *spm )
     /* Rebuild the colptr with the correct baseval */
     tmp = spm->colptr[0];
     spm->colptr[0] = baseval;
-
     spmptx = spm->colptr + 1;
     for (i=1; i<(spm->n+1); i++, spmptx++)
     {
@@ -198,6 +195,10 @@ z_spmConvertCSR2CSC( pastix_spm_t *spm )
 
     spm->fmttype = PastixCSC;
 
+    pastix_int_t type = spm->mtxtype;
+    if(spm->dof != 1)
+        spm->mtxtype = PastixGeneral;
+
     switch( spm->mtxtype ) {
 #if defined(PRECISION_z) || defined(PRECISION_c)
     case PastixHermitian:
@@ -242,7 +243,6 @@ z_spmConvertCSR2CSC( pastix_spm_t *spm )
         pastix_int_t  i, j, k, col, row, nnz, baseval;
         pastix_int_t dofi, dofj;
 
-
         baseval = spmFindBase( spm );
         nnz = spm->nnz;
 
@@ -257,12 +257,10 @@ z_spmConvertCSR2CSC( pastix_spm_t *spm )
         assert( ( (dofs) && !(spm->dof > 0) ) ||
                 ( !(dofs) && (spm->dof > 0) ) ); // (dofs) xor (spm->dof > 0)
 
-
 #if !defined(PRECISION_p)
         val_csc = malloc(spm->nnzexp*sizeof(pastix_complex64_t));
         assert( val_csc );
 #endif
-
         /* Count the number of elements per column */
         for (j=0; j<nnz; j++) {
             col = spm->colptr[j] - baseval;
@@ -318,12 +316,11 @@ z_spmConvertCSR2CSC( pastix_spm_t *spm )
 #if !defined(PRECISION_p)
                 dofi = ( spm->dof > 0 ) ? spm->dof : dofs[col+1] - dofs[col];
                 dofj = ( spm->dof > 0 ) ? spm->dof : dofs[row+1] - dofs[row];
-                //printf("dof dof %d %d\n",dofi,dofj);
                 for(jj=0; jj < dofj ; jj++)
                 {
                     for(ii=0; ii < dofi ; ii++)
                     {
-                        val_csc[node[j]+ii*dofj+jj] = valptr[cpt];
+                        val_csc[node[j] + ii * dofj + jj] = valptr[cpt];
                         cpt++;
                     }
                 }
@@ -355,5 +352,8 @@ z_spmConvertCSR2CSC( pastix_spm_t *spm )
     }
     }
 
+    if(spm-> dof != 1)
+        spm->mtxtype = type;
+
     return PASTIX_SUCCESS;
 }
diff --git a/z_spm_convert_to_csr.c b/z_spm_convert_to_csr.c
index 792a6ae5..a3eca787 100644
--- a/z_spm_convert_to_csr.c
+++ b/z_spm_convert_to_csr.c
@@ -9,6 +9,7 @@
  * @version 5.1.0
  * @author Mathieu Faverge
  * @author Theophile Terraz
+ * @authot Alban Bellot
  * @date 2015-01-01
  *
  * @precisions normal z -> c d s p
@@ -43,6 +44,10 @@ z_spmConvertCSC2CSR( pastix_spm_t *spm )
 {
     pastix_int_t *tmp;
     pastix_int_t  result;
+    pastix_int_t  type = spm->mtxtype;
+
+    if(spm->dof != 1)
+        spm->mtxtype = PastixGeneral;
 
     switch( spm->mtxtype ) {
 #if defined(PRECISION_z) || defined(PRECISION_c)
@@ -66,7 +71,6 @@ z_spmConvertCSC2CSR( pastix_spm_t *spm )
         spm->rowptr  = spm->colptr;
         spm->colptr  = tmp;
         spm->fmttype = PastixCSR;
-
         return PASTIX_SUCCESS;
     }
     break;
@@ -91,6 +95,9 @@ z_spmConvertCSC2CSR( pastix_spm_t *spm )
     }
     }
 
+    if(spm-> dof != 1)
+        spm->mtxtype = type;
+
     return result;
 }
 
@@ -127,7 +134,7 @@ z_spmConvertIJV2CSR( pastix_spm_t *spm )
 
     pastix_int_t *node     = calloc(spm->nnz+1,sizeof(pastix_int_t));
     pastix_int_t *old_node = calloc(spm->nnz+1,sizeof(pastix_int_t));
-    pastix_int_t *dofs     =spm->dofs;
+    pastix_int_t *dofs     = spm->dofs;
 
     pastix_spm_t oldspm;
 
@@ -136,17 +143,16 @@ z_spmConvertIJV2CSR( pastix_spm_t *spm )
      */
     baseval = spmFindBase( spm );
 
-
 #if !defined(PRECISION_p)
-    pastix_int_t ii, jj;
     /* Transpose values in row major format */
-    if( spm->colmajor ) //A test
+    if( spm->colmajor )
     {
-        int k;
-        int cpt=0;
+        pastix_int_t ii, jj, k;
+        pastix_int_t cpt=0;
+        pastix_int_t* dofs = spm->dofs;
+
         oavals = (pastix_complex64_t*)spm->values;
         navals = malloc(sizeof(pastix_complex64_t)*spm->nnzexp);
-        pastix_int_t* dofs=spm->dofs;
 
         for(k=0; k<spm->nnz; k++)
         {
@@ -158,22 +164,19 @@ z_spmConvertIJV2CSR( pastix_spm_t *spm )
             {
                 for(jj=0; jj<dofj; jj++)
                 {
-                    navals[cpt+jj*dofi+ii]=*oavals;
+                    navals[cpt + jj * dofi + ii] = *oavals;
                     oavals++;
                 }
             }
-            cpt += dofi*dofj;
+            cpt += dofi * dofj;
         }
-        spm->values=navals;
+        spm->values = navals;
     }
 #endif
 
-
-
     /* Backup the input */
     memcpy( &oldspm, spm, sizeof(pastix_spm_t) );
 
-
     /* Compute the new rowptr */
     spm->rowptr = (pastix_int_t *) calloc(spm->n+1,sizeof(pastix_int_t));
 
@@ -277,6 +280,6 @@ z_spmConvertIJV2CSR( pastix_spm_t *spm )
 
     spm->fmttype = PastixCSR;
 
-
     return PASTIX_SUCCESS;
 }
+
diff --git a/z_spm_convert_to_ijv.c b/z_spm_convert_to_ijv.c
index d81ab2d4..4c518b98 100644
--- a/z_spm_convert_to_ijv.c
+++ b/z_spm_convert_to_ijv.c
@@ -9,6 +9,7 @@
  * @version 5.1.0
  * @author Mathieu Faverge
  * @author Theophile Terraz
+ * @author Alban Bellot
  * @date 2015-01-01
  *
  * @precisions normal z -> c d s p
@@ -65,11 +66,12 @@ z_spmConvertCSC2IJV( pastix_spm_t *spm )
     /* Transpose values in row major format */
     if( !spm->colmajor ) //A test
     {
-        int k,ii,jj,dofi,dofj;
-        int cpt=0;
+        int k, ii, jj, dofi, dofj;
+        int cpt = 0;
         pastix_complex64_t* oavals = (pastix_complex64_t*)spm->values;
         pastix_complex64_t* navals = malloc(sizeof(pastix_complex64_t)*spm->nnzexp);
         pastix_int_t* dofs=spm->dofs;
+
         for(k=0; k<spm->nnz; k++)
         {
             j = spm->rowptr[k]-baseval;
@@ -80,13 +82,13 @@ z_spmConvertCSC2IJV( pastix_spm_t *spm )
             {
                 for(jj=0; jj<dofj; jj++)
                 {
-                    navals[cpt+jj*dofi+ii]=*oavals;
+                    navals[cpt + jj * dofi + ii] = *oavals;
                     oavals++;
                 }
             }
-            cpt+=dofi*dofj;
+            cpt + = dofi * dofj;
         }
-        spm->values=navals;
+        spm->values = navals;
     }
 
     memFree_null(spm->colptr);
@@ -143,8 +145,8 @@ z_spmConvertCSR2IJV( pastix_spm_t *spm )
     /* Transpose values in column major format */
     if( spm->colmajor )
     {
-        int k,ii,jj,dofi,dofj;
-        int cpt=0;
+        pastix_int_t k, ii, jj, dofi, dofj;
+        pastix_int_t cpt=0;
         pastix_complex64_t* oavals = (pastix_complex64_t*)spm->values;
         pastix_complex64_t* navals = malloc(sizeof(pastix_complex64_t)*spm->nnzexp);
         pastix_int_t* dofs=spm->dofs;
@@ -158,13 +160,13 @@ z_spmConvertCSR2IJV( pastix_spm_t *spm )
             {
                 for(ii=0; ii<dofi; ii++)
                 {
-                    navals[cpt+ii*dofj+jj]=*oavals;
+                    navals[cpt + ii * dofj + jj] = *oavals;
                     oavals++;
                 }
             }
-            cpt+=dofi*dofj;
+            cpt += dofi * dofj;
         }
-        spm->values=navals;
+        spm->values = navals;
     }
 
     memFree_null(spm->rowptr);
diff --git a/z_spm_dofs2flat.c b/z_spm_dofs2flat.c
index 546da548..42b9805a 100644
--- a/z_spm_dofs2flat.c
+++ b/z_spm_dofs2flat.c
@@ -1,8 +1,10 @@
 /**
  *
- * @file z_spm_2dense.c
+ * @file z_spm_dofs2flat.c
  *
- * Convert a sparse matrix into a dense matrix.
+ *  PaStiX spm routines
+ *  PaStiX is a software package provided by Inria Bordeaux - Sud-Ouest,
+ *  LaBRI, University of Bordeaux 1 and IPB.
  *
  * @version 5.1.0
  * @author Mathieu Faverge
@@ -24,31 +26,24 @@
 #include "spm.h"
 #include "z_spm.h"
 
-
-pastix_spm_t *
-dofs2flat(pastix_spm_t *spm)
+/**
+ *******************************************************************************
+ *
+ * @ingroup spm_internal
+ *
+ * z_spmDofs2Flat - Convert a sparse matrix with dofs into a sparse matrix without dofs.
+ *
+ *
+ *******************************************************************************
+ *
+ * @param[in] spm
+ *           The sparse matrix which needs to be converted
+ *
+ *******************************************************************************
+ **/
+void
+z_spmDofs2Flat(pastix_spm_t *spm)
 {
-    pastix_spm_t* new_spm=malloc(sizeof(pastix_spm_t));
-    spmInit(new_spm);
-
-    new_spm->mtxtype = spm->mtxtype;
-    new_spm->flttype = spm->flttype;
-    new_spm->fmttype = spm->fmttype;
-
-    new_spm->gN   = spm->gNexp;
-    new_spm->n    = spm->nexp;
-    new_spm->gnnz = spm->gnnzexp;
-    new_spm->nnz  = spm->nnzexp;
-
-    new_spm->gNexp   = spm->gNexp;
-    new_spm->nexp    = spm->nexp;
-    new_spm->gnnzexp = spm->gnnzexp;
-    new_spm->nnzexp  = spm->nnzexp;
-
-    new_spm->dof       = 1;
-    new_spm->dofs      = NULL;
-    new_spm->colmajor  = 1;
-
     pastix_int_t i, j, k, ii, jj, dofi, dofj, col, row, baseval;
     baseval = spmFindBase( spm );
 
@@ -115,10 +110,17 @@ dofs2flat(pastix_spm_t *spm)
         new_col[i] += baseval;
     }
 
-    new_spm->colptr   = new_col;
-    new_spm->rowptr   = new_row;
-    new_spm->loc2glob = NULL; // ?
-    new_spm->values   = new_vals;
+    spm->gN   = spm->gNexp;
+    spm->n    = spm->nexp;
+    spm->gnnz = spm->gnnzexp;
+    spm->nnz  = spm->nnzexp;
+
+    spm->dof       = 1;
+    spm->dofs      = NULL;
+    spm->colmajor  = 1;
 
-    return new_spm;
+    spm->colptr   = new_col;
+    spm->rowptr   = new_row;
+    spm->loc2glob = NULL; // ?
+    spm->values   = new_vals;
 }
diff --git a/z_spm_matrixvector.c b/z_spm_matrixvector.c
index 14238ff1..7b67fc3c 100644
--- a/z_spm_matrixvector.c
+++ b/z_spm_matrixvector.c
@@ -75,7 +75,7 @@ z_spmGeCSCv(      int                 trans,
     pastix_complex64_t *yptr = y;
     pastix_int_t col, row, i, j, baseval;
     pastix_int_t ii, jj, k, dofi, dofj;
-    pastix_int_t *dofs=csc->dofs;
+    pastix_int_t *dofs = csc->dofs;
 
     if ( (csc == NULL) || (x == NULL) || (y == NULL ) )
     {
@@ -168,7 +168,6 @@ z_spmGeCSCv(      int                 trans,
             return PASTIX_ERR_BADPARAMETER;
         }
     }
-
     return PASTIX_SUCCESS;
 }
 
@@ -219,8 +218,7 @@ z_spmSyCSCv(      pastix_complex64_t  alpha,
     pastix_complex64_t *yptr = y;
     pastix_int_t col, row, i, j, baseval;
     pastix_int_t ii, jj, k, dofi, dofj;
-    pastix_int_t *dofs=csc->dofs;
-
+    pastix_int_t *dofs = csc->dofs;
 
     if ( (csc == NULL) || (x == NULL) || (y == NULL ) )
     {
@@ -321,8 +319,7 @@ z_spmHeCSCv(      pastix_complex64_t  alpha,
     pastix_complex64_t *yptr = y;
     pastix_int_t col, row, i, j, baseval;
     pastix_int_t ii, jj, k, dofi, dofj;
-    pastix_int_t *dofs=csc->dofs;
-
+    pastix_int_t *dofs = csc->dofs;
 
     if ( (csc == NULL) || (x == NULL) || (y == NULL ) )
     {
@@ -371,22 +368,6 @@ z_spmHeCSCv(      pastix_complex64_t  alpha,
             }
         }
     }
-
-    /*
-    if( alpha != 0. ) {
-        for( col=0; col < csc->gN; col++ )
-        {
-            for( i=csc->colptr[col]; i < csc->colptr[col+1]; i++ )
-            {
-                row=csc->rowptr[i-baseval]-baseval;
-                yptr[row] += alpha * valptr[i-baseval] * xptr[col];
-                if( col != row )
-                    yptr[col] += alpha * conj( valptr[i-baseval] ) * xptr[row];
-            }
-        }
-    }
-     */
-
     return PASTIX_SUCCESS;
 }
 #endif
diff --git a/z_spm_norm.c b/z_spm_norm.c
index 549a1415..360c6246 100644
--- a/z_spm_norm.c
+++ b/z_spm_norm.c
@@ -62,8 +62,9 @@ z_spmFrobeniusNorm( const pastix_spm_t *spm )
     else {
         pastix_int_t *colptr = spm->colptr;
         pastix_int_t *rowptr = spm->rowptr;
+        pastix_int_t *dofs   = spm->dofs;
+
         int nb, dofi, dofj, ii, jj;
-        pastix_int_t *dofs=spm->dofs;
         baseval = spmFindBase( spm );
 
         switch( spm->fmttype ){
@@ -183,7 +184,7 @@ z_spmInfNorm( const pastix_spm_t *spm )
 {
     pastix_int_t col, row, i, j, k, ii, jj, baseval;
     pastix_int_t dofi, dofj;
-    pastix_int_t *dofs=spm->dofs;
+    pastix_int_t *dofs = spm->dofs;
 
     pastix_complex64_t *valptr = (pastix_complex64_t*)spm->values;
     double norm = 0.;
@@ -195,33 +196,6 @@ z_spmInfNorm( const pastix_spm_t *spm )
 
     switch( spm->fmttype ){
     case PastixCSC:
-        /* Original */
-        /*
-        for( col=0; col < spm->gN; col++ )
-        {
-            for( i=spm->colptr[col]-baseval; i<spm->colptr[col+1]-baseval; i++ )
-            {
-                sumcol[spm->rowptr[i]-baseval] += cabs( valptr[i] );
-            }
-        }
-         */
-
-        /* Add the symmetric/hermitian part */
-        /*
-        if ( (spm->mtxtype == PastixHermitian) ||
-             (spm->mtxtype == PastixSymmetric) )
-        {
-            for( col=0; col < spm->gN; col++ )
-            {
-                for( i=spm->colptr[col]-baseval+1; i<spm->colptr[col+1]-baseval; i++ )
-                {
-                    sumcol[col] += cabs( valptr[i] );
-                }
-            }
-        }
-         */
-
-        /* Dofs */
         for( i=0; i < spm->n; i++)
         {
             dofi = ( spm->dof > 0 ) ? spm->dof : dofs[i+1] - dofs[i];
@@ -241,6 +215,7 @@ z_spmInfNorm( const pastix_spm_t *spm )
                 }
             }
         }
+
         /* Add the symmetric/hermitian part */
         if ( (spm->mtxtype == PastixHermitian) ||
              (spm->mtxtype == PastixSymmetric) )
@@ -319,7 +294,7 @@ z_spmInfNorm( const pastix_spm_t *spm )
         return PASTIX_ERR_BADPARAMETER;
     }
 
-    for( i=0; i<spm->gNexp; i++) //gNexp
+    for( i=0; i<spm->gNexp; i++)
     {
         if(norm < sumcol[i])
         {
@@ -357,11 +332,11 @@ z_spmOneNorm( const pastix_spm_t *spm )
 {
     pastix_int_t col, row, i, j, k, ii, jj, baseval;
     pastix_int_t dofi, dofj;
+    pastix_int_t* dofs = spm->dofs;
 
     pastix_complex64_t *valptr = (pastix_complex64_t*)spm->values;
     double norm = 0.;
     double *sumrow;
-    pastix_int_t* dofs=spm->dofs;
 
     MALLOC_INTERN( sumrow, spm->gNexp, double );
     memset( sumrow, 0, spm->gNexp * sizeof(double) );
@@ -369,16 +344,6 @@ z_spmOneNorm( const pastix_spm_t *spm )
 
     switch( spm->fmttype ){
     case PastixCSC:
-        /*
-         for( col=0; col < spm->gN; col++ )
-         {
-         for( i=spm->colptr[col]-baseval; i<spm->colptr[col+1]-baseval; i++ )
-         {
-         sumrow[col] += cabs( valptr[i] );
-         }
-         }
-         */
-
         for(i=0; i < spm->n; i++)
         {
             col  = ( spm->dof > 0 ) ? i        : dofs[i];
@@ -398,6 +363,7 @@ z_spmOneNorm( const pastix_spm_t *spm )
                 }
             }
         }
+
         /* Add the symmetric/hermitian part */
         if ( (spm->mtxtype == PastixHermitian) ||
              (spm->mtxtype == PastixSymmetric) )
diff --git a/z_spm_print.c b/z_spm_print.c
new file mode 100644
index 00000000..6e4f9929
--- /dev/null
+++ b/z_spm_print.c
@@ -0,0 +1,129 @@
+/**
+ *
+ * @file z_spm_print.c
+ *
+ * Convert a sparse matrix into a dense matrix.
+ *
+ * @version 5.1.0
+ * @author Mathieu Faverge
+ * @author Theophile Terraz
+ * @author Alban Bellot
+ * @date 2015-01-01
+ *
+ * @precisions normal z -> c d s
+ *
+ **/
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+#include "pastix.h"
+#include "common.h"
+#include "spm.h"
+#include "z_spm.h"
+
+void
+z_spmPrint( const pastix_spm_t *spm )
+{
+    pastix_int_t i, j, baseval;
+    pastix_int_t k, ii, jj, dofi, dofj, col, row;
+    pastix_complex64_t *valptr;
+    pastix_int_t *colptr, *rowptr, *dofs;
+
+    assert( spm->fmttype == PastixCSC );
+    assert( spm->flttype == PastixComplex64 );
+
+    baseval = spmFindBase( spm );
+    i = 0; j = 0;
+
+    colptr = spm->colptr;
+    rowptr = spm->rowptr;
+    valptr = (pastix_complex64_t*)(spm->values);
+    dofs   = spm->dofs;
+
+    switch( spm->mtxtype ){
+#if defined(PRECISION_z) || defined(PRECISION_c)
+    case PastixHermitian:
+        for(i=0; i<spm->n; i++, colptr++)
+        {
+            dofi = ( spm->dof > 1 ) ? spm->dof : dofs[i+1] - dofs[i];
+            col = dofs[i];
+
+            for(k=colptr[0]; k<colptr[1]; k++, rowptr++)
+            {
+                j = (*rowptr - baseval);
+                dofj = ( spm->dof > 1 ) ? spm->dof : dofs[j+1] - dofs[j];
+                row = dofs[j];
+
+                for(ii=0; ii<dofi; ii++)
+                {
+                    for(jj=0; jj<dofj; jj++, valptr++)
+                    {
+                        fprintf( stderr, "%ld %ld %e\n",
+                                 row + jj, col + ii, *valptr );
+                        if (i != j) {
+                            fprintf( stderr, "%ld %ld %e\n",
+                                     col + ii, row + jj, conj(*valptr) );
+                        }
+                    }
+                }
+            }
+        }
+        break;
+#endif
+    case PastixSymmetric:
+        for(i=0; i<spm->n; i++, colptr++)
+        {
+            dofi = ( spm->dof > 1 ) ? spm->dof : dofs[i+1] - dofs[i];
+            col = dofs[i];
+
+            for(k=colptr[0]; k<colptr[1]; k++, rowptr++)
+            {
+                j = (*rowptr - baseval);
+                dofj = ( spm->dof > 1 ) ? spm->dof : dofs[j+1] - dofs[j];
+                row = dofs[j];
+
+                for(ii=0; ii<dofi; ii++)
+                {
+                    for(jj=0; jj<dofj; jj++, valptr++)
+                    {
+                        fprintf( stderr, "%ld %ld %e\n",
+                                 row + jj, col + ii, *valptr );
+                        if (i != j) {
+                            fprintf( stderr, "%ld %ld %e\n",
+                                     col + ii, row + jj, *valptr );
+                        }
+                    }
+                }
+            }
+        }
+        break;
+    case PastixGeneral:
+    default:
+        for(i=0; i<spm->n; i++, colptr++)
+        {
+            dofi = ( spm->dof > 1 ) ? spm->dof : dofs[i+1] - dofs[i];
+            col = dofs[i];
+
+            for(k=colptr[0]; k<colptr[1]; k++, rowptr++)
+            {
+                j = (*rowptr - baseval);
+                dofj = ( spm->dof > 1 ) ? spm->dof : dofs[j+1] - dofs[j];
+                row = dofs[j];
+
+                for(ii=0; ii<dofi; ii++)
+                {
+                    for(jj=0; jj<dofj; jj++, valptr++)
+                    {
+                        fprintf( stderr, "%ld %ld %e\n",
+                                 row + jj, col + ii, *valptr );
+                    }
+                }
+            }
+        }
+    }
+    return;
+}
+
-- 
GitLab