Simplified IJMatrixRead and IJMatrixPrint file formats. Did not change
the corresponding IJVector routines, but should. Fixed opaque type stuff for IJMatrix and IJVector.
This commit is contained in:
parent
c97af0ce03
commit
3ac73987e0
@ -488,27 +488,49 @@ HYPRE_IJMatrixSetDiagOffdSizes( HYPRE_IJMatrix matrix,
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
HYPRE_IJMatrixRead( const char *filename, MPI_Comm comm, int type,
|
||||
HYPRE_IJMatrix *matrix)
|
||||
HYPRE_IJMatrixRead( const char *filename,
|
||||
MPI_Comm comm,
|
||||
int type,
|
||||
HYPRE_IJMatrix *matrix_ptr )
|
||||
{
|
||||
int ierr = 0;
|
||||
hypre_IJMatrix *ijmatrix;
|
||||
HYPRE_IJMatrix matrix;
|
||||
int ilower, iupper, jlower, jupper;
|
||||
int nrows, ncols, I, J;
|
||||
double value;
|
||||
int myid;
|
||||
char new_filename[255];
|
||||
FILE *file;
|
||||
|
||||
/* if ( type == HYPRE_PETSC )
|
||||
ierr = hypre_IJMatrixReadPETSc( comm, filename, &ijmatrix );
|
||||
else if ( type == HYPRE_ISIS )
|
||||
ierr = hypre_IJMatrixReadISIS( comm, filename, &ijmatrix );
|
||||
else */ if ( type == HYPRE_PARCSR )
|
||||
ierr = hypre_IJMatrixReadParCSR( comm, filename, &ijmatrix );
|
||||
else
|
||||
MPI_Comm_rank(comm, &myid);
|
||||
|
||||
sprintf(new_filename,"%s.%05d", filename, myid);
|
||||
|
||||
if ((file = fopen(new_filename, "r")) == NULL)
|
||||
{
|
||||
printf("Unrecognized object type -- HYPRE_IJMatrixRead\n");
|
||||
printf("Error: can't open input file %s\n", new_filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
*matrix = (HYPRE_IJMatrix ) ijmatrix;
|
||||
hypre_IJMatrixAssembleFlag(ijmatrix) = 1;
|
||||
|
||||
fscanf(file, "%d %d %d %d", &ilower, &iupper, &jlower, &jupper);
|
||||
ierr = HYPRE_IJMatrixCreate(comm, ilower, iupper, jlower, jupper, &matrix);
|
||||
|
||||
ierr += HYPRE_IJMatrixSetObjectType(matrix, type);
|
||||
ierr += HYPRE_IJMatrixInitialize(matrix);
|
||||
|
||||
nrows = 1;
|
||||
ncols = 1;
|
||||
while ( fscanf(file, "%d %d %le", &I, &J, &value) != EOF )
|
||||
{
|
||||
ierr += HYPRE_IJMatrixSetValues(matrix, nrows, &ncols, &I, &J, &value);
|
||||
}
|
||||
|
||||
ierr += HYPRE_IJMatrixAssemble(matrix);
|
||||
|
||||
fclose(file);
|
||||
|
||||
*matrix_ptr = matrix;
|
||||
|
||||
return ierr;
|
||||
}
|
||||
|
||||
@ -517,30 +539,85 @@ HYPRE_IJMatrixRead( const char *filename, MPI_Comm comm, int type,
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int
|
||||
HYPRE_IJMatrixPrint( HYPRE_IJMatrix matrix, const char *filename)
|
||||
HYPRE_IJMatrixPrint( HYPRE_IJMatrix matrix,
|
||||
const char *filename )
|
||||
{
|
||||
int ierr = 0;
|
||||
hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;
|
||||
MPI_Comm comm = hypre_IJMatrixComm(matrix);
|
||||
int *row_partitioning;
|
||||
int *col_partitioning;
|
||||
int ilower, iupper, jlower, jupper;
|
||||
int i, j, ii;
|
||||
int ncols, *cols;
|
||||
double *values;
|
||||
int myid;
|
||||
char new_filename[255];
|
||||
FILE *file;
|
||||
void *object;
|
||||
|
||||
if (!ijmatrix)
|
||||
{
|
||||
printf("Variable ijmatrix is NULL -- HYPRE_IJMatrixPrint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PETSC )
|
||||
ierr = hypre_IJMatrixPrintPETSc( ijmatrix , filename );
|
||||
else if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_ISIS )
|
||||
ierr = hypre_IJMatrixPrintISIS( ijmatrix , filename );
|
||||
else */
|
||||
|
||||
if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
|
||||
ierr = hypre_IJMatrixPrintParCSR( ijmatrix , filename );
|
||||
else
|
||||
if ( (hypre_IJMatrixObjectType(matrix) != HYPRE_PARCSR) )
|
||||
{
|
||||
printf("Unrecognized object type -- HYPRE_IJMatrixPrint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
MPI_Comm_rank(comm, &myid);
|
||||
|
||||
sprintf(new_filename,"%s.%05d", filename, myid);
|
||||
|
||||
if ((file = fopen(new_filename, "w")) == NULL)
|
||||
{
|
||||
printf("Error: can't open output file %s\n", new_filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!matrix)
|
||||
{
|
||||
printf("Variable matrix is NULL -- HYPRE_IJMatrixPrint\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
row_partitioning = hypre_IJMatrixRowPartitioning(matrix);
|
||||
col_partitioning = hypre_IJMatrixColPartitioning(matrix);
|
||||
ilower = row_partitioning[myid];
|
||||
iupper = row_partitioning[myid+1] - 1;
|
||||
jlower = col_partitioning[myid];
|
||||
jupper = col_partitioning[myid+1] - 1;
|
||||
|
||||
fprintf(file, "%d %d %d %d\n", ilower, iupper, jlower, jupper);
|
||||
|
||||
ierr += HYPRE_IJMatrixGetObject(matrix, &object);
|
||||
|
||||
for (i = ilower; i <= iupper; i++)
|
||||
{
|
||||
if ( hypre_IJMatrixObjectType(matrix) == HYPRE_PARCSR )
|
||||
{
|
||||
ii = i - row_partitioning[0];
|
||||
ierr += HYPRE_ParCSRMatrixGetRow((HYPRE_ParCSRMatrix) object,
|
||||
ii, &ncols, &cols, &values);
|
||||
for (j = 0; j < ncols; j++)
|
||||
{
|
||||
cols[j] += col_partitioning[0];
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < ncols; j++)
|
||||
{
|
||||
fprintf(file, "%d %d %le\n", i, cols[j], values[j]);
|
||||
}
|
||||
|
||||
if ( hypre_IJMatrixObjectType(matrix) == HYPRE_PARCSR )
|
||||
{
|
||||
for (j = 0; j < ncols; j++)
|
||||
{
|
||||
cols[j] -= col_partitioning[0];
|
||||
}
|
||||
ierr += HYPRE_ParCSRMatrixRestoreRow((HYPRE_ParCSRMatrix) object,
|
||||
ii, &ncols, &cols, &values);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
return ierr;
|
||||
}
|
||||
|
||||
@ -1344,79 +1344,3 @@ hypre_IJMatrixDestroyParCSR(hypre_IJMatrix *matrix)
|
||||
ierr += hypre_AuxParCSRMatrixDestroy(hypre_IJMatrixTranslator(matrix));
|
||||
return ierr;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* hypre_IJMatrixPrintParCSR
|
||||
*
|
||||
* prints an IJMatrix for debugging purposes
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
hypre_IJMatrixPrintParCSR(hypre_IJMatrix *matrix,
|
||||
const char *filename)
|
||||
{
|
||||
int ierr = 0;
|
||||
int *row_partitioning = hypre_IJMatrixRowPartitioning(matrix);
|
||||
int *col_partitioning = hypre_IJMatrixColPartitioning(matrix);
|
||||
ierr = hypre_ParCSRMatrixPrintIJ(hypre_IJMatrixObject(matrix),
|
||||
row_partitioning[0],
|
||||
col_partitioning[0],
|
||||
filename);
|
||||
return ierr;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* hypre_IJMatrixReadParCSR
|
||||
*
|
||||
* reads an IJMatrix from files generated by hypre_IJMatrixPrintParCSR
|
||||
*
|
||||
*****************************************************************************/
|
||||
int
|
||||
hypre_IJMatrixReadParCSR(MPI_Comm comm,
|
||||
const char *filename,
|
||||
hypre_IJMatrix **matrix)
|
||||
{
|
||||
int ierr = 0;
|
||||
hypre_ParCSRMatrix *par_matrix;
|
||||
int base_i, base_j;
|
||||
int num_procs, i;
|
||||
int *row_partitioning;
|
||||
int *col_partitioning;
|
||||
int *row_starts;
|
||||
int *col_starts;
|
||||
MPI_Comm_size(comm,&num_procs);
|
||||
ierr = hypre_ParCSRMatrixReadIJ( comm, filename,
|
||||
&base_i, &base_j, &par_matrix);
|
||||
row_starts = hypre_ParCSRMatrixRowStarts(par_matrix);
|
||||
col_starts = hypre_ParCSRMatrixColStarts(par_matrix);
|
||||
|
||||
*matrix = hypre_CTAlloc(hypre_IJMatrix,1);
|
||||
hypre_IJMatrixComm(*matrix) = comm;
|
||||
hypre_IJMatrixObject(*matrix) = par_matrix;
|
||||
hypre_IJMatrixTranslator(*matrix) = NULL;
|
||||
hypre_IJMatrixObjectType(*matrix) = HYPRE_PARCSR;
|
||||
|
||||
row_partitioning = hypre_CTAlloc(int, num_procs+1);
|
||||
if (row_starts == col_starts && base_i == base_j)
|
||||
{
|
||||
for (i=0; i < num_procs+1; i++)
|
||||
row_partitioning[i] = row_starts[i] + base_i;
|
||||
col_partitioning = row_partitioning;
|
||||
}
|
||||
else
|
||||
{
|
||||
col_partitioning = hypre_CTAlloc(int, num_procs+1);
|
||||
for (i=0; i < num_procs+1; i++)
|
||||
{
|
||||
row_partitioning[i] = row_starts[i] + base_i;
|
||||
col_partitioning[i] = col_starts[i] + base_j;
|
||||
}
|
||||
}
|
||||
hypre_IJMatrixRowPartitioning(*matrix) = row_partitioning;
|
||||
hypre_IJMatrixColPartitioning(*matrix) = col_partitioning;
|
||||
|
||||
return ierr;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
* hypre_IJMatrix:
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
typedef struct hypre_IJMatrix_struct
|
||||
{
|
||||
MPI_Comm comm;
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ typedef struct
|
||||
* hypre_IJMatrix:
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
typedef struct hypre_IJMatrix_struct
|
||||
{
|
||||
MPI_Comm comm;
|
||||
|
||||
@ -167,7 +167,7 @@ hypre_GetIJMatrixISISMatrix( HYPRE_IJMatrix IJmatrix, RowMatrix *reference )
|
||||
* hypre_IJVector:
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
typedef struct hypre_IJVector_struct
|
||||
{
|
||||
MPI_Comm comm;
|
||||
|
||||
@ -236,8 +236,6 @@ int hypre_IJMatrixSetValuesParCSR( hypre_IJMatrix *matrix , int nrows , int *nco
|
||||
int hypre_IJMatrixAddToValuesParCSR( hypre_IJMatrix *matrix , int nrows , int *ncols , const int *rows , const int *cols , const double *values );
|
||||
int hypre_IJMatrixAssembleParCSR( hypre_IJMatrix *matrix );
|
||||
int hypre_IJMatrixDestroyParCSR( hypre_IJMatrix *matrix );
|
||||
int hypre_IJMatrixPrintParCSR( hypre_IJMatrix *matrix , const char *filename );
|
||||
int hypre_IJMatrixReadParCSR( MPI_Comm comm , const char *filename , hypre_IJMatrix **matrix );
|
||||
|
||||
/* IJMatrix_petsc.c */
|
||||
int hypre_IJMatrixSetLocalSizePETSc( hypre_IJMatrix *matrix , int local_m , int local_n );
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
* hypre_IJVector:
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
typedef struct hypre_IJVector_struct
|
||||
{
|
||||
MPI_Comm comm;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user