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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1
2 /*****************************************************************************
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
17
18 /****************************************************************************/
19
20 /* Paso: SparseMatrix */
21
22 /****************************************************************************/
23
24 /* Copyrights by ACcESS Australia 2003, 2004,2005 */
25 /* Author: Lutz Gross, l.gross@uq.edu.au */
26
27 /****************************************************************************/
28
29 #include "Paso.h"
30 #include "SparseMatrix.h"
31 #include "PasoUtil.h"
32
33 namespace paso {
34
35 /*****************************************************************************
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 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 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 */
60 out=SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
61 if (Esys_noError()) {
62 #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 tmp=new_col_index[A->pattern->index[k]-index_offset];
67 if (tmp>-1) {
68 #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 Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
72 break;
73 }
74 }
75 }
76 }
77 }
78 }
79 }
80 }
81 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

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