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

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

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

revision 415 by gross, Wed Jan 4 05:37:33 2006 UTC revision 1562 by gross, Wed May 21 13:04:40 2008 UTC
# Line 1  Line 1 
1    
2  /* $Id$ */  /* $Id$ */
3    
4    /*******************************************************
5     *
6     *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  /**************************************************************/  /**************************************************************/
17    
18  /* Paso: Matrix Market format is loaded to a SystemMatrix   */  /* Paso: Matrix Market format is loaded to a SystemMatrix   */
# Line 83  void q_sort( index_t *row, index_t *col, Line 96  void q_sort( index_t *row, index_t *col,
96    
97  Paso_SystemMatrix* Paso_SystemMatrix_loadMM_toCSR( char *fileName_p )  Paso_SystemMatrix* Paso_SystemMatrix_loadMM_toCSR( char *fileName_p )
98  {  {
99      int i, curr_row;          index_t dist[2];
100      MM_typecode matrixCode;          Paso_Distribution* input_dist=NULL, *output_dist=NULL;
         Paso_resetError();  
   
101      index_t *col_ind = NULL;      index_t *col_ind = NULL;
102      index_t *row_ind = NULL;      index_t *row_ind = NULL;
103      index_t *row_ptr = NULL;      index_t *row_ptr = NULL;
104      double *val = NULL;      double *val = NULL;
105        FILE *fileHandle_p = NULL;
106      Paso_SystemMatrixPattern *loc_pattern = NULL;          Paso_Pattern* mainPattern=NULL, *couplePattern=NULL;
107        Paso_SystemMatrixPattern *pattern = NULL;
108      Paso_SystemMatrix *out = NULL;      Paso_SystemMatrix *out = NULL;
109            Paso_SharedComponents *send =NULL;
110            Paso_Connector *connector=NULL;
111        int i, curr_row;
112        MM_typecode matrixCode;
113            Paso_MPIInfo* mpi_info=Paso_MPIInfo_alloc( MPI_COMM_WORLD);
114            Paso_resetError();
115            if (mpi_info->size >1) {
116            Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSR: support single processor only");
117            return NULL;
118            }
119      /* open the file */      /* open the file */
120      FILE *fileHandle_p = fopen( fileName_p, "r" );      fileHandle_p = fopen( fileName_p, "r" );
121      if( fileHandle_p == NULL )      if( fileHandle_p == NULL )
122      {      {
123          Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Cannot read file for reading.");          Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Cannot read file for reading.");
124                    Paso_MPIInfo_free(mpi_info);
125          return NULL;          return NULL;
126      }      }
127    
# Line 107  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 129  Paso_SystemMatrix* Paso_SystemMatrix_loa
129      if( mm_read_banner(fileHandle_p, &matrixCode) != 0 )      if( mm_read_banner(fileHandle_p, &matrixCode) != 0 )
130      {      {
131          Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Error processing MM banner.");          Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Error processing MM banner.");
132                    Paso_MPIInfo_free(mpi_info);
133          fclose( fileHandle_p );          fclose( fileHandle_p );
134          return NULL;          return NULL;
135      }      }
# Line 114  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 137  Paso_SystemMatrix* Paso_SystemMatrix_loa
137      {      {
138    
139          Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_loadMM_toCSR: found Matrix Market type is not supported.");          Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_loadMM_toCSR: found Matrix Market type is not supported.");
140                    Paso_MPIInfo_free(mpi_info);
141          fclose( fileHandle_p );          fclose( fileHandle_p );
142          return NULL;          return NULL;
143      }      }
# Line 122  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 146  Paso_SystemMatrix* Paso_SystemMatrix_loa
146      if( mm_read_mtx_crd_size(fileHandle_p, &M, &N, &nz) != 0 )      if( mm_read_mtx_crd_size(fileHandle_p, &M, &N, &nz) != 0 )
147      {      {
148          Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Could not parse matrix size");          Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Could not parse matrix size");
149                    Paso_MPIInfo_free(mpi_info);
150          fclose( fileHandle_p );          fclose( fileHandle_p );
151          return NULL;          return NULL;
152      }      }
# Line 137  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 162  Paso_SystemMatrix* Paso_SystemMatrix_loa
162      {      {
163          Paso_setError(MEMORY_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Could not allocate memory" );          Paso_setError(MEMORY_ERROR, "Paso_SystemMatrix_loadMM_toCSR: Could not allocate memory" );
164    
165                    Paso_MPIInfo_free(mpi_info);
166          fclose( fileHandle_p );          fclose( fileHandle_p );
167          return NULL;          return NULL;
168      }      }
# Line 163  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 189  Paso_SystemMatrix* Paso_SystemMatrix_loa
189      }      }
190      row_ptr[M] = nz;      row_ptr[M] = nz;
191    
192            /* create return value */
193      /* create F_SMP and F_SM */      /* create F_SMP and F_SM */
194      loc_pattern = Paso_SystemMatrixPattern_alloc(PATTERN_FORMAT_DEFAULT, M, row_ptr, col_ind );          dist[0]=0;
195      if(! Paso_noError() )          dist[1]=M;
196          return NULL;          output_dist=Paso_Distribution_alloc(mpi_info, dist,1,0);
197            dist[1]=N;
198      out = Paso_SystemMatrix_alloc(MATRIX_FORMAT_DEFAULT, loc_pattern, 1, 1 );          input_dist=Paso_Distribution_alloc(mpi_info, dist,1,0);
199      if(! Paso_noError() )          mainPattern=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,1,1,M,row_ptr,row_ind);
200          return NULL;          couplePattern=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,1,1,M,NULL,NULL);
201            send=Paso_SharedComponents_alloc(M,0,NULL,NULL,NULL,1,0,mpi_info);
202            connector=Paso_Connector_alloc(send,send);
203            pattern=Paso_SystemMatrixPattern_alloc(PATTERN_FORMAT_DEFAULT,output_dist,input_dist,
204                                                   mainPattern,couplePattern,couplePattern,connector,connector);
205    
206        out = Paso_SystemMatrix_alloc(MATRIX_FORMAT_DEFAULT, pattern, 1, 1);
207      /* copy values and cleanup temps */      /* copy values and cleanup temps */
208      for( i=0; i<nz; i++ )      for( i=0; i<nz; i++ ) out->mainBlock->val[i] = val[i];
         out->val[i] = val[i];  
