/[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 4829 - (show annotations)
Thu Apr 3 04:02:53 2014 UTC (5 years, 5 months ago) by caltinay
File size: 5502 byte(s)
checkpointing some SparseMatrix cleanup.

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_ptr SparseMatrix::getSubmatrix(int n_row_sub, int n_col_sub,
45 const index_t* row_list,
46 const index_t* new_col_index) const
47 {
48 SparseMatrix_ptr out;
49 Esys_resetError();
50 if (type & MATRIX_FORMAT_CSC) {
51 Esys_setError(TYPE_ERROR, "SparseMatrix::getSubmatrix: gathering submatrices supports CSR matrix format only.");
52 return out;
53 }
54
55 const index_t index_offset = (type & MATRIX_FORMAT_OFFSET1 ? 1:0);
56 Pattern_ptr sub_pattern(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.reset(new SparseMatrix(type, sub_pattern, row_block_size,
61 col_block_size, true));
62 if (Esys_noError()) {
63 #pragma omp parallel for
64 for (int i=0; i<n_row_sub; ++i) {
65 const index_t subpattern_row = row_list[i];
66 for (int k=pattern->ptr[subpattern_row]-index_offset;
67 k < pattern->ptr[subpattern_row+1]-index_offset; ++k) {
68 index_t tmp=new_col_index[pattern->index[k]-index_offset];
69 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 #pragma omp parallel for
113 for (dim_t i=0; i<n; i++) {
114 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

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