/[escript]/trunk/paso/src/SparseMatrix.c
ViewVC logotype

Diff of /trunk/paso/src/SparseMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3258 by gross, Fri Aug 13 08:38:06 2010 UTC revision 3259 by jfenwick, Mon Oct 11 01:48:14 2010 UTC
# Line 109  Paso_SparseMatrix* Paso_SparseMatrix_all Line 109  Paso_SparseMatrix* Paso_SparseMatrix_all
109    bool_t unroll=FALSE;    bool_t unroll=FALSE;
110    
111    if (type & MATRIX_FORMAT_SYM) {    if (type & MATRIX_FORMAT_SYM) {
112       Paso_setError(TYPE_ERROR,"Paso_SparseMatrix_alloc: symmetric matrix pattern are not supported.");       Esys_setError(TYPE_ERROR,"Paso_SparseMatrix_alloc: symmetric matrix pattern are not supported.");
113       return NULL;       return NULL;
114    }    }
115    
116    if (patternIsUnrolled) {    if (patternIsUnrolled) {
117       if (! XNOR(type & MATRIX_FORMAT_OFFSET1, pattern->type & PATTERN_FORMAT_OFFSET1) ) {       if (! XNOR(type & MATRIX_FORMAT_OFFSET1, pattern->type & PATTERN_FORMAT_OFFSET1) ) {
118           Paso_setError(TYPE_ERROR,"Paso_SparseMatrix_alloc: requested offset and pattern offset does not match.");           Esys_setError(TYPE_ERROR,"Paso_SparseMatrix_alloc: requested offset and pattern offset does not match.");
119           return NULL;           return NULL;
120       }       }
121    }    }
# Line 132  Paso_SparseMatrix* Paso_SparseMatrix_all Line 132  Paso_SparseMatrix* Paso_SparseMatrix_all
132    
133    pattern_format_out= (type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1:  PATTERN_FORMAT_DEFAULT;    pattern_format_out= (type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1:  PATTERN_FORMAT_DEFAULT;
134    
135    Paso_resetError();    Esys_resetError();
136    out=MEMALLOC(1,Paso_SparseMatrix);    out=MEMALLOC(1,Paso_SparseMatrix);
137    if (! Paso_checkPtr(out)) {      if (! Esys_checkPtr(out)) {  
138       out->pattern=NULL;         out->pattern=NULL;  
139       out->val=NULL;         out->val=NULL;  
140       out->reference_counter=1;       out->reference_counter=1;
# Line 156  Paso_SparseMatrix* Paso_SparseMatrix_all Line 156  Paso_SparseMatrix* Paso_SparseMatrix_all
156                out->row_block_size=row_block_size;                out->row_block_size=row_block_size;
157                out->col_block_size=col_block_size;                out->col_block_size=col_block_size;
158             }             }
159             if (Paso_noError()) {             if (Esys_noError()) {
160                out->numRows = out->pattern->numInput;                out->numRows = out->pattern->numInput;
161                out->numCols = out->pattern->numOutput;                out->numCols = out->pattern->numOutput;
162             }             }
# Line 175  Paso_SparseMatrix* Paso_SparseMatrix_all Line 175  Paso_SparseMatrix* Paso_SparseMatrix_all
175                out->row_block_size=row_block_size;                out->row_block_size=row_block_size;
176                out->col_block_size=col_block_size;                out->col_block_size=col_block_size;
177             }             }
178             if (Paso_noError()) {             if (Esys_noError()) {
179                 out->numRows = out->pattern->numOutput;                 out->numRows = out->pattern->numOutput;
180                 out->numCols = out->pattern->numInput;                 out->numCols = out->pattern->numInput;
181             }             }
182       }       }
183       if (Paso_noError()) {       if (Esys_noError()) {
184           out->block_size=out->row_block_size*out->col_block_size;           out->block_size=out->row_block_size*out->col_block_size;
185           out->len=(size_t)(out->pattern->len)*(size_t)(out->block_size);           out->len=(size_t)(out->pattern->len)*(size_t)(out->block_size);
186            
187           out->val=MEMALLOC(out->len,double);           out->val=MEMALLOC(out->len,double);
188           if (! Paso_checkPtr(out->val)) Paso_SparseMatrix_setValues(out,DBLE(0));           if (! Esys_checkPtr(out->val)) Paso_SparseMatrix_setValues(out,DBLE(0));
189       }       }
190    }    }
191    /* all done: */    /* all done: */
192    if (Paso_noError()) {    if (Esys_noError()) {
193      return out;      return out;
194    } else {    } else {
195      Paso_SparseMatrix_free(out);      Paso_SparseMatrix_free(out);
# Line 231  Paso_SparseMatrix* Paso_SparseMatrix_loa Line 231  Paso_SparseMatrix* Paso_SparseMatrix_loa
231      Paso_SparseMatrix *out = NULL;      Paso_SparseMatrix *out = NULL;
232      int i, curr_row, scan_ret;      int i, curr_row, scan_ret;
233      MM_typecode matrixCode;      MM_typecode matrixCode;
234          Paso_resetError();          Esys_resetError();
235    
236      /* open the file */      /* open the file */
237      fileHandle_p = fopen( fileName_p, "r" );      fileHandle_p = fopen( fileName_p, "r" );
238      if( fileHandle_p == NULL )      if( fileHandle_p == NULL )
239      {      {
240          Paso_setError(IO_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Cannot read file for reading.");          Esys_setError(IO_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Cannot read file for reading.");
241          return NULL;          return NULL;
242      }      }
243    
244      /* process banner */      /* process banner */
245      if( mm_read_banner(fileHandle_p, &matrixCode) != 0 )      if( mm_read_banner(fileHandle_p, &matrixCode) != 0 )
246      {      {
247          Paso_setError(IO_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Error processing MM banner.");          Esys_setError(IO_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Error processing MM banner.");
248          fclose( fileHandle_p );          fclose( fileHandle_p );
249          return NULL;          return NULL;
250      }      }
251      if( !(mm_is_real(matrixCode) && mm_is_sparse(matrixCode) && mm_is_general(matrixCode)) )      if( !(mm_is_real(matrixCode) && mm_is_sparse(matrixCode) && mm_is_general(matrixCode)) )
252      {      {
253    
254          Paso_setError(TYPE_ERROR,"Paso_SparseMatrix_loadMM_toCSR: found Matrix Market type is not supported.");          Esys_setError(TYPE_ERROR,"Paso_SparseMatrix_loadMM_toCSR: found Matrix Market type is not supported.");
255          fclose( fileHandle_p );          fclose( fileHandle_p );
256          return NULL;          return NULL;
257      }      }
# Line 259  Paso_SparseMatrix* Paso_SparseMatrix_loa Line 259  Paso_SparseMatrix* Paso_SparseMatrix_loa
259      /* get matrix size */      /* get matrix size */
260      if( mm_read_mtx_crd_size(fileHandle_p, &M, &N, &nz) != 0 )      if( mm_read_mtx_crd_size(fileHandle_p, &M, &N, &nz) != 0 )
261      {      {
262          Paso_setError(IO_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Could not parse matrix size");          Esys_setError(IO_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Could not parse matrix size");
263          fclose( fileHandle_p );          fclose( fileHandle_p );
264          return NULL;          return NULL;
265      }      }
# Line 273  Paso_SparseMatrix* Paso_SparseMatrix_loa Line 273  Paso_SparseMatrix* Paso_SparseMatrix_loa
273    
274      if( col_ind == NULL || row_ind == NULL || val == NULL || row_ptr == NULL )      if( col_ind == NULL || row_ind == NULL || val == NULL || row_ptr == NULL )
275      {      {
276          Paso_setError(MEMORY_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Could not allocate memory" );          Esys_setError(MEMORY_ERROR, "Paso_SparseMatrix_loadMM_toCSR: Could not allocate memory" );
277          fclose( fileHandle_p );          fclose( fileHandle_p );
278          return NULL;          return NULL;
279      }      }
# Line 327  void Paso_SparseMatrix_saveMM(Paso_Spars Line 327  void Paso_SparseMatrix_saveMM(Paso_Spars
327    MM_typecode matcode;                            MM_typecode matcode;                        
328    
329    if (A_p->col_block_size !=A_p->row_block_size) {    if (A_p->col_block_size !=A_p->row_block_size) {
330      Paso_setError(TYPE_ERROR, "Paso_SparseMatrix_saveMM: currently only square blocks are supported.");      Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_saveMM: currently only square blocks are supported.");
331      return;      return;
332    }    }
333    if (A_p->row_block_size>3) {    if (A_p->row_block_size>3) {
334         Paso_setError(TYPE_ERROR,"Paso_SparseMatrix_saveMM: currently only block size 3 is supported.\n");         Esys_setError(TYPE_ERROR,"Paso_SparseMatrix_saveMM: currently only block size 3 is supported.\n");
335         return;         return;
336    }    }
337    
338    if (A_p->type & MATRIX_FORMAT_SYM) {    if (A_p->type & MATRIX_FORMAT_SYM) {
339      Paso_setError(TYPE_ERROR,"Paso_SparseMatrix_saveMM does not support symmetric storage scheme");      Esys_setError(TYPE_ERROR,"Paso_SparseMatrix_saveMM does not support symmetric storage scheme");
340      return;      return;
341    }    }
342        
343    /* open the file */    /* open the file */
344    fileHandle_p = fopen(fileName_p, "w");    fileHandle_p = fopen(fileName_p, "w");
345    if (fileHandle_p==NULL) {    if (fileHandle_p==NULL) {
346      Paso_setError(IO_ERROR,"file could not be opened for writing");      Esys_setError(IO_ERROR,"file could not be opened for writing");
347      return;      return;
348    }    }
349    
350    if (A_p->type & MATRIX_FORMAT_CSC) {    if (A_p->type & MATRIX_FORMAT_CSC) {
351      Paso_setError(TYPE_ERROR,"Paso_SparseMatrix_saveMM does not support CSC yet.");      Esys_setError(TYPE_ERROR,"Paso_SparseMatrix_saveMM does not support CSC yet.");
352    } else {    } else {
353      mm_initialize_typecode(&matcode);      mm_initialize_typecode(&matcode);
354      mm_set_matrix(&matcode);      mm_set_matrix(&matcode);

Legend:
Removed from v.3258  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC 1.1.26