/[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

revision 1639 by gross, Mon Jul 14 08:55:25 2008 UTC revision 3642 by caltinay, Thu Oct 27 03:41:51 2011 UTC
# Line 1  Line 1 
1    
 /* $Id: SparseMatrix_getSubmatrix.c 1306 2007-09-18 05:51:09Z ksteube $ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2010 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  /**************************************************************/  /**************************************************************/
16    
# Line 20  Line 19 
19  /**************************************************************/  /**************************************************************/
20    
21  /* Copyrights by ACcESS Australia 2003, 2004,2005 */  /* Copyrights by ACcESS Australia 2003, 2004,2005 */
22  /* Author: gross@access.edu.au */  /* Author: Lutz Gross, l.gross@uq.edu.au */
23    
24  /**************************************************************/  /**************************************************************/
25    
# Line 30  Line 29 
29    
30  /**************************************************************  /**************************************************************
31    
32      returns the submatrix of A where rows are gathered by index row_list      Returns the submatrix of A where rows are gathered by index row_list
33      and columns are selected by non-negative values of new_col_index.      and columns are selected by non-negative values of new_col_index.
34      if new_col_index[i]>-1 new_col_index[i] gives the column of i in      If new_col_index[i]>-1 new_col_index[i] gives the column of i in
35      the returned submatrix      the returned submatrix.
   
36  */  */
37    
38    
# Line 44  Paso_SparseMatrix* Paso_SparseMatrix_get Line 42  Paso_SparseMatrix* Paso_SparseMatrix_get
42        index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);        index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
43        int i,k,tmp,m,subpattern_row;        int i,k,tmp,m,subpattern_row;
44        int type=A->type;        int type=A->type;
45        Paso_resetError();        Esys_resetError();
46        if (A->type & MATRIX_FORMAT_CSC) {        if (A->type & MATRIX_FORMAT_CSC) {
47            Paso_setError(TYPE_ERROR,"gathering submatrices supports CSR matrix format only.");            Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_getSubmatrix: gathering submatrices supports CSR matrix format only.");
48        } else {        } else {
49           sub_pattern=Paso_Pattern_getSubpattern(A->pattern,n_row_sub,n_col_sub,row_list,new_col_index);           sub_pattern=Paso_Pattern_getSubpattern(A->pattern,n_row_sub,n_col_sub,row_list,new_col_index);
50           if (Paso_noError()) {           if (Esys_noError()) {
51              /* create the return object */              /* create the return object */
52              out=Paso_SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size);              out=Paso_SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
53              if (Paso_noError()) {              if (Esys_noError()) {
54                   #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)
55                   for (i=0;i<n_row_sub;++i) {                   for (i=0;i<n_row_sub;++i) {
56                       subpattern_row=row_list[i];                       subpattern_row=row_list[i];
# Line 75  Paso_SparseMatrix* Paso_SparseMatrix_get Line 73  Paso_SparseMatrix* Paso_SparseMatrix_get
73        }        }
74        return out;        return out;
75  }  }
76    
77    Paso_SparseMatrix* Paso_SparseMatrix_getBlock(Paso_SparseMatrix* A, int blockid){
78          
79          dim_t blocksize=A->row_block_size,i;
80          dim_t n=A->numRows;
81          index_t iptr;
82          
83          Paso_SparseMatrix* out=NULL;
84        
85          out=Paso_SparseMatrix_alloc(A->type,A->pattern, 1, 1, 0);
86          
87          if (blocksize==1) {
88                if (blockid==1) {
89                      #pragma omp parallel for private(i,iptr) schedule(static)
90                      for(i=0;i<n;++i) {
91                          for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
92                                  out->val[iptr]=A->val[iptr];
93                          }
94                      }
95                }
96                else {
97                      Esys_setError(VALUE_ERROR, "Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
98                }
99          }
100          else if (blocksize==2) {
101                if (blockid==1) {
102                      #pragma omp parallel for private(i,iptr) schedule(static)
103                      for(i=0;i<n;i++) {
104                            for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
105                                  out->val[iptr]=A->val[4*iptr];
106                            }
107                      }
108                }
109                else if (blockid==2) {
110                      #pragma omp parallel for private(i,iptr) schedule(static)
111                      for(i=0;i<n;i++) {
112                            for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
113                                  out->val[iptr]=A->val[4*iptr+3];
114                            }
115                      }
116                }
117                else {
118                      Esys_setError(VALUE_ERROR,"Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
119                }
120          }
121          else if (blocksize==3) {
122                if (blockid==1) {
123                      #pragma omp parallel for private(i,iptr) schedule(static)
124                      for(i=0;i<n;i++) {
125                            for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
126                                        out->val[iptr]=A->val[9*iptr];
127                            }
128                      }
129                }
130                else if (blockid==2) {
131                      #pragma omp parallel for private(i,iptr) schedule(static)
132                      for(i=0;i<n;i++) {
133                            for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
134                                        out->val[iptr]=A->val[9*iptr+4];
135                            }
136                      }
137                }
138                else if (blockid==3) {
139                      #pragma omp parallel for private(i,iptr) schedule(static)
140                      for(i=0;i<n;i++) {
141                            for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
142                                        out->val[iptr]=A->val[9*iptr+8];
143                            }
144                      }
145                }
146                else {
147                      Esys_setError(VALUE_ERROR,"Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
148                }
149          }
150                
151             return out;
152    }

Legend:
Removed from v.1639  
changed lines
  Added in v.3642

  ViewVC Help
Powered by ViewVC 1.1.26