KLU-1 Patch for dump_routines and new SMPmatrix structure
This commit is contained in:
parent
6d7dcc1e59
commit
221940b3ae
|
|
@ -77,26 +77,6 @@ static void ExpandTranslationArrays( MatrixPtr, int );
|
|||
|
||||
|
||||
|
||||
int WriteCol_original(MatrixPtr Matrix, int Col, spREAL *CSC_Element, int *CSC_Row, spREAL **bind_Sparse, spREAL **bind_KLU, spREAL **diag) {
|
||||
|
||||
int i=0;
|
||||
ElementPtr current=Matrix->FirstInCol[Col];
|
||||
while (current!=NULL) {
|
||||
// spREAL element=current->Real;
|
||||
bind_Sparse [i] = (double *)current ;
|
||||
// CSC_Element[i]=element;
|
||||
bind_KLU [i] = &(CSC_Element [i]) ;
|
||||
CSC_Row[i]=(current->Row) - 1;
|
||||
if (CSC_Row [i] == Col - 1) diag [0] = &(CSC_Element [i]) ;
|
||||
i++;
|
||||
current=current->NextInCol;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* CLEAR MATRIX
|
||||
|
|
|
|||
|
|
@ -60,131 +60,6 @@ int Printer_Width = PRINTER_WIDTH;
|
|||
#include "ngspice/wstdio.h"
|
||||
#endif
|
||||
|
||||
void spMatrix_CSC(MatrixPtr Matrix, int *Ap, int *Ai, double *Ax, int n, double **bind_Sparse, double **bind_KLU, double **diag) {
|
||||
|
||||
int offset, i ;
|
||||
|
||||
offset=0;
|
||||
Ap[0]=offset;
|
||||
for (i=1;i<=n;i++) {
|
||||
offset+=WriteCol_original(Matrix, i, (spREAL*)((long)Ax+offset*sizeof(spREAL)),
|
||||
(int*)((long)Ai+offset*sizeof(int)),
|
||||
(spREAL **)((long)bind_Sparse + offset * sizeof(spREAL *)),
|
||||
(spREAL **)((long)bind_KLU + offset * sizeof(spREAL *)),
|
||||
(spREAL **)((long)diag + (i - 1) * sizeof(spREAL *)));
|
||||
|
||||
Ap[i]=offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void spMatrix_CSC_dump(MatrixPtr Matrix, char *CSC_output) {
|
||||
|
||||
int offset, i, j, *CSC_Ai, *CSC_Ap, *temp_vector_Ap, *temp_vector_Ai, *Q, *Q_new, n, nz, col;
|
||||
int pstart, pend, dim, k, max_index, max_Ai, temp_Ai;
|
||||
double **bind ; //FITTIZIO
|
||||
spREAL temp_elem, *CSC_A, *temp_vector_A;
|
||||
n=spGetSize(Matrix, 1);
|
||||
nz = Matrix->Elements ;
|
||||
Q=(int*)SP_MALLOC(int, n);
|
||||
temp_vector_Ap=(int*)SP_MALLOC(int, n+1);
|
||||
temp_vector_Ai=(int*)SP_MALLOC(int, nz);
|
||||
temp_vector_A=(spREAL*)SP_MALLOC(spREAL, nz);
|
||||
CSC_Ap=(int*)SP_MALLOC(int, n+1);
|
||||
CSC_Ai=(int*)SP_MALLOC(int, nz);
|
||||
CSC_A=(spREAL*)SP_MALLOC(spREAL, nz);
|
||||
|
||||
offset=0;
|
||||
temp_vector_Ap[0]=offset;
|
||||
for (i=1;i<=n;i++) {
|
||||
offset+=WriteCol_original(Matrix, i, (spREAL*)((long)temp_vector_A+offset*sizeof(spREAL)), (int*)((long)temp_vector_Ai+offset*sizeof(int)), (spREAL **)bind, (spREAL **)bind, (spREAL **)bind); //NON FUNZIONA PER ORA
|
||||
temp_vector_Ap[i]=offset;
|
||||
Q[i-1]=col;
|
||||
}
|
||||
|
||||
for (i=0;i<n;i++) {
|
||||
pstart=temp_vector_Ap[i];
|
||||
pend=temp_vector_Ap[i+1];
|
||||
dim=pend-pstart;
|
||||
for (j=0;j<dim;j++) {
|
||||
max_index=pstart;
|
||||
max_Ai=temp_vector_Ai[pstart];
|
||||
for (k=1;k<dim-j;k++) {
|
||||
if (max_Ai<temp_vector_Ai[pstart+k]) {
|
||||
max_index=pstart+k;
|
||||
max_Ai=temp_vector_Ai[pstart+k];
|
||||
}
|
||||
}
|
||||
temp_Ai=0;
|
||||
temp_Ai=temp_vector_Ai[pstart+dim-j-1];
|
||||
temp_vector_Ai[pstart+dim-j-1]=temp_vector_Ai[max_index];
|
||||
temp_vector_Ai[max_index]=temp_Ai;
|
||||
temp_Ai=0;
|
||||
temp_elem=0;
|
||||
temp_elem=temp_vector_A[pstart+dim-j-1];
|
||||
temp_vector_A[pstart+dim-j-1]=temp_vector_A[max_index];
|
||||
temp_vector_A[max_index]=temp_elem;
|
||||
temp_elem=0;
|
||||
}
|
||||
}
|
||||
|
||||
Q_new=(int*)SP_MALLOC(int, n);
|
||||
for (i=0;i<n;i++) Q_new[Q[i]]=i;
|
||||
offset=0;
|
||||
for (i=0;i<n;i++) {
|
||||
CSC_Ap[i]=offset;
|
||||
pstart=temp_vector_Ap[Q_new[i]];
|
||||
pend=temp_vector_Ap[Q_new[i]+1];
|
||||
for (j=pstart;j<pend;j++) {
|
||||
CSC_Ai[offset]=temp_vector_Ai[j];
|
||||
CSC_A[offset]=temp_vector_A[j];
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
CSC_Ap[n]=offset;
|
||||
|
||||
FILE *output;
|
||||
output=fopen(CSC_output, "w");
|
||||
fprintf(output, "%%%%MatrixMarket matrix coordinate real general\n");
|
||||
fprintf(output, "%%-------------------------------------------------------------------------------\n");
|
||||
fprintf(output, "%% Transient Matrix Dump\n%% Family: ISCAS Circuit\n");
|
||||
fprintf(output, "%%-------------------------------------------------------------------------------\n");
|
||||
fprintf(output, "%d %d %d\n", n, n, offset);
|
||||
for (i=0;i<n;i++) {
|
||||
for (j=CSC_Ap[i];j<CSC_Ap[i+1];j++) fprintf(output, "%d %d %-.9g\n", CSC_Ai[j]+1, i+1, CSC_A[j]);
|
||||
}
|
||||
fclose(output);
|
||||
|
||||
free(Q);
|
||||
free(Q_new);
|
||||
free(temp_vector_Ap);
|
||||
free(temp_vector_Ai);
|
||||
free(temp_vector_A);
|
||||
free(CSC_Ap);
|
||||
free(CSC_Ai);
|
||||
free(CSC_A);
|
||||
|
||||
}
|
||||
|
||||
void spRHS_CSC_dump(RealNumber *RHS, char *CSC_output_b, MatrixPtr Matrix) {
|
||||
|
||||
int n, i;
|
||||
n=spGetSize(Matrix, 1);
|
||||
FILE *output;
|
||||
output=fopen(CSC_output_b, "w");
|
||||
fprintf(output, "%%%%MatrixMarket matrix array real general\n");
|
||||
fprintf(output, "%%-------------------------------------------------------------------------------\n");
|
||||
fprintf(output, "%% Transient RHS Vector Dump\n%% Family: ISCAS Circuit\n");
|
||||
fprintf(output, "%%-------------------------------------------------------------------------------\n");
|
||||
fprintf(output, "%d %d\n", n, 1);
|
||||
for (i=1;i<n+1;i++) fprintf(output, "%-.9g\n", RHS[i]);
|
||||
fclose(output);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if DOCUMENTATION
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue