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

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 4797 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 caltinay 4803 Pattern* sub_pattern=NULL;
49 caltinay 4797 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 caltinay 4803 sub_pattern=Pattern_getSubpattern(A->pattern, n_row_sub, n_col_sub,
58     row_list, new_col_index);
59 caltinay 4797 if (Esys_noError()) {
60 ksteube 1315 /* create the return object */
61 caltinay 4797 out=SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
62 jfenwick 3259 if (Esys_noError()) {
63 caltinay 4797 #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 ksteube 1315 tmp=new_col_index[A->pattern->index[k]-index_offset];
68     if (tmp>-1) {
69 caltinay 4797 #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 gross 1639 Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
73 ksteube 1315 break;
74 caltinay 4797 }
75     }
76 ksteube 1315 }
77 caltinay 4797 }
78     }
79 ksteube 1315 }
80 caltinay 4797 }
81 caltinay 4803 Pattern_free(sub_pattern);
82 caltinay 4797 }
83     return out;
84 ksteube 1315 }
85 artak 2659
86 caltinay 4797 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 artak 2659 }
101 caltinay 4797 } 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 artak 2659 }
112 caltinay 4797 } 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 artak 2659 }
119 caltinay 4797 } 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 artak 2659 }
130 caltinay 4797 } 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 artak 2659 }
137 caltinay 4797 } 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 artak 2659 }
144 caltinay 4797 } else {
145     Esys_setError(VALUE_ERROR,"SparseMatrix_getBlock: Requested and actual block sizes do not match.");
146     }
147     }
148    
149     return out;
150 artak 2659 }
151 caltinay 4797
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