/[escript]/trunk/paso/src/SparseMatrix_getSubmatrix.cpp
ViewVC logotype

Diff of /trunk/paso/src/SparseMatrix_getSubmatrix.cpp

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

temp_trunk_copy/paso/src/SparseMatrix_getSubmatrix.c revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC trunk/paso/src/SparseMatrix_getSubmatrix.cpp revision 4819 by caltinay, Tue Apr 1 03:50:23 2014 UTC
# Line 1  Line 1 
1    
2  /* $Id: SparseMatrix_getSubmatrix.c 1306 2007-09-18 05:51:09Z ksteube $ */  /*****************************************************************************
3    *
4    * Copyright (c) 2003-2014 by University of Queensland
5    * http://www.uq.edu.au
6    *
7    * Primary Business: Queensland, Australia
8    * Licensed under the Open Software License version 3.0
9    * http://www.opensource.org/licenses/osl-3.0.php
10    *
11    * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    * Development 2012-2013 by School of Earth Sciences
13    * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14    *
15    *****************************************************************************/
16    
 /*******************************************************  
  *  
  *           Copyright 2003-2007 by ACceSS MNRF  
  *       Copyright 2007 by University of Queensland  
  *  
  *                http://esscc.uq.edu.au  
  *        Primary Business: Queensland, Australia  
  *  Licensed under the Open Software License version 3.0  
  *     http://www.opensource.org/licenses/osl-3.0.php  
  *  
  *******************************************************/  
17    
18  /**************************************************************/  /****************************************************************************/
19    
20  /* Paso: SparseMatrix */  /* Paso: SparseMatrix */
21    
22  /**************************************************************/  /****************************************************************************/
23    
24  /* Copyrights by ACcESS Australia 2003, 2004,2005 */  /* Copyrights by ACcESS Australia 2003, 2004,2005 */
25  /* Author: gross@access.edu.au */  /* Author: Lutz Gross, l.gross@uq.edu.au */
26    
27  /**************************************************************/  /****************************************************************************/
28    
29  #include "Paso.h"  #include "Paso.h"
30  #include "SparseMatrix.h"  #include "SparseMatrix.h"
31  #include "PasoUtil.h"  #include "PasoUtil.h"
32    
33  /**************************************************************  namespace paso {
34    
35      returns the submatrix of A where rows are gathered by index row_list  /*****************************************************************************
     and columns are selected by non-negative values of new_col_index.  
     if new_col_index[i]>-1 new_col_index[i] gives the column of i in  
     the returned submatrix  
36    
37        Returns the submatrix of A where rows are gathered by index row_list
38        and columns are selected by non-negative values of new_col_index.
39        If new_col_index[i]>-1 new_col_index[i] gives the column of i in
40        the returned submatrix.
41  */  */
42    
43    
44  Paso_SparseMatrix* Paso_SparseMatrix_getSubmatrix(Paso_SparseMatrix* A,int n_row_sub,int n_col_sub, index_t* row_list,index_t* new_col_index){  SparseMatrix* SparseMatrix_getSubmatrix(const SparseMatrix* A,int n_row_sub,
45        Paso_Pattern* sub_pattern=NULL;                                          int n_col_sub, const index_t* row_list,
46        Paso_SparseMatrix* out=NULL;                                          const index_t* new_col_index)
47        index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);  {
48        int i,k,tmp,m,subpattern_row;      SparseMatrix* out=NULL;
49        int type=A->type;      index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
50        Paso_resetError();      int i,k,tmp,m,subpattern_row;
51        if (A->type & MATRIX_FORMAT_CSC) {      int type=A->type;
52            Paso_setError(TYPE_ERROR,"gathering submatrices supports CSR matrix format only.");      Esys_resetError();
53        } else {      if (A->type & MATRIX_FORMAT_CSC) {
54           sub_pattern=Paso_Pattern_getSubpattern(A->pattern,n_row_sub,n_col_sub,row_list,new_col_index);          Esys_setError(TYPE_ERROR, "SparseMatrix_getSubmatrix: gathering submatrices supports CSR matrix format only.");
55           if (Paso_noError()) {      } else {
56            Pattern_ptr sub_pattern(A->pattern->getSubpattern(n_row_sub, n_col_sub,
57                                              row_list, new_col_index));
58            if (Esys_noError()) {
59              /* create the return object */              /* create the return object */
60              out=Paso_SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size);              out=SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
61              if (Paso_noError()) {              if (Esys_noError()) {
62                   #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)                  #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)
63                   for (i=0;i<n_row_sub;++i) {                  for (i=0;i<n_row_sub;++i) {
64                       subpattern_row=row_list[i];                      subpattern_row=row_list[i];
65                       for (k=A->pattern->ptr[subpattern_row]-index_offset;k<A->pattern->ptr[subpattern_row+1]-index_offset;++k) {                      for (k=A->pattern->ptr[subpattern_row]-index_offset;k<A->pattern->ptr[subpattern_row+1]-index_offset;++k) {
66                          tmp=new_col_index[A->pattern->index[k]-index_offset];                          tmp=new_col_index[A->pattern->index[k]-index_offset];
67                          if (tmp>-1) {                          if (tmp>-1) {
68                             #pragma ivdep                              #pragma ivdep
69                             for (m=out->pattern->ptr[i]-index_offset;m<out->pattern->ptr[i+1]-index_offset;++m) {                              for (m=out->pattern->ptr[i]-index_offset;m<out->pattern->ptr[i+1]-index_offset;++m) {
70                                 if (out->pattern->index[m]==tmp+index_offset) {                                  if (out->pattern->index[m]==tmp+index_offset) {
71                                     Paso_copyDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));                                     Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
72                                     break;                                     break;
73                                 }                                  }
74                             }                              }
75                          }                          }
76                       }                      }
77                   }                  }
78              }              }
79           }          }
80           Paso_Pattern_free(sub_pattern);      }
81        }      return out;
       return out;  
