Skip to content

Commit

Permalink
In dcreate_matrix.c, only ask Proc 0 generate Xtrue, then bcast to al…
Browse files Browse the repository at this point in the history
…l Procs, avoiding

    inconsistency due to use of rand() on different Procs.
In pdgstrs.c, initialize nub when DEBEGlevel>=2.
  • Loading branch information
xiaoyeli committed Apr 25, 2022
1 parent 0b1eafe commit 21b1544
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 197 deletions.
Binary file modified EXAMPLE/batch_summit_1cpu1gpu.sh
Binary file not shown.
145 changes: 96 additions & 49 deletions EXAMPLE/dcreate_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ at the top-level directory.
* Purpose
* =======
*
* DCREATE_MATRIX read the matrix from data file in Harwell-Boeing format,
* and distribute it to processors in a distributed compressed row format.
* It also generate the distributed true solution X and the right-hand
* side RHS.
* DCREATE_MATRIX_POSTFIX read the matrix from data file in different formats
* depending on the surfix of the file name. The supported formats include:
* .rua / cua : Harwell-Boeing format
* .rb : Rutherford-Boeing format
* .mtx : Matrix Market format
* .dat : triplet format with a header line {n nnz}
* .ddatnh : triplet format without a header
* .bin : binary format
* The routine distribute the matrix to processors in a distributed
* compressed row format. It also generate the distributed true solution X
* and the right-hand side RHS.
*
*
* Arguments
Expand All @@ -58,14 +65,17 @@ at the top-level directory.
* FP (input) FILE*
* The matrix file pointer.
*
* POSTFIX (input) char*
* The surfix string of the filename.
*
* GRID (input) gridinof_t*
* The 2D process mesh.
* </pre>
*/

