/[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 4803 - (show annotations)
Wed Mar 26 06:52:28 2014 UTC (5 years, 6 months ago) by caltinay
File size: 5927 byte(s)
Removed obsolete wrappers for malloc and friends.
Paso_Pattern -> paso::Pattern

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 Pattern* sub_pattern=NULL;
49 SparseMatrix* out=NULL;
50 index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
51 int i,k,tmp,m,subpattern_row;
52 int type=A->type;
53 Esys_resetError();
54 if (A->type & MATRIX_FORMAT_CSC) {
55 Esys_setError(TYPE_ERROR, "SparseMatrix_getSubmatrix: gathering submatrices supports CSR matrix format only.");
56 } else {
57 sub_pattern=Pattern_getSubpattern(A->pattern, n_row_sub, n_col_sub,
58 row_list, new_col_index);
59 if (Esys_noError()) {
60 /* create the return object */
61 out=SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
62 if (Esys_noError()) {
63 #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)
64 for (i=0;i<n_row_sub;++i) {
65 subpattern_row=row_list[i];
66 for (k=A->pattern->ptr[subpattern_row]-index_offset;k<A->pattern->ptr[subpattern_row+1]-index_offset;++k) {
67 tmp=new_col_index[A->pattern->index[k]-index_offset];
68 if (tmp>-1) {
69 #pragma ivdep
70 for (m=out->pattern->ptr[i]-index_offset;m<out->pattern->ptr[i+1]-index_offset;++m) {
71 if (out->pattern->index[m]==tmp+index_offset) {
72 Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
73 break;
74 }
75 }
76 }
77 }
78 }
79 }
80 }
81 Pattern_free(sub_pattern);
82 }
83 return out;
84 }
85
86 SparseMatrix* SparseMatrix_getBlock(const SparseMatrix* A, int blockid)
87 {
88 dim_t blocksize=A->row_block_size,i;
89 dim_t n=A->numRows;
90 index_t iptr;
91 SparseMatrix* out = SparseMatrix_alloc(A->type, A->pattern, 1, 1, 0);
92
93 if (blocksize==1) {
94 if (blockid==1) {
95 #pragma omp parallel for private(i,iptr) schedule(static)
96 for(i=0;i<n;++i) {
97 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
98 out->val[iptr]=A->val[iptr];
99 }
100 }
101 } else {
102 Esys_setError(VALUE_ERROR, "SparseMatrix_getBlock: Requested and actual block sizes do not match.");
103 }
104 } else if (blocksize==2) {
105 if (blockid==1) {
106 #pragma omp parallel for private(i,iptr) schedule(static)
107 for(i=0;i<n;i++) {
108 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
109 out->val[iptr]=A->val[4*iptr];
110 }
111 }
112 } else if (blockid==2) {
113 #pragma omp parallel for private(i,iptr) schedule(static)
114 for(i=0;i<n;i++) {
115 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
116 out->val[iptr]=A->val[4*iptr+3];
117 }
118 }
119 } else {
120 Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
121 }
122 } else if (blocksize==3) {
123 if (blockid==1) {
124 #pragma omp parallel for private(i,iptr) schedule(static)
125 for(i=0;i<n;i++) {
126 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
127 out->val[iptr]=A->val[9*iptr];
128 }
129 }
130 } else if (blockid==2) {
131 #pragma omp parallel for private(i,iptr) schedule(static)
132 for(i=0;i<n;i++) {
133 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
134 out->val[iptr]=A->val[9*iptr+4];
135 }
136 }
137 } else if (blockid==3) {
138 #pragma omp parallel for private(i,iptr) schedule(static)
139 for(i=0;i<n;i++) {
140 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
141 out->val[iptr]=A->val[9*iptr+8];
142 }
143 }
144 } else {
145 Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
146 }
147 }
148
149 return out;
150 }
151
152 } // namespace paso
153

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