void dreadhb(int *nrow, int *ncol, int *nonz, double **nzval, int **rowind, int **colptr) { /* * Purpose * ======= * * Read a DOUBLE PRECISION matrix stored in Harwell-Boeing format * as described below. * * Line 1 (A72,A8) * Col. 1 - 72 Title (TITLE) * Col. 73 - 80 Key (KEY) * * Line 2 (5I14) * Col. 1 - 14 Total number of lines excluding header (TOTCRD) * Col. 15 - 28 Number of lines for pointers (PTRCRD) * Col. 29 - 42 Number of lines for row (or variable) indices (INDCRD) * Col. 43 - 56 Number of lines for numerical values (VALCRD) * Col. 57 - 70 Number of lines for right-hand sides (RHSCRD) * (including starting guesses and solution vectors * if present) * (zero indicates no right-hand side data is present) * * Line 3 (A3, 11X, 4I14) * Col. 1 - 3 Matrix type (see below) (MXTYPE) * Col. 15 - 28 Number of rows (or variables) (NROW) * Col. 29 - 42 Number of columns (or elements) (NCOL) * Col. 43 - 56 Number of row (or variable) indices (NNZERO) * (equal to number of entries for assembled matrices) * Col. 57 - 70 Number of elemental matrix entries (NELTVL) * (zero in the case of assembled matrices) * Line 4 (2A16, 2A20) * Col. 1 - 16 Format for pointers (PTRFMT) * Col. 17 - 32 Format for row (or variable) indices (INDFMT) * Col. 33 - 52 Format for numerical values of coefficient matrix (VALFMT) * Col. 53 - 72 Format for numerical values of right-hand sides (RHSFMT) * * Line 5 (A3, 11X, 2I14) Only present if there are right-hand sides present * Col. 1 Right-hand side type: * F for full storage or M for same format as matrix * Col. 2 G if a starting vector(s) (Guess) is supplied. (RHSTYP) * Col. 3 X if an exact solution vector(s) is supplied. * Col. 15 - 28 Number of right-hand sides (NRHS) * Col. 29 - 42 Number of row indices (NRHSIX) * (ignored in case of unassembled matrices) * * The three character type field on line 3 describes the matrix type. * The following table lists the permitted values for each of the three * characters. As an example of the type field, RSA denotes that the matrix * is real, symmetric, and assembled. * * First Character: * R Real matrix * C Complex matrix * P Pattern only (no numerical values supplied) * * Second Character: * S Symmetric * U Unsymmetric * H Hermitian * Z Skew symmetric * R Rectangular * * Third Character: * A Assembled * E Elemental matrices (unassembled) * */ register int i, numer_lines, rhscrd = 0; int tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4], key[10]; FILE *fp; fp = stdin; /* Line 1 */ fscanf(fp, "%72c", buf); buf[72] = 0; printf("Title: %s", buf); fscanf(fp, "%8c", key); key[8] = 0; printf("Key: %s\n", key); dDumpLine(fp); /* Line 2 */ for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; sscanf(buf, "%d", &tmp); if (i == 3) numer_lines = tmp; if (i == 4 && tmp) rhscrd = tmp; } dDumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #ifdef DEBUG printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); sscanf(buf, "%d", nrow); fscanf(fp, "%14c", buf); sscanf(buf, "%d", ncol); fscanf(fp, "%14c", buf); sscanf(buf, "%d", nonz); fscanf(fp, "%14c", buf); sscanf(buf, "%d", &tmp); if (tmp != 0) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) printf("Matrix is not square.\n"); dDumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); dParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); dParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); dParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); dDumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) dDumpLine(fp); /* skip RHSFMT */ #ifdef DEBUG printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); #endif dReadVector(fp, *ncol+1, *colptr, colnum, colsize); dReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } fclose(fp); }
void dreadrb(int *nrow, int *ncol, int *nonz, double **nzval, int **rowind, int **colptr) { register int i, numer_lines = 0; int tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; int sym; FILE *fp; fp = stdin; /* Line 1 */ fgets(buf, 100, fp); fputs(buf, stdout); /* Line 2 */ for (i=0; i<4; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; sscanf(buf, "%d", &tmp); if (i == 3) numer_lines = tmp; } dDumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #ifdef DEBUG printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); sscanf(buf, "%d", nrow); fscanf(fp, "%14c", buf); sscanf(buf, "%d", ncol); fscanf(fp, "%14c", buf); sscanf(buf, "%d", nonz); fscanf(fp, "%14c", buf); sscanf(buf, "%d", &tmp); if (tmp != 0) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) printf("Matrix is not square.\n"); dDumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); dParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); dParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); dParseFloatFormat(buf, &valnum, &valsize); dDumpLine(fp); #ifdef DEBUG printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); ReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } sym = (type[1] == 'S' || type[1] == 's'); if ( sym ) { FormFullA(*ncol, nonz, nzval, rowind, colptr); } fclose(fp); }
void dreadrb_dist(int iam, FILE *fp, int_t *nrow, int_t *ncol, int_t *nonz, double **nzval, int_t **rowind, int_t **colptr) { register int_t i, numer_lines = 0; int_t tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; int sym; /* Line 1 */ fgets(buf, 100, fp); fputs(buf, stdout); /* Line 2 */ for (i=0; i<4; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (i == 3) numer_lines = tmp; } DumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #if (DEBUGlevel >= 1) if ( !iam ) printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); *nrow = atoi(buf); fscanf(fp, "%14c", buf); *ncol = atoi(buf); fscanf(fp, "%14c", buf); *nonz = atoi(buf); fscanf(fp, "%14c", buf); tmp = atoi(buf); if (tmp != 0) if ( !iam ) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) if ( !iam ) printf("Matrix is not square.\n"); DumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA_dist(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); ParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); ParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); ParseFloatFormat(buf, &valnum, &valsize); DumpLine(fp); #if (DEBUGlevel >= 1) if ( !iam ) { printf(IFMT " rows, " IFMT " nonzeros\n", *nrow, *nonz); printf("colnum " IFMT ", colsize " IFMT "\n", colnum, colsize); printf("rownum " IFMT ", rowsize " IFMT "\n", rownum, rowsize); printf("valnum " IFMT ", valsize " IFMT "\n", valnum, valsize); } #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); ReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } sym = (type[1] == 'S' || type[1] == 's'); if ( sym ) { FormFullA(*ncol, nonz, nzval, rowind, colptr); } fclose(fp); }
void dreadhb(int *nrow, int *ncol, int *nonz, double **nzval, int **rowind, int **colptr) { register int i, numer_lines = 0, rhscrd = 0; int tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4], key[10]; FILE *fp; fp = stdin; /* Line 1 */ fgets(buf, 100, fp); fputs(buf, stdout); #if 0 fscanf(fp, "%72c", buf); buf[72] = 0; printf("Title: %s", buf); fscanf(fp, "%8c", key); key[8] = 0; printf("Key: %s\n", key); dDumpLine(fp); #endif /* Line 2 */ for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; sscanf(buf, "%d", &tmp); if (i == 3) numer_lines = tmp; if (i == 4 && tmp) rhscrd = tmp; } dDumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #ifdef DEBUG printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); sscanf(buf, "%d", nrow); fscanf(fp, "%14c", buf); sscanf(buf, "%d", ncol); fscanf(fp, "%14c", buf); sscanf(buf, "%d", nonz); fscanf(fp, "%14c", buf); sscanf(buf, "%d", &tmp); if (tmp != 0) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) printf("Matrix is not square.\n"); dDumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); dParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); dParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); dParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); dDumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) dDumpLine(fp); /* skip RHSFMT */ #ifdef DEBUG printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); ReadVector(fp, *nonz, *rowind, rownum, rowsize); if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); } fclose(fp); }
void dreadhb_dist(int iam, FILE *fp, int_t *nrow, int_t *ncol, int_t *nonz, double **nzval, int_t **rowind, int_t **colptr) { /* * -- Distributed SuperLU routine (version 1.0) -- * Lawrence Berkeley National Lab, Univ. of California Berkeley. * September 1, 1999 * * * Purpose * ======= * * Read a DOUBLE PRECISION matrix stored in Harwell-Boeing format * as described below. * * Line 1 (A72,A8) * Col. 1 - 72 Title (TITLE) * Col. 73 - 80 Key (KEY) * * Line 2 (5I14) * Col. 1 - 14 Total number of lines excluding header (TOTCRD) * Col. 15 - 28 Number of lines for pointers (PTRCRD) * Col. 29 - 42 Number of lines for row (or variable) indices (INDCRD) * Col. 43 - 56 Number of lines for numerical values (VALCRD) * Col. 57 - 70 Number of lines for right-hand sides (RHSCRD) * (including starting guesses and solution vectors * if present) * (zero indicates no right-hand side data is present) * * Line 3 (A3, 11X, 4I14) * Col. 1 - 3 Matrix type (see below) (MXTYPE) * Col. 15 - 28 Number of rows (or variables) (NROW) * Col. 29 - 42 Number of columns (or elements) (NCOL) * Col. 43 - 56 Number of row (or variable) indices (NNZERO) * (equal to number of entries for assembled matrices) * Col. 57 - 70 Number of elemental matrix entries (NELTVL) * (zero in the case of assembled matrices) * Line 4 (2A16, 2A20) * Col. 1 - 16 Format for pointers (PTRFMT) * Col. 17 - 32 Format for row (or variable) indices (INDFMT) * Col. 33 - 52 Format for numerical values of coefficient matrix (VALFMT) * Col. 53 - 72 Format for numerical values of right-hand sides (RHSFMT) * * Line 5 (A3, 11X, 2I14) Only present if there are right-hand sides present * Col. 1 Right-hand side type: * F for full storage or M for same format as matrix * Col. 2 G if a starting vector(s) (Guess) is supplied. (RHSTYP) * Col. 3 X if an exact solution vector(s) is supplied. * Col. 15 - 28 Number of right-hand sides (NRHS) * Col. 29 - 42 Number of row indices (NRHSIX) * (ignored in case of unassembled matrices) * * The three character type field on line 3 describes the matrix type. * The following table lists the permitted values for each of the three * characters. As an example of the type field, RSA denotes that the matrix * is real, symmetric, and assembled. * * First Character: * R Real matrix * C Complex matrix * P Pattern only (no numerical values supplied) * * Second Character: * S Symmetric * U Unsymmetric * H Hermitian * Z Skew symmetric * R Rectangular * * Third Character: * A Assembled * E Elemental matrices (unassembled) * */ register int_t i, numer_lines, rhscrd = 0; int_t tmp, colnum, colsize, rownum, rowsize, valnum, valsize; char buf[100], type[4]; int_t sym; #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Enter dreadhb_dist()"); #endif /* Line 1 */ fgets(buf, 100, fp); /*dDumpLine(fp);*/ /*if ( !iam ) fflush(stdout);*/ /* Line 2 */ for (i=0; i<5; i++) { fscanf(fp, "%14c", buf); buf[14] = 0; tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (i == 3) numer_lines = tmp; if (i == 4 && tmp) rhscrd = tmp; } dDumpLine(fp); /* Line 3 */ fscanf(fp, "%3c", type); fscanf(fp, "%11c", buf); /* pad */ type[3] = 0; #if ( DEBUGlevel>=1 ) if ( !iam ) printf("Matrix type %s\n", type); #endif fscanf(fp, "%14c", buf); *nrow = atoi(buf); /*sscanf(buf, "%d", nrow);*/ fscanf(fp, "%14c", buf); *ncol = atoi(buf); /*sscanf(buf, "%d", ncol);*/ fscanf(fp, "%14c", buf); *nonz = atoi(buf); /*sscanf(buf, "%d", nonz);*/ fscanf(fp, "%14c", buf); tmp = atoi(buf); /*sscanf(buf, "%d", &tmp);*/ if (tmp != 0) if ( !iam ) printf("This is not an assembled matrix!\n"); if (*nrow != *ncol) if ( !iam ) printf("Matrix is not square.\n"); dDumpLine(fp); /* Allocate storage for the three arrays ( nzval, rowind, colptr ) */ dallocateA_dist(*ncol, *nonz, nzval, rowind, colptr); /* Line 4: format statement */ fscanf(fp, "%16c", buf); dParseIntFormat(buf, &colnum, &colsize); fscanf(fp, "%16c", buf); dParseIntFormat(buf, &rownum, &rowsize); fscanf(fp, "%20c", buf); dParseFloatFormat(buf, &valnum, &valsize); fscanf(fp, "%20c", buf); dDumpLine(fp); /* Line 5: right-hand side */ if ( rhscrd ) dDumpLine(fp); /* skip RHSFMT */ #if ( DEBUGlevel>=1 ) if ( !iam ) { printf("%d rows, %d nonzeros\n", *nrow, *nonz); printf("colnum %d, colsize %d\n", colnum, colsize); printf("rownum %d, rowsize %d\n", rownum, rowsize); printf("valnum %d, valsize %d\n", valnum, valsize); } #endif ReadVector(fp, *ncol+1, *colptr, colnum, colsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read colptr[%d] = %d\n", *ncol, (*colptr)[*ncol]); #endif ReadVector(fp, *nonz, *rowind, rownum, rowsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read rowind[%d] = %d\n", *nonz-1, (*rowind)[*nonz-1]); #endif if ( numer_lines ) { dReadValues(fp, *nonz, *nzval, valnum, valsize); #if ( DEBUGlevel>=1 ) if ( !iam ) printf("read nzval[%d] = %e\n", *nonz-1, (*nzval)[*nonz-1]); #endif } sym = (type[1] == 'S' || type[1] == 's'); if ( sym ) { FormFullA(*ncol, nonz, nzval, rowind, colptr); } /*if ( !iam ) fflush(stdout);*/ fclose(fp); #if ( DEBUGlevel>=1 ) CHECK_MALLOC(0, "Exit dreadhb_dist()"); #endif }