82  }  }
83    
84    SparseMatrix* SparseMatrix_getBlock(const SparseMatrix* A, int blockid)
85    {
86        dim_t blocksize=A->row_block_size,i;
87        dim_t n=A->numRows;
88        index_t iptr;
89        SparseMatrix* out = SparseMatrix_alloc(A->type, A->pattern, 1, 1, 0);
90    
91        if (blocksize==1) {
92            if (blockid==1) {
93                #pragma omp parallel for private(i,iptr) schedule(static)
94                for(i=0;i<n;++i) {
95                    for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
96                        out->val[iptr]=A->val[iptr];
97                    }
98                }
99            } else {
100                Esys_setError(VALUE_ERROR, "SparseMatrix_getBlock: Requested and actual block sizes do not match.");
101            }
102        } else if (blocksize==2) {
103            if (blockid==1) {
104                #pragma omp parallel for private(i,iptr) schedule(static)
105                for(i=0;i<n;i++) {
106                    for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
107                        out->val[iptr]=A->val[4*iptr];
108                    }
109                }
110            } else if (blockid==2) {
111                #pragma omp parallel for private(i,iptr) schedule(static)
112                for(i=0;i<n;i++) {
113                    for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
114                        out->val[iptr]=A->val[4*iptr+3];
115                    }
116                }
117            } else {
118                Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
119            }
120        } else if (blocksize==3) {
121            if (blockid==1) {
122                #pragma omp parallel for private(i,iptr) schedule(static)
123                for(i=0;i<n;i++) {
124                    for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
125                        out->val[iptr]=A->val[9*iptr];
126                    }
127                }
128            } else if (blockid==2) {
129                #pragma omp parallel for private(i,iptr) schedule(static)
130                for(i=0;i<n;i++) {
131                    for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
132                        out->val[iptr]=A->val[9*iptr+4];
133                    }
134                }
135            } else if (blockid==3) {
136                #pragma omp parallel for private(i,iptr) schedule(static)
137                for(i=0;i<n;i++) {
138                    for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
139                        out->val[iptr]=A->val[9*iptr+8];
140                    }
141                }
142            } else {
143                Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
144            }
145        }
146    
147        return out;
148    }
149    
150    } // namespace paso
151    

Legend:
Removed from v.1384  
changed lines
  Added in v.4819

  ViewVC Help
Powered by ViewVC 1.1.26