#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <oski/common.h>
#include <oski/matrix.h>
#include <oski/matcreate.h>
#include "array_util.h"
#include "readhbpat.h"
Functions | |
static void | dDumpLine (FILE *fp) |
Eat up the rest of the current line. | |
static void | dParseIntFormat (const char *buf, size_t *num, size_t *size) |
Parse a Fortran-style integer format string. | |
static void | dReadVector (FILE *fp, size_t n, oski_index_t *where, size_t perline, size_t persize) |
Read a stream of formatted integers from an input file. | |
int | readhb_pattern (const char *filename, oski_index_t *p_m, oski_index_t *p_n, oski_index_t *p_nnz, oski_index_t **p_ptr, oski_index_t **p_ind, char *mattype) |
Read the raw pattern of a sparse matrix stored in Harwell-Boeing formatted file in compressed-sparse column format. | |
static int | is_csc_lower_tri (oski_index_t n, const oski_index_t *ptr, const oski_index_t *ind, oski_index_t base) |
Returns 1 <==> the given CSC matrix array pattern corresponds to that of a lower triangular matrix, and 0 otherwise. | |
static int | is_csc_upper_tri (oski_index_t n, const oski_index_t *ptr, const oski_index_t *ind, oski_index_t base) |
Returns 1 <==> the given CSC matrix array pattern corresponds to that of a upper triangular matrix, and 0 otherwise. | |
static void | ResetDiagImag (oski_index_t m, oski_index_t *ptr, oski_index_t *ind, oski_value_t *val, oski_index_t indbase) |
Sets the imaginary part of the diagonal elements to 0. | |
static void | reduce_offdiag_values (oski_index_t n, const oski_index_t *ptr, const oski_index_t *ind, oski_value_t *val, oski_index_t indbase) |
Reduce off-diagonal values by a factor of 2*n Main purpose of this routine is to make triangular matrices better-conditioned. | |
static oski_index_t | count_diag_elems (oski_index_t n, const oski_index_t *ptr, const oski_index_t *ind, oski_index_t indbase) |
Returns the number of diagonal elements. | |
oski_matrix_t | readhb_pattern_matrix (const char *matfile, oski_index_t *p_m, oski_index_t *p_n, char *p_mattype, int expand_symm) |
Read the pattern of a sparse matrix from a Harwell-Boeing formatted file, and return it as a tunable matrix handle. | |
oski_matrix_t | readhb_pattern_matrix_nnz (const char *matfile, oski_index_t *p_m, oski_index_t *p_n, oski_index_t *p_nnz_stored, oski_index_t *p_nnz_true, char *p_mattype, int expand_symm) |
Only the pattern is read from the file. |
Adapted from the "dreadhb.c" routine written by Xiaoye Li <xiaoye@nersc.gov> for SuperLU v2.0.
-- SuperLU routine (version 2.0) -- Univ. of California Berkeley, Xerox Palo Alto Research Center, and Lawrence Berkeley National Lab. November 15, 1997
Updated: August 2, 2001 by rich vuduc <richie@cs.berkeley.edu>
Updated: November 10, 2002 by rich vuduc <richie@cs.berkeley.edu>
Updated: October 2004 by rich vuduc <richie@cs.berkeley.edu>
Updated: November 2004 by rich vuduc <richie@cs.berkeley.edu>
static void dDumpLine | ( | FILE * | fp | ) | [static] |
Eat up the rest of the current line.
Reads characters one by one from 'fp' beginning at the current file position until a new-line ('\n') or carriage-return ('\r') is encountered.
[in,out] | fp | File. |
Referenced by readhb_pattern().
static void dParseIntFormat | ( | const char * | buf, | |
size_t * | num, | |||
size_t * | size | |||
) | [static] |
Parse a Fortran-style integer format string.
This routine parses integer format strings given by the regular expression:
.* \( [0-9]* [Ii] [0-9]+
e.g., "(5I7)" (5 integers, each of maximum width 7), "(I14junk" (1 integer, of maximum width 14).
[in] | buf | Buffer containing the format. |
[out] | num | Number of integers. |
[out] | size | String width of integer. |
Referenced by readhb_pattern().
static void dReadVector | ( | FILE * | fp, | |
size_t | n, | |||
oski_index_t * | where, | |||
size_t | perline, | |||
size_t | persize | |||
) | [static] |
Read a stream of formatted integers from an input file.
[in,out] | fp | File. |
[in] | n | Total number of integers to read. |
[out] | where | Array in which to return the integers read. |
[in] | perline | Number of integers per line of the input file. |
[in] | persize | Exact distance (in characters) between consecutive integer starting locations in the file. |
References oski_PrintDebugMessage().
Referenced by readhb_pattern().
int readhb_pattern | ( | const char * | filename, | |
oski_index_t * | p_m, | |||
oski_index_t * | p_n, | |||
oski_index_t * | p_nnz, | |||
oski_index_t ** | p_ptr, | |||
oski_index_t ** | p_ind, | |||
char * | mattype | |||
) |
Read the raw pattern of a sparse matrix stored in Harwell-Boeing formatted file in compressed-sparse column format.
[in] | filename | Name of the Harwell-Boeing file. |
[out] | p_m | Number of rows in the matrix. |
[out] | p_n | Number of columns in the matrix. |
[out] | p_nnz | Number of logical (NOT stored) non-zeros. |
[out] | p_ptr | Stores the column pointers. |
[out] | p_ind | Stores the row indices. |
[out] | mattype | Pointer to a buffer of size 4, used to return the Harwell-Boeing matrix type (see Note below). |
Second character
Third character
References dDumpLine(), dParseIntFormat(), dReadVector(), ERR_BAD_ARG, ERR_FILE_READ, ERR_OUT_OF_MEMORY, OSKI_ERR, OSKI_ERR_FILE_READ, oski_Free, oski_HandleError, oski_Malloc, and oski_PrintDebugMessage().
oski_matrix_t readhb_pattern_matrix_nnz | ( | const char * | matfile, | |
oski_index_t * | p_m, | |||
oski_index_t * | p_n, | |||
oski_index_t * | p_nnz_stored, | |||
oski_index_t * | p_nnz_true, | |||
char * | p_mattype, | |||
int | expand_symm | |||
) |
Only the pattern is read from the file.
Read the pattern of a sparse matrix from a Harwell-Boeing formatted file, and return it as a tunable matrix handle.
The non-zero values are replaced by random numbers in the interval (0,1].
[in] | matfile | File to read. |
[in,out] | p_m | Pointer to scalar integer in which to return the number of matrix rows. May set to NULL if this information is not desired. |
[in,out] | p_n | Pointer to scalar integer in which to return the number of matrix columns. May set to NULL if this information is not desired. |
[in,out] | p_nnz_stored | Pointer to scalar integer in which to return the number of stored non-zeros. |
[in,out] | p_nnz_true | Pointer to scalar integer in which to return the number of true non-zeros. |
[in,out] | p_mattype | String buffer of length >= 3 in which to store the matrix type. May set to NULL if this information is not desired. This routine does NOT NULL-terminate mattype on return. |
References COPY_INPUTMAT, ERR_OUT_OF_MEMORY, INVALID_MAT, is_csc_lower_tri(), is_csc_upper_tri(), MACRO_TO_STRING, MAT_GENERAL, MAT_HERM_FULL, MAT_HERM_LOWER, MAT_HERM_UPPER, MAT_SYMM_FULL, MAT_SYMM_LOWER, MAT_SYMM_UPPER, MAT_TRI_LOWER, MAT_TRI_UPPER, OSKI_ERR, oski_Free, oski_Malloc, oski_PrintDebugMessage(), reduce_offdiag_values(), and ResetDiagImag().
static void ResetDiagImag | ( | oski_index_t | m, | |
oski_index_t * | ptr, | |||
oski_index_t * | ind, | |||
oski_value_t * | val, | |||
oski_index_t | indbase | |||
) | [static] |
Sets the imaginary part of the diagonal elements to 0.
This routine is used primarily to ensure that the diagonal of a Hermitian matrix is pure real.
References _RE, MAKE_VAL_COMPLEX, and VAL_ASSIGN.
Referenced by readhb_pattern_matrix_nnz().