Revision 117 - (show annotations)
Fri Apr 1 05:48:57 2005 UTC (15 years ago) by jgs
File MIME type: text/plain
File size: 4422 byte(s)
```*** empty log message ***

```
 1 /* \$Id\$ */ 2 3 /**************************************************************/ 4 5 /* Finley: Matrix Market format is loaded to a SystemMatrix */ 6 7 /**************************************************************/ 8 9 /* Copyrights by ACcESS Australia 2003,2004,2005 */ 10 /* Author: imran@access.edu.au */ 11 12 /**************************************************************/ 13 14 #include "Finley.h" 15 #include "mmio.h" 16 #include "System.h" 17 18 static void swap( maybelong*, maybelong*, double*, int, int ); 19 static void q_sort( maybelong*, maybelong*, double*, int, int ); 20 static void print_entries( maybelong*, maybelong*, double* ); 21 22 static int M, N, nz; 23 24 25 /* debug: print the entries */ 26 void print_entries( maybelong *r, maybelong *c, double *v ) 27 { 28 int i; 29 30 for( i=0; i begin ) 61 { 62 pivot = N * row[begin] + col[begin]; 63 l = begin + 1; 64 r = end; 65 66 while( l < r ) 67 { 68 lval = N * row[l] + col[l]; 69 if( lval < pivot ) 70 l++; 71 else 72 { 73 r--; 74 swap( row, col, val, l, r ); 75 } 76 } 77 l--; 78 swap( row, col, val, begin, l ); 79 q_sort( row, col, val, begin, l ); 80 q_sort( row, col, val, r, end ); 81 } 82 } 83 84 Finley_SystemMatrix* Finley_SystemMatrix_loadMM_toCSR( char *fileName_p ) 85 { 86 int i, curr_row; 87 MM_typecode matrixCode; 88 89 maybelong *col_ind = NULL; 90 maybelong *row_ind = NULL; 91 maybelong *row_ptr = NULL; 92 double *val = NULL; 93 94 Finley_SystemMatrixPattern *loc_pattern = NULL; 95 Finley_SystemMatrixType type = UNKNOWN; 96 Finley_SystemMatrix *out = NULL; 97 98 Finley_ErrorCode = NO_ERROR; 99 100 /* open the file */ 101 FILE *fileHandle_p = fopen( fileName_p, "r" ); 102 if( fileHandle_p == NULL ) 103 { 104 Finley_ErrorCode = IO_ERROR; 105 sprintf( Finley_ErrorMsg, "File %s could not be opened for reading", fileName_p ); 106 return NULL; 107 } 108 109 /* process banner */ 110 if( mm_read_banner(fileHandle_p, &matrixCode) != 0 ) 111 { 112 Finley_ErrorCode = IO_ERROR; 113 sprintf( Finley_ErrorMsg, "Error processing MM banner in file %s", fileName_p ); 114 115 fclose( fileHandle_p ); 116 return NULL; 117 } 118 if( !(mm_is_real(matrixCode) && mm_is_sparse(matrixCode) && mm_is_general(matrixCode)) ) 119 { 120 Finley_ErrorCode = TYPE_ERROR; 121 sprintf( Finley_ErrorMsg, "Sorry, Matrix Market type: [%s] is not supported", mm_typecode_to_str(matrixCode) ); 122 123 fclose( fileHandle_p ); 124 return NULL; 125 } 126 127 /* get matrix size */ 128 if( mm_read_mtx_crd_size(fileHandle_p, &M, &N, &nz) != 0 ) 129 { 130 Finley_ErrorCode = IO_ERROR; 131 sprintf( Finley_ErrorMsg, "Could not parse matrix size in %s", fileName_p ); 132 133 fclose( fileHandle_p ); 134 return NULL; 135 } 136 137 /* prepare storage */ 138 col_ind = MEMALLOC( nz, maybelong ); 139 row_ind = MEMALLOC( nz, maybelong ); 140 val = MEMALLOC( nz, double ); 141 142 row_ptr = MEMALLOC( (M+1), maybelong ); 143 144 if( col_ind == NULL || row_ind == NULL || val == NULL || row_ptr == NULL ) 145 { 146 Finley_ErrorCode = MEMORY_ERROR; 147 sprintf( Finley_ErrorMsg, "Could not allocate memory" ); 148 149 fclose( fileHandle_p ); 150 return NULL; 151 } 152 153 /* perform actual read of elements */ 154 for( i=0; ival[i] = val[i]; 188 189 MEMFREE( val ); 190 MEMFREE( row_ind ); 191 192 return out; 193 } 194 195 196 /* 197 * \$Log\$ 198 * Revision 1.2 2005/04/01 05:48:56 jgs 199 * *** empty log message *** 200 * 201 * Revision 1.1.2.1 2005/03/30 05:00:31 imran 202 * Added a MM load (as CSR) function 203 * 204 * 205 */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision