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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4819 - (hide annotations)
Tue Apr 1 03:50:23 2014 UTC (5 years, 6 months ago) by caltinay
File size: 5866 byte(s)
Pattern shared ptrs

1 ksteube 1315
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 4657 * Copyright (c) 2003-2014 by University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
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 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
13     * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 *
15     *****************************************************************************/
16 ksteube 1315
17 ksteube 1811
18 caltinay 4797 /****************************************************************************/
19 ksteube 1315
20     /* Paso: SparseMatrix */
21    
22 caltinay 4797 /****************************************************************************/
23 ksteube 1315
24     /* Copyrights by ACcESS Australia 2003, 2004,2005 */
25 jfenwick 2608 /* Author: Lutz Gross, l.gross@uq.edu.au */
26 ksteube 1315
27 caltinay 4797 /****************************************************************************/
28 ksteube 1315
29     #include "Paso.h"
30     #include "SparseMatrix.h"
31     #include "PasoUtil.h"
32    
33 caltinay 4797 namespace paso {
34 ksteube 1315
35 caltinay 4797 /*****************************************************************************
36    
37 caltinay 3642 Returns the submatrix of A where rows are gathered by index row_list
38 ksteube 1315 and columns are selected by non-negative values of new_col_index.
39 caltinay 3642 If new_col_index[i]>-1 new_col_index[i] gives the column of i in
40     the returned submatrix.
41 ksteube 1315 */
42    
43    
44 caltinay 4797 SparseMatrix* SparseMatrix_getSubmatrix(const SparseMatrix* A,int n_row_sub,
45     int n_col_sub, const index_t* row_list,
46     const index_t* new_col_index)
47     {
48     SparseMatrix* out=NULL;
49     index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
50     int i,k,tmp,m,subpattern_row;
51     int type=A->type;
52     Esys_resetError();
53     if (A->type & MATRIX_FORMAT_CSC) {
54     Esys_setError(TYPE_ERROR, "SparseMatrix_getSubmatrix: gathering submatrices supports CSR matrix format only.");
55     } else {
56 caltinay 4819 Pattern_ptr sub_pattern(A->pattern->getSubpattern(n_row_sub, n_col_sub,
57     row_list, new_col_index));
58 caltinay 4797 if (Esys_noError()) {
59 ksteube 1315 /* create the return object */
60 caltinay 4797 out=SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
61 jfenwick 3259 if (Esys_noError()) {
62 caltinay 4797 #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)
63     for (i=0;i<n_row_sub;++i) {
64     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) {
66 ksteube 1315 tmp=new_col_index[A->pattern->index[k]-index_offset];
67     if (tmp>-1) {
68 caltinay 4797 #pragma ivdep
69     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) {
71 gross 1639 Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
72 ksteube 1315 break;
73 caltinay 4797 }
74     }
75 ksteube 1315 }
76 caltinay 4797 }
77     }
78 ksteube 1315 }
79 caltinay 4797 }
80     }
81     return out;
82 ksteube 1315 }
83 artak 2659
84 caltinay 4797 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 artak 2659 }
99 caltinay 4797 } 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 artak 2659 }
110 caltinay 4797 } 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 artak 2659 }
117 caltinay 4797 } 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 artak 2659 }
128 caltinay 4797 } 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 artak 2659 }
135 caltinay 4797 } 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 artak 2659 }
142 caltinay 4797 } else {
143     Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
144     }
145     }
146    
147     return out;
148 artak 2659 }
149 caltinay 4797
150     } // namespace paso
151    

Properties

Name Value
svn:mergeinfo /branches/amg_from_3530/paso/src/SparseMatrix_getSubmatrix.cpp:3531-3826 /branches/lapack2681/paso/src/SparseMatrix_getSubmatrix.cpp:2682-2741 /branches/pasowrap/paso/src/SparseMatrix_getSubmatrix.cpp:3661-3674 /branches/py3_attempt2/paso/src/SparseMatrix_getSubmatrix.cpp:3871-3891 /branches/restext/paso/src/SparseMatrix_getSubmatrix.cpp:2610-2624 /branches/ripleygmg_from_3668/paso/src/SparseMatrix_getSubmatrix.cpp:3669-3791 /branches/stage3.0/paso/src/SparseMatrix_getSubmatrix.cpp:2569-2590 /branches/symbolic_from_3470/paso/src/SparseMatrix_getSubmatrix.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/paso/src/SparseMatrix_getSubmatrix.cpp:3517-3974 /release/3.0/paso/src/SparseMatrix_getSubmatrix.cpp:2591-2601 /trunk/paso/src/SparseMatrix_getSubmatrix.cpp:4257-4344 /trunk/ripley/test/python/paso/src/SparseMatrix_getSubmatrix.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26