/[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 4797 - (hide annotations)
Mon Mar 24 05:42:42 2014 UTC (5 years, 8 months ago) by caltinay
File size: 5994 byte(s)
put SparseMatrix into paso namespace, accompanied by minor code cleanup.

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     Paso_Pattern* sub_pattern=NULL;
49     SparseMatrix* out=NULL;
50     index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
51     int i,k,tmp,m,subpattern_row;
52     int type=A->type;
53     Esys_resetError();
54     if (A->type & MATRIX_FORMAT_CSC) {
55     Esys_setError(TYPE_ERROR, "SparseMatrix_getSubmatrix: gathering submatrices supports CSR matrix format only.");
56     } else {
57     sub_pattern=Paso_Pattern_getSubpattern(A->pattern, n_row_sub,
58     n_col_sub, row_list,
59     new_col_index);
60     if (Esys_noError()) {
61 ksteube 1315 /* create the return object */
62 caltinay 4797 out=SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
63 jfenwick 3259 if (Esys_noError()) {
64 caltinay 4797 #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)
65     for (i=0;i<n_row_sub;++i) {
66     subpattern_row=row_list[i];
67     for (k=A->pattern->ptr[subpattern_row]-index_offset;k<A->pattern->ptr[subpattern_row+1]-index_offset;++k) {
68 ksteube 1315 tmp=new_col_index[A->pattern->index[k]-index_offset];
69     if (tmp>-1) {
70 caltinay 4797 #pragma ivdep
71     for (m=out->pattern->ptr[i]-index_offset;m<out->pattern->ptr[i+1]-index_offset;++m) {
72     if (out->pattern->index[m]==tmp+index_offset) {
73 gross 1639 Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
74 ksteube 1315 break;
75 caltinay 4797 }
76     }
77 ksteube 1315 }
78 caltinay 4797 }
79     }
80 ksteube 1315 }
81 caltinay 4797 }
82     Paso_Pattern_free(sub_pattern);
83     }
84     return out;
85 ksteube 1315 }
86 artak 2659
87 caltinay 4797 SparseMatrix* SparseMatrix_getBlock(const SparseMatrix* A, int blockid)
88     {
89     dim_t blocksize=A->row_block_size,i;
90     dim_t n=A->numRows;
91     index_t iptr;
92     SparseMatrix* out = SparseMatrix_alloc(A->type, A->pattern, 1, 1, 0);
93    
94     if (blocksize==1) {
95     if (blockid==1) {
96     #pragma omp parallel for private(i,iptr) schedule(static)
97     for(i=0;i<n;++i) {
98     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
99     out->val[iptr]=A->val[iptr];
100     }
101 artak 2659 }
102 caltinay 4797 } else {
103     Esys_setError(VALUE_ERROR, "SparseMatrix_getBlock: Requested and actual block sizes do not match.");
104     }
105     } else if (blocksize==2) {
106     if (blockid==1) {
107     #pragma omp parallel for private(i,iptr) schedule(static)
108     for(i=0;i<n;i++) {
109     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
110     out->val[iptr]=A->val[4*iptr];
111     }
112 artak 2659 }
113 caltinay 4797 } else if (blockid==2) {
114     #pragma omp parallel for private(i,iptr) schedule(static)
115     for(i=0;i<n;i++) {
116     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
117     out->val[iptr]=A->val[4*iptr+3];
118     }
119 artak 2659 }
120 caltinay 4797 } else {
121     Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
122     }
123     } else if (blocksize==3) {
124     if (blockid==1) {
125     #pragma omp parallel for private(i,iptr) schedule(static)
126     for(i=0;i<n;i++) {
127     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
128     out->val[iptr]=A->val[9*iptr];
129     }
130 artak 2659 }
131 caltinay 4797 } else if (blockid==2) {
132     #pragma omp parallel for private(i,iptr) schedule(static)
133     for(i=0;i<n;i++) {
134     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
135     out->val[iptr]=A->val[9*iptr+4];
136     }
137 artak 2659 }
138 caltinay 4797 } 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 artak 2659 }
145 caltinay 4797 } else {
146     Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
147     }
148     }
149    
150     return out;
151 artak 2659 }
152 caltinay 4797
153     } // namespace paso
154    

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