/[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 4829 - (hide annotations)
Thu Apr 3 04:02:53 2014 UTC (5 years, 7 months ago) by caltinay
File size: 5502 byte(s)
checkpointing some SparseMatrix 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 4829 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 caltinay 4797 {
48 caltinay 4829 SparseMatrix_ptr out;
49 caltinay 4797 Esys_resetError();
50 caltinay 4829 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 caltinay 4797 if (Esys_noError()) {
63 caltinay 4829 #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 caltinay 4797 }
77 ksteube 1315 }
78 caltinay 4797 }
79     }
80 ksteube 1315 }
81 caltinay 4797 }
82     }
83     return out;
84 ksteube 1315 }
85 artak 2659
86 caltinay 4829 SparseMatrix_ptr SparseMatrix::getBlock(int blockid) const
87 caltinay 4797 {
88 caltinay 4829 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 caltinay 4797
92     if (blocksize==1) {
93     if (blockid==1) {
94 caltinay 4829 #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 caltinay 4797 }
99 artak 2659 }
100 caltinay 4797 } else {
101 caltinay 4829 Esys_setError(VALUE_ERROR, "SparseMatrix::getBlock: Invalid block ID requested.");
102 caltinay 4797 }
103     } else if (blocksize==2) {
104     if (blockid==1) {
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];
109 caltinay 4797 }
110 artak 2659 }
111 caltinay 4797 } else if (blockid==2) {
112 caltinay 4829 #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 caltinay 4797 }
117 artak 2659 }
118 caltinay 4797 } else {
119 caltinay 4829 Esys_setError(VALUE_ERROR, "SparseMatrix::getBlock: Invalid block ID requested.");
120 caltinay 4797 }
121     } else if (blocksize==3) {
122     if (blockid==1) {
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];
127 caltinay 4797 }
128 artak 2659 }
129 caltinay 4797 } else if (blockid==2) {
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+4];
134 caltinay 4797 }
135 artak 2659 }
136 caltinay 4797 } else if (blockid==3) {
137 caltinay 4829 #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 caltinay 4797 }
142 artak 2659 }
143 caltinay 4797 } else {
144 caltinay 4829 Esys_setError(VALUE_ERROR, "SparseMatrix::getBlock: Invalid block ID requested.");
145 caltinay 4797 }
146     }
147     return out;
148 artak 2659 }
149 caltinay 4797
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