209    
210            Paso_SystemMatrixPattern_free(pattern);
211            Paso_Pattern_free(mainPattern);
212            Paso_Pattern_free(couplePattern);
213            Paso_Connector_free(connector);
214            Paso_Distribution_free(output_dist);
215            Paso_Distribution_free(input_dist);
216        Paso_SharedComponents_free(send);
217            Paso_MPIInfo_free(mpi_info);
218      MEMFREE( val );      MEMFREE( val );
219      MEMFREE( row_ind );      MEMFREE( row_ind );
220    
# Line 184  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 223  Paso_SystemMatrix* Paso_SystemMatrix_loa
223    
224  Paso_SystemMatrix* Paso_SystemMatrix_loadMM_toCSC( char *fileName_p )  Paso_SystemMatrix* Paso_SystemMatrix_loadMM_toCSC( char *fileName_p )
225  {  {
226      int i;          index_t dist[2];
227  //  int curr_row;          Paso_Distribution* input_dist=NULL, *output_dist=NULL;
228      int curr_col;      FILE *fileHandle_p = NULL;
229      MM_typecode matrixCode;          Paso_Pattern* mainPattern=NULL, *couplePattern=NULL;
230        Paso_SystemMatrixPattern *pattern = NULL;
231        Paso_SystemMatrix *out = NULL;
232            Paso_SharedComponents *send =NULL;
233            Paso_Connector *connector=NULL;
234      index_t *col_ind = NULL;      index_t *col_ind = NULL;
235      index_t *row_ind = NULL;      index_t *row_ind = NULL;
 //  index_t *row_ptr = NULL;  
236      index_t *col_ptr = NULL;      index_t *col_ptr = NULL;
237      double *val = NULL;      double *val = NULL;
238        int i, curr_col=0;
239      Paso_SystemMatrixPattern *loc_pattern = NULL;      MM_typecode matrixCode;
240      Paso_SystemMatrix *out = NULL;          Paso_MPIInfo* mpi_info=Paso_MPIInfo_alloc( MPI_COMM_WORLD);
241            if (mpi_info->size >1) {
242            Paso_setError(IO_ERROR, "Paso_SystemMatrix_loadMM_toCSC: support single processor only");
243            return NULL;
244            }
245    
246      Paso_resetError();      Paso_resetError();
247    
248      /* open the file */      /* open the file */
249      FILE *fileHandle_p = fopen( fileName_p, "r" );      fileHandle_p = fopen( fileName_p, "r" );
250      if( fileHandle_p == NULL )      if( fileHandle_p == NULL )
251      {      {
252          Paso_setError(IO_ERROR,"Paso_SystemMatrix_loadMM_toCSC: File could not be opened for reading");          Paso_setError(IO_ERROR,"Paso_SystemMatrix_loadMM_toCSC: File could not be opened for reading");
253                    Paso_MPIInfo_free(mpi_info);
254          return NULL;          return NULL;
255      }      }
256    
# Line 213  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 259  Paso_SystemMatrix* Paso_SystemMatrix_loa
259      {      {
260          Paso_setError(IO_ERROR,"Paso_SystemMatrix_loadMM_toCSC: Error processing MM banner");          Paso_setError(IO_ERROR,"Paso_SystemMatrix_loadMM_toCSC: Error processing MM banner");
261          fclose( fileHandle_p );          fclose( fileHandle_p );
262                    Paso_MPIInfo_free(mpi_info);
263          return NULL;          return NULL;
264      }      }
265      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)) )
266      {      {
267          Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_loadMM_toCSC: found Matrix Market type is not supported.");          Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_loadMM_toCSC: found Matrix Market type is not supported.");
268          fclose( fileHandle_p );          fclose( fileHandle_p );
269                    Paso_MPIInfo_free(mpi_info);
270          return NULL;          return NULL;
271      }      }
272    
# Line 227  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 275  Paso_SystemMatrix* Paso_SystemMatrix_loa
275      {      {
276          Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_loadMM_toCSC: found Matrix Market type is not supported.");          Paso_setError(TYPE_ERROR,"Paso_SystemMatrix_loadMM_toCSC: found Matrix Market type is not supported.");
277          fclose( fileHandle_p );          fclose( fileHandle_p );
278                    Paso_MPIInfo_free(mpi_info);
279          return NULL;          return NULL;
280      }      }
281    
# Line 235  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 284  Paso_SystemMatrix* Paso_SystemMatrix_loa
284      row_ind = MEMALLOC( nz, index_t );      row_ind = MEMALLOC( nz, index_t );
285      val = MEMALLOC( nz, double );      val = MEMALLOC( nz, double );
286    
 //  row_ptr = MEMALLOC( (M+1), index_t );  
