/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (20 months ago) by jfenwick
File size: 5184 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
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 "SparseMatrix.h"
30 #include "BlockOps.h"
31
32 namespace paso {
33
34 /*****************************************************************************
35
36 Returns the submatrix of A where rows are gathered by index row_list
37 and columns are selected by non-negative values of new_col_index.
38 If new_col_index[i]>-1 new_col_index[i] gives the column of i in
39 the returned submatrix.
40 */
41
42
43 SparseMatrix_ptr SparseMatrix::getSubmatrix(dim_t n_row_sub, dim_t n_col_sub,
44 const index_t* row_list,
45 const index_t* new_col_index) const
46 {
47 SparseMatrix_ptr out;
48 if (type & MATRIX_FORMAT_CSC) {
49 throw PasoException("SparseMatrix::getSubmatrix: gathering submatrices supports CSR matrix format only.");
50 }
51
52 const index_t index_offset = (type & MATRIX_FORMAT_OFFSET1 ? 1:0);
53 Pattern_ptr sub_pattern(pattern->getSubpattern(n_row_sub, n_col_sub,
54 row_list, new_col_index));
55 // create the return object
56 out.reset(new SparseMatrix(type, sub_pattern, row_block_size,
57 col_block_size, true));
58 #pragma omp parallel for
59 for (int i=0; i<n_row_sub; ++i) {
60 const index_t subpattern_row = row_list[i];
61 for (int k=pattern->ptr[subpattern_row]-index_offset;
62 k < pattern->ptr[subpattern_row+1]-index_offset; ++k) {
63 index_t tmp=new_col_index[pattern->index[k]-index_offset];
64 if (tmp > -1) {
65 #pragma ivdep
66 for (index_t m=out->pattern->ptr[i]-index_offset;
67 m < out->pattern->ptr[i+1]-index_offset; ++m) {
68 if (out->pattern->index[m]==tmp+index_offset) {
69 BlockOps_Cpy_N(block_size, &out->val[m*block_size], &val[k*block_size]);
70 break;
71 }
72 }
73 }
74 }
75 }
76 return out;
77 }
78
79 SparseMatrix_ptr SparseMatrix::getBlock(int blockid) const
80 {
81 const dim_t blocksize = row_block_size;
82 const dim_t n = numRows;
83 SparseMatrix_ptr out(new SparseMatrix(type, pattern, 1, 1, 0));
84
85 if (blocksize==1) {
86 if (blockid==1) {
87 #pragma omp parallel for
88 for (dim_t i=0; i<n; ++i) {
89 for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
90 out->val[iptr] = val[iptr];
91 }
92 }
93 } else {
94 throw PasoException("SparseMatrix::getBlock: Invalid block ID requested.");
95 }
96 } else if (blocksize==2) {
97 if (blockid==1) {
98 #pragma omp parallel for
99 for (dim_t i=0; i<n; i++) {
100 for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
101 out->val[iptr] = val[4*iptr];
102 }
103 }
104 } else if (blockid==2) {
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+3];
109 }
110 }
111 } else {
112 throw PasoException("SparseMatrix::getBlock: Invalid block ID requested.");
113 }
114 } else if (blocksize==3) {
115 if (blockid==1) {
116 #pragma omp parallel for
117 for (dim_t i=0; i<n; i++) {
118 for (index_t iptr=pattern->ptr[i]; iptr<pattern->ptr[i+1]; ++iptr) {
119 out->val[iptr] = val[9*iptr];
120 }
121 }
122 } else if (blockid==2) {
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+4];
127 }
128 }
129 } else if (blockid==3) {
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+8];
134 }
135 }
136 } else {
137 throw PasoException("SparseMatrix::getBlock: Invalid block ID requested.");
138 }
139 }
140 return out;
141 }
142
143 } // namespace paso
144

Properties

Name Value
svn:mergeinfo /branches/4.0fordebian/paso/src/SparseMatrix_getSubmatrix.cpp:5567-5588 /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 /branches/trilinos_from_5897/paso/src/SparseMatrix_getSubmatrix.cpp:5898-6118 /release/3.0/paso/src/SparseMatrix_getSubmatrix.cpp:2591-2601 /release/4.0/paso/src/SparseMatrix_getSubmatrix.cpp:5380-5406 /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