From 741638480df69c9e5c7cd1402d989f73c876bdf2 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Wed, 5 Oct 2016 16:33:41 +0200
Subject: [PATCH] Start cleaning up the multi-dof

---
 spm.h          |  1 +
 spm_expand.c   | 19 +++++++++-----
 z_spm.h        | 23 +++++++++++++----
 z_spm_expand.c | 69 ++++++++++++++++++++++++++++++++------------------
 4 files changed, 75 insertions(+), 37 deletions(-)

diff --git a/spm.h b/spm.h
index 71fd4698..971fc622 100644
--- a/spm.h
+++ b/spm.h
@@ -99,6 +99,7 @@ pastix_int_t  spmSymmetrize( pastix_spm_t *spm );
 
 pastix_spm_t *spmCheckAndCorrect( pastix_spm_t *spm );
 
+void spmExpand(pastix_spm_t* spm);
 void dofVar(pastix_spm_t* spm);//tmp
 
 #endif /* _SPM_H_ */
diff --git a/spm_expand.c b/spm_expand.c
index 6dead986..ac66de23 100644
--- a/spm_expand.c
+++ b/spm_expand.c
@@ -15,25 +15,30 @@
  **/
 #include "common.h"
 #include "spm.h"
+
 #include "z_spm.h"
+#include "c_spm.h"
+#include "d_spm.h"
+#include "s_spm.h"
+#include "p_spm.h"
 
 void
-spmExpandCSC(pastix_spm_t* spm)
+spmExpand(pastix_spm_t* spm)
 {
     switch(spm->flttype)
     {
     case PastixFloat:
-        s_extandCSC(spm);
+        s_spmExpand(spm);
         break;
     case PastixComplex32:
-        c_extandCSC(spm);
+        c_spmExpand(spm);
         break;
     case PastixComplex64:
-        z_extandCSC(spm);
+        z_spmExpand(spm);
         break;
     case PastixDouble:
     default:
-        d_extandCSC(spm);
+        d_spmExpand(spm);
         break;
     }
 }
@@ -141,7 +146,7 @@ dofCst(pastix_spm_t* spm,pastix_int_t dof)
     for(i=0;i<spm->n+1;i++)
         dofs[i]=dof*i;
 
-    spmExpandCSC(spm);
+    spmExpand(spm);
 }
 
 
@@ -194,7 +199,7 @@ dofVar(pastix_spm_t* spm)
     pastix_int_t* tab = computeCorrespondIndex(dofs,spm->n);
 
     spm->dofs   = tab;
-    spmExpandCSC(spm);
+    spmExpand(spm);
 
     /*
     print_tab_int(spm->colptr,spm->n);
diff --git a/z_spm.h b/z_spm.h
index 886f39e9..0c4ae86c 100644
--- a/z_spm.h
+++ b/z_spm.h
@@ -18,6 +18,9 @@
 #ifndef _z_spm_H_
 #define _z_spm_H_
 
+/**
+ * Conversion routines
+ */
 int z_spmConvertCSC2CSR( pastix_spm_t *spm );
 int z_spmConvertCSC2IJV( pastix_spm_t *spm );
 int z_spmConvertCSR2CSC( pastix_spm_t *spm );
@@ -25,10 +28,21 @@ int z_spmConvertCSR2IJV( pastix_spm_t *spm );
 int z_spmConvertIJV2CSC( pastix_spm_t *spm );
 int z_spmConvertIJV2CSR( pastix_spm_t *spm );
 
+void z_spmConvertColMaj2RowMaj(pastix_spm_t *spm);
+void z_spmConvertRowMaj2ColMaj(pastix_spm_t *spm);
+
+pastix_complex64_t *z_spm2dense( const pastix_spm_t *spm );
+
+/**
+ * Matrix-Vector product routines
+ */
 int    z_spmGeCSCv(int trans, pastix_complex64_t alpha, const pastix_spm_t *csc, const pastix_complex64_t *x, pastix_complex64_t beta, pastix_complex64_t *y);
 int    z_spmSyCSCv(           pastix_complex64_t alpha, const pastix_spm_t *csc, const pastix_complex64_t *x, pastix_complex64_t beta, pastix_complex64_t *y);
 int    z_spmHeCSCv(           pastix_complex64_t alpha, const pastix_spm_t *csc, const pastix_complex64_t *x, pastix_complex64_t beta, pastix_complex64_t *y);
 
+/**
+ * Extra routines
+ */
 double       z_spmNorm( int ntype, const pastix_spm_t *csc );
 void         z_spmSort( pastix_spm_t *csc );
 pastix_int_t z_spmMergeDuplicate( pastix_spm_t *csc );
