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

Copyright dates update

1 ksteube 1315
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 6651 * Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8 jfenwick 6112 * Licensed under the Apache License, version 2.0
9     * http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1811 *
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 "SparseMatrix.h"
30 caltinay 4869 #include "BlockOps.h"
31 ksteube 1315
32 caltinay 4797 namespace paso {
33 ksteube 1315
34 caltinay 4797 /*****************************************************************************
35    
36 caltinay 4873 Returns the submatrix of A where rows are gathered by index row_list
37 ksteube 1315 and columns are selected by non-negative values of new_col_index.
38 caltinay 4873 If new_col_index[i]>-1 new_col_index[i] gives the column of i in
39 caltinay 3642 the returned submatrix.
40 ksteube 1315 */
41    
42    
43 caltinay 5182 SparseMatrix_ptr SparseMatrix::getSubmatrix(dim_t n_row_sub, dim_t n_col_sub,
44 caltinay 4829 const index_t* row_list,
45     const index_t* new_col_index) const
46 caltinay 4797 {
47 caltinay 4829 SparseMatrix_ptr out;
48     if (type & MATRIX_FORMAT_CSC) {
49 caltinay 5996 throw PasoException("SparseMatrix::getSubmatrix: gathering submatrices supports CSR matrix format only.");
50 caltinay 4829 }
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 caltinay 5996 // create the return object
56     out.reset(new SparseMatrix(type, sub_pattern, row_block_size,
57     col_block_size, true));
58 caltinay 4829 #pragma omp parallel for
59 caltinay 5996 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 caltinay 4797 }
72     }
73 ksteube 1315 }
74 caltinay 4797 }
75     }
76     return out;
77 ksteube 1315 }
78 artak 2659
79 caltinay 4829 SparseMatrix_ptr SparseMatrix::getBlock(int blockid) const
80 caltinay 4797 {
81 caltinay 4829 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 caltinay 4797
85     if (blocksize==1) {
86     if (blockid==1) {
87 caltinay 4829 #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 caltinay 4797 }
92 artak 2659 }
93 caltinay 4797 } else {
94 caltinay 5996 throw PasoException("SparseMatrix::getBlock: Invalid block ID requested.");
95 caltinay 4797 }
96     } else if (blocksize==2) {
97     if (blockid==1) {
98 caltinay 4829 #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 caltinay 4797 }
103 artak 2659 }
104 caltinay 4797 } else if (blockid==2) {
105 caltinay 4829 #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 caltinay 4797 }
110 artak 2659 }
111 caltinay 4797 } else {
112 caltinay 5996 throw PasoException("SparseMatrix::getBlock: Invalid block ID requested.");
113 caltinay 4797 }
114     } else if (blocksize==3) {
115     if (blockid==1) {
116 caltinay 4829 #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 caltinay 4797 }
121 artak 2659 }
122 caltinay 4797 } else if (blockid==2) {
123 caltinay 4829 #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 caltinay 4797 }
128 artak 2659 }
129 caltinay 4797 } else if (blockid==3) {
130 caltinay 4829 #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 caltinay 4797 }
135 artak 2659 }
136 caltinay 4797 } else {
137 caltinay 5996 throw PasoException("SparseMatrix::getBlock: Invalid block ID requested.");
138 caltinay 4797 }
139     }
140     return out;
141 artak 2659 }
142 caltinay 4797
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