/[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 4829 by caltinay, Thu Apr 3 04:02:53 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_ptr SparseMatrix::getSubmatrix(int n_row_sub, int n_col_sub,
45        Paso_Pattern* sub_pattern=NULL;                                              const index_t* row_list,
46        Paso_SparseMatrix* out=NULL;                                              const index_t* new_col_index) const
47        index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);  {
48        int i,k,tmp,m,subpattern_row;      SparseMatrix_ptr out;
49        int type=A->type;      Esys_resetError();
50        Paso_resetError();      if (type & MATRIX_FORMAT_CSC) {
51        if (A->type & MATRIX_FORMAT_CSC) {          Esys_setError(TYPE_ERROR, "SparseMatrix::getSubmatrix: gathering submatrices supports CSR matrix format only.");
52            Paso_setError(TYPE_ERROR,"gathering submatrices supports CSR matrix format only.");          return out;
53        } else {      }
54           sub_pattern=Paso_Pattern_getSubpattern(A->pattern,n_row_sub,n_col_sub,row_list,new_col_index);  
55           if (Paso_noError()) {      const index_t index_offset = (type & MATRIX_FORMAT_OFFSET1 ? 1:0);
56              /* create the return object */      Pattern_ptr sub_pattern(pattern->getSubpattern(n_row_sub, n_col_sub,
57              out=Paso_SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size);                                                     row_list, new_col_index));
58              if (Paso_noError()) {      if (Esys_noError()) {
59                   #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)          // create the return object
60                   for (i=0;i<n_row_sub;++i) {          out.reset(new SparseMatrix(type, sub_pattern, row_block_size,
61                       subpattern_row=row_list[i];                                     col_block_size, true));
62                       for (k=A->pattern->ptr[subpattern_row]-index_offset;k<A->pattern->ptr[subpattern_row+1]-index_offset;++k) {          if (Esys_noError()) {
63                          tmp=new_col_index[A->pattern->index[k]-index_offset];  #pragma omp parallel for
64                          if (tmp>-1) {              for (int i=0; i<n_row_sub; ++i) {
65                             #pragma ivdep                  const index_t subpattern_row = row_list[i];
66                             for (m=out->pattern->ptr[i]-index_offset;m<out->pattern->ptr[i+1]-index_offset;++m) {                  for (int k=pattern->ptr[subpattern_row]-index_offset;
67                                 if (out->pattern->index[m]==tmp+index_offset) {                          k < pattern->ptr[subpattern_row+1]-index_offset; ++k) {
68                                     Paso_copyDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));                      index_t tmp=new_col_index[pattern->index[k]-index_offset];
69                                     break;                      if (tmp > -1) {
70                                 }                          #pragma ivdep
71                             }                          for (index_t m=out->pattern->ptr[i]-index_offset;
72                                    m < out->pattern->ptr[i+1]-index_offset; ++m) {
73                                if (out->pattern->index[m]==tmp+index_offset) {
74                                    Paso_copyShortDouble(block_size, &val[k*block_size], &out->val[m*block_size]);
75                                    break;
76                                }
77                          }                          }
78                       }                      }
79                   }                  }
80                }
81            }
82        }
83        return out;
84    }
85    
86    SparseMatrix_ptr SparseMatrix::getBlock(int blockid) const
87    {
88        const dim_t blocksize = row_block_size;
89        const dim_t n = numRows;
90        SparseMatrix_ptr out(new SparseMatrix(type, pattern, 1, 1, 0));
91    
92        if (blocksize==1) {
93            if (blockid==1) {
94    #pragma omp parallel for
95                for (dim_t i=0; i<n; ++i) {
96                    for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
97                        out->val[iptr] = val[iptr];
98                    }
99                }
100            } else {
101                Esys_setError(VALUE_ERROR, "SparseMatrix::getBlock: Invalid block ID requested.");
102            }
103        } else if (blocksize==2) {
104            if (blockid==1) {
105    #pragma omp parallel for
106                for (dim_t i=0; i<n; i++) {
107                    for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
108                        out->val[iptr] = val[4*iptr];
109                    }
110              }              }
111           }          } else if (blockid==2) {
112           Paso_Pattern_free(sub_pattern);  #pragma omp parallel for
113        }              for (dim_t i=0; i<n; i++) {
114        return out;                  for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
115                        out->val[iptr] = val[4*iptr+3];
116                    }
117                }
118            } else {
119                Esys_setError(VALUE_ERROR, "SparseMatrix::getBlock: Invalid block ID requested.");
120            }
121        } else if (blocksize==3) {
122            if (blockid==1) {
123    #pragma omp parallel for
124                for (dim_t i=0; i<n; i++) {
125                    for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
126                        out->val[iptr] = val[9*iptr];
127                    }
128                }
129            } else if (blockid==2) {
130    #pragma omp parallel for
131                for (dim_t i=0; i<n; i++) {
132                    for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
133                        out->val[iptr] = val[9*iptr+4];
134                    }
135                }
136            } else if (blockid==3) {
137    #pragma omp parallel for
138                for (dim_t i=0; i<n; i++) {
139                    for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
140                        out->val[iptr] = val[9*iptr+8];
141                    }
142                }
143            } else {
144                Esys_setError(VALUE_ERROR, "SparseMatrix::getBlock: Invalid block ID requested.");
145            }
146        }
147        return out;
148  }  }
149    
150    } // namespace paso
151    

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

  ViewVC Help
Powered by ViewVC 1.1.26