int dcreate_matrix(SuperMatrix *A, int nrhs, double **rhs,
int dcreate_matrix_postfix(SuperMatrix *A, int nrhs, double **rhs,
int *ldb, double **x, int *ldx,
FILE *fp, gridinfo_t *grid)
FILE *fp, char * postfix, gridinfo_t *grid)
{
SuperMatrix GA; /* global A */
double *b_global, *xtrue_global; /* replicated on all processes */
Expand All @@ -89,14 +99,33 @@ int dcreate_matrix(SuperMatrix *A, int nrhs, double **rhs,
#endif

if ( !iam ) {
double t = SuperLU_timer_();
double t = SuperLU_timer_();

/* Read the matrix stored on disk in Harwell-Boeing format. */
dreadhb_dist(iam, fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
if(!strcmp(postfix,"rua")){
/* Read the matrix stored on disk in Harwell-Boeing format. */
dreadhb_dist(iam, fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"mtx")){
/* Read the matrix stored on disk in Matrix Market format. */
dreadMM_dist(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"rb")){
/* Read the matrix stored on disk in Rutherford-Boeing format. */
dreadrb_dist(iam, fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"dat")){
/* Read the matrix stored on disk in triplet format. */
dreadtriple_dist(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"datnh")){
/* Read the matrix stored on disk in triplet format (without header). */
dreadtriple_noheader(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"bin")){
/* Read the matrix stored on disk in binary format. */
dread_binary(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else {
ABORT("File format not known");
}

printf("Time to read and distribute matrix %.2f\n",
SuperLU_timer_() - t); fflush(stdout);

/* Broadcast matrix A to the other PEs. */
MPI_Bcast( &m, 1, mpi_int_t, 0, grid->comm );
MPI_Bcast( &n, 1, mpi_int_t, 0, grid->comm );
Expand Down Expand Up @@ -144,9 +173,17 @@ int dcreate_matrix(SuperMatrix *A, int nrhs, double **rhs,
ABORT("Malloc fails for xtrue[]");
*trans = 'N';

dGenXtrue_dist(n, nrhs, xtrue_global, n);
dFillRHS_dist(trans, nrhs, xtrue_global, n, &GA, b_global, m);

if (iam == 0) {
dGenXtrue_dist(n, nrhs, xtrue_global, n);
dFillRHS_dist(trans, nrhs, xtrue_global, n, &GA, b_global, m);

MPI_Bcast( xtrue_global, n*nrhs, MPI_DOUBLE, 0, grid->comm );
MPI_Bcast( b_global, m*nrhs, MPI_DOUBLE, 0, grid->comm );
} else {
MPI_Bcast( xtrue_global, n*nrhs, MPI_DOUBLE, 0, grid->comm );
MPI_Bcast( b_global, m*nrhs, MPI_DOUBLE, 0, grid->comm );
}

/*************************************************
* Change GA to a local A with NR_loc format *
*************************************************/
Expand Down Expand Up @@ -234,10 +271,49 @@ int dcreate_matrix(SuperMatrix *A, int nrhs, double **rhs,
return 0;
}


int dcreate_matrix_postfix(SuperMatrix *A, int nrhs, double **rhs,
/* \brief
*
* <pre>
* Purpose
* =======
*
* DCREATE_MATRIX read the matrix from data file in Harwell-Boeing format,
* and distribute it to processors in a distributed compressed row format.
* It also generate the distributed true solution X and the right-hand
* side RHS.
*
*
* Arguments
* =========
*
* A (output) SuperMatrix*
* Local matrix A in NR_loc format.
*
* NRHS (input) int_t
* Number of right-hand sides.
*
* RHS (output) double**
* The right-hand side matrix.
*
* LDB (output) int*
* Leading dimension of the right-hand side matrix.
*
* X (output) double**
* The true solution matrix.
*
* LDX (output) int*
* The leading dimension of the true solution matrix.
*
* FP (input) FILE*
* The matrix file pointer.
*
* GRID (input) gridinof_t*
* The 2D process mesh.
* </pre>
*/
int dcreate_matrix(SuperMatrix *A, int nrhs, double **rhs,
int *ldb, double **x, int *ldx,
FILE *fp, char * postfix, gridinfo_t *grid)
FILE *fp, gridinfo_t *grid)
{
SuperMatrix GA; /* global A */
double *b_global, *xtrue_global; /* replicated on all processes */
Expand All @@ -261,33 +337,14 @@ int dcreate_matrix_postfix(SuperMatrix *A, int nrhs, double **rhs,
#endif

if ( !iam ) {
double t = SuperLU_timer_();
double t = SuperLU_timer_();

if(!strcmp(postfix,"rua")){
/* Read the matrix stored on disk in Harwell-Boeing format. */
dreadhb_dist(iam, fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"mtx")){
/* Read the matrix stored on disk in Matrix Market format. */
dreadMM_dist(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"rb")){
/* Read the matrix stored on disk in Rutherford-Boeing format. */
dreadrb_dist(iam, fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"dat")){
/* Read the matrix stored on disk in triplet format. */
dreadtriple_dist(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"datnh")){
/* Read the matrix stored on disk in triplet format (without header). */
dreadtriple_noheader(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else if(!strcmp(postfix,"bin")){
/* Read the matrix stored on disk in binary format. */
dread_binary(fp, &m, &n, &nnz, &nzval, &rowind, &colptr);
}else {
ABORT("File format not known");
}
/* Read the matrix stored on disk in Harwell-Boeing format. */
dreadhb_dist(iam, fp, &m, &n, &nnz, &nzval, &rowind, &colptr);

printf("Time to read and distribute matrix %.2f\n",
SuperLU_timer_() - t); fflush(stdout);

/* Broadcast matrix A to the other PEs. */
MPI_Bcast( &m, 1, mpi_int_t, 0, grid->comm );
MPI_Bcast( &n, 1, mpi_int_t, 0, grid->comm );
Expand Down Expand Up @@ -338,16 +395,6 @@ int dcreate_matrix_postfix(SuperMatrix *A, int nrhs, double **rhs,
dGenXtrue_dist(n, nrhs, xtrue_global, n);
dFillRHS_dist(trans, nrhs, xtrue_global, n, &GA, b_global, m);

if (iam == 0) {
double xmax = 0.0, xmin = 1.0e+15;
for (i = 0; i < n; ++i) {
xmax = SUPERLU_MAX(xmax, xtrue_global[i]);
xmin = SUPERLU_MIN(xmin, xtrue_global[i]);
}
//printf("Kappa(x): xmax %e / xmin %e = %e\n", xmax, xmin, xmax / xmin);
//fflush(stdout);
}

/*************************************************
* Change GA to a local A with NR_loc format *
*************************************************/
Expand Down
2 changes: 1 addition & 1 deletion EXAMPLE/psdrive.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ int main(int argc, char *argv[])
sSolveFinalize(&options, &SOLVEstruct);
SUPERLU_FREE(b);
SUPERLU_FREE(xtrue);
SUPERLU_FREE(dxtrue);
SUPERLU_FREE(err_bounds);
SUPERLU_FREE(berr);
if ( options.IterRefine >= SLU_DOUBLE ) SUPERLU_FREE(dxtrue);

/* ------------------------------------------------------------
RELEASE THE SUPERLU PROCESS GRID.
Expand Down
Loading

0 comments on commit 21b1544

Please sign in to comment.