287      col_ptr = MEMALLOC( (N+1), index_t );      col_ptr = MEMALLOC( (N+1), index_t );
288    
289    
 //  if( col_ind == NULL || row_ind == NULL || val == NULL || row_ptr == NULL )  
     if( col_ind == NULL || row_ind == NULL || val == NULL || col_ptr == NULL )  
     {  
         Paso_setError(MEMORY_ERROR,"Could not allocate memory" );  
         fclose( fileHandle_p );  
         return NULL;  
     }  
   
290      /* perform actual read of elements */      /* perform actual read of elements */
291      for( i=0; i<nz; i++ )      for( i=0; i<nz; i++ )
292      {      {
# Line 257  Paso_SystemMatrix* Paso_SystemMatrix_loa Line 297  Paso_SystemMatrix* Paso_SystemMatrix_loa
297      fclose( fileHandle_p );      fclose( fileHandle_p );
298    
299      /* sort the entries */      /* sort the entries */
 //  q_sort( row_ind, col_ind, val, 0, nz );  
300      q_sort( col_ind, row_ind, val, 0, nz );      q_sort( col_ind, row_ind, val, 0, nz );
301    
302      /* setup row_ptr */      /* setup row_ptr */
 //  curr_row = 0;  
     curr_col = 0;  
 //  for( i=0; (i<nz && curr_row<M); curr_row++ )  
303      for( i=0; (i<nz && curr_col<N); curr_col++ )      for( i=0; (i<nz && curr_col<N); curr_col++ )
304      {      {
 //      while( row_ind[i] != curr_row )  
305          while( col_ind[i] != curr_col )          while( col_ind[i] != curr_col )
306              i++;              i++;
 //      row_ptr[curr_row] = i;  
307          col_ptr[curr_col] = i;          col_ptr[curr_col] = i;
308      }      }
 //  row_ptr[M] = nz;  
309      col_ptr[N] = nz;      col_ptr[N] = nz;
310    
311      /* create F_SMP and F_SM */      /* create F_SMP and F_SM */
312  //  loc_pattern = Paso_SystemMatrixPattern_alloc(PATTERN_FORMAT_DEFAULT, M, row_ptr, col_ind );          dist[0]=0;
313      loc_pattern = Paso_SystemMatrixPattern_alloc(PATTERN_FORMAT_DEFAULT, N, col_ptr, row_ind );          dist[1]=N;
314      if(! Paso_noError() )          output_dist=Paso_Distribution_alloc(mpi_info, dist,1,0);
315          return NULL;          dist[1]=M;
316            input_dist=Paso_Distribution_alloc(mpi_info, dist,1,0);
317  //      out = Paso_SystemMatrix_alloc( MATRIX_FORMAT_DEFAULT, loc_pattern, 1, 1 );          mainPattern=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,1,1,N,col_ptr,col_ind);
318      out = Paso_SystemMatrix_alloc(  MATRIX_FORMAT_CSC, loc_pattern, 1, 1 );          couplePattern=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,1,1,N,NULL,NULL);
319      if(! Paso_noError() )          send=Paso_SharedComponents_alloc(N,0,NULL,NULL,NULL,1,0,mpi_info);
320          return NULL;          connector=Paso_Connector_alloc(send,send);
321            pattern=Paso_SystemMatrixPattern_alloc(PATTERN_FORMAT_DEFAULT,output_dist,input_dist,
322                                                   mainPattern,couplePattern,couplePattern,connector,connector);
323        out = Paso_SystemMatrix_alloc(MATRIX_FORMAT_CSC, pattern, 1, 1);
324      /* copy values and cleanup temps */      /* copy values and cleanup temps */
325      for( i=0; i<nz; i++ )      for( i=0; i<nz; i++ )
326          out->val[i] = val[i];          out->mainBlock->val[i] = val[i];
327    
328            Paso_SystemMatrixPattern_free(pattern);
329            Paso_Pattern_free(mainPattern);
330            Paso_Pattern_free(couplePattern);
331            Paso_Connector_free(connector);
332            Paso_Distribution_free(output_dist);
333            Paso_Distribution_free(input_dist);
334        Paso_SharedComponents_free(send);
335            Paso_MPIInfo_free(mpi_info);
336      MEMFREE( val );      MEMFREE( val );
 //  MEMFREE( row_ind );  
337      MEMFREE( col_ind );      MEMFREE( col_ind );
   
338      return out;      return out;
339  }  }
   
   
 /*  
  * $Log$  
  * Revision 1.2  2005/09/15 03:44:39  jgs  
  * Merge of development branch dev-02 back to main trunk on 2005-09-15  
  *  
  * Revision 1.1.2.1  2005/09/05 06:29:48  gross  
  * These files have been extracted from finley to define a stand alone libray for iterative  
  * linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but  
  * has not been tested yet.  
  *  
  *  
  */  

Legend:
Removed from v.415  
changed lines
  Added in v.1562

  ViewVC Help
Powered by ViewVC 1.1.26