@@ -37,15 +51,14 @@ pastix_int_t z_spmSymmetrize( pastix_spm_t *csc );
 int z_spmGenRHS(int type, int nrhs, const pastix_spm_t *spm, void *x, int ldx, void *b, int ldb );
 int z_spmCheckAxb( int nrhs, const pastix_spm_t *spm, void *x0, int ldx0, void *b, int ldb, const void *x, int ldx );
 
-pastix_complex64_t *z_spm2dense( const pastix_spm_t *spm );
+/**
+ * Output routines
+ */
 void z_spmDensePrint( pastix_int_t m, pastix_int_t n, pastix_complex64_t *A, pastix_int_t lda );
 void z_spmPrint( const pastix_spm_t *spm );
 
-void z_spmConvertColMaj2RowMaj(pastix_spm_t *spm);
-void z_spmConvertRowMaj2ColMaj(pastix_spm_t *spm);
-
-void z_extandCSC(pastix_spm_t *spm);
 
+void z_spmExpand(pastix_spm_t *spm);
 void z_spmDofs2Flat(pastix_spm_t *spm);
 
 #endif /* _z_spm_H_ */
diff --git a/z_spm_expand.c b/z_spm_expand.c
index 8167b0c5..3e461691 100644
--- a/z_spm_expand.c
+++ b/z_spm_expand.c
@@ -8,7 +8,6 @@
  *
  * @version 5.1.0
  * @author Mathieu Faverge
- * @author Theophile Terraz
  * @author Alban Bellot
  * @date 2015-01-01
  *
@@ -18,29 +17,49 @@
 #include "spm.h"
 #include "z_spm.h"
 
-
-void z_extandCSC(pastix_spm_t* spm)
+/**
+ * TODO: This function is incorrect
+ */
+int
+z_spmExpand(pastix_spm_t* spm)
 {
-  pastix_int_t col, row, i, cpt, dofj, dofi, baseval;
-  cpt=0;
-
-  pastix_complex64_t *valptr = (pastix_complex64_t*)spm->values;
-  pastix_complex64_t *newval = calloc(spm->nnzexp,sizeof(pastix_complex64_t));
-
-  baseval=spmFindBase( spm );
-
-  for( col=0; col<spm->n; col++)
-  {
-      for( row=spm->colptr[col]-baseval; row<spm->colptr[col+1]-baseval; row++)
-      {
-          dofi = ( spm->dof > 0 ) ? spm->dof : spm->dofs[col+1] - spm->dofs[col];
-          dofj = ( spm->dof > 0 ) ? spm->dof : spm->dofs[spm->rowptr[row]-baseval+1] - spm->dofs[spm->rowptr[row]-baseval];
-	  for( i=0; i<dofi*dofj; i++)
-          {
-              newval[cpt] = valptr[row] / ((i/dofj) + (i%dofj) + 2); // Col major
-	      cpt++;
-          }
-      }
-  }
-  spm->values=newval;
+    pastix_int_t i, col, row, cpt, dofj, dofi, baseval;
+    pastix_complex64_t *oldvalptr;
+    pastix_complex64_t *newvalptr;
+
+    if (1) {
+        return PASTIX_ERR_NOTIMPLEMENTED;
+    }
+
+    baseval = spmFindBase( spm );
+
+    oldvalptr = (pastix_complex64_t*)spm->values;
+    spm->values = malloc( spm->nnzexp * sizeof(pastix_complex64_t) );
+    newvalptr = (pastix_complex64_t*)spm->values;
+
+    cpt = 0;
+    dofi = spm->dof;
+    dofj = spm->dof;
+
+    for( col=0; col<spm->n; col++)
+    {
+        if ( spm->dof <= 0 ) {
+            dofi = spm->dofs[col+1] - spm->dofs[col];
+        }
+
+        for( row=spm->colptr[col]-baseval; row<spm->colptr[col+1]-baseval; row++)
+        {
+            if ( spm->dof <= 0 ) {
+                dofj = spm->dofs[spm->rowptr[row]-baseval+1] - spm->dofs[spm->rowptr[row]-baseval];
+            }
+
+            for( i=0; i<dofi*dofj; i++)
+            {
+                newvalptr[cpt] = oldvalptr[row] / ((i/dofj) + (i%dofj) + 2); // Col major
+                cpt++;
+            }
+        }
+    }
+
+    free( oldvalptr );
 }
-- 
GitLab