/[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 4657 - (hide annotations)
Thu Feb 6 06:12:20 2014 UTC (5 years, 8 months ago) by jfenwick
File size: 6376 byte(s)
I changed some files.
Updated copyright notices, added GeoComp.



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 jfenwick 3981 /************************************************************************************/
19 ksteube 1315
20     /* Paso: SparseMatrix */
21    
22 jfenwick 3981 /************************************************************************************/
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 jfenwick 3981 /************************************************************************************/
28 ksteube 1315
29     #include "Paso.h"
30     #include "SparseMatrix.h"
31     #include "PasoUtil.h"
32    
33 jfenwick 3981 /************************************************************************************
34 ksteube 1315
35 caltinay 3642 Returns the submatrix of A where rows are gathered by index row_list
36 ksteube 1315 and columns are selected by non-negative values of new_col_index.
37 caltinay 3642 If new_col_index[i]>-1 new_col_index[i] gives the column of i in
38     the returned submatrix.
39 ksteube 1315 */
40    
41    
42     Paso_SparseMatrix* Paso_SparseMatrix_getSubmatrix(Paso_SparseMatrix* A,int n_row_sub,int n_col_sub, index_t* row_list,index_t* new_col_index){
43     Paso_Pattern* sub_pattern=NULL;
44     Paso_SparseMatrix* out=NULL;
45     index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
46     int i,k,tmp,m,subpattern_row;
47     int type=A->type;
48 jfenwick 3259 Esys_resetError();
49 ksteube 1315 if (A->type & MATRIX_FORMAT_CSC) {
50 caltinay 3642 Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_getSubmatrix: gathering submatrices supports CSR matrix format only.");
51 ksteube 1315 } else {
52     sub_pattern=Paso_Pattern_getSubpattern(A->pattern,n_row_sub,n_col_sub,row_list,new_col_index);
53 jfenwick 3259 if (Esys_noError()) {
54 ksteube 1315 /* create the return object */
55 gross 2551 out=Paso_SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
56 jfenwick 3259 if (Esys_noError()) {
57 ksteube 1315 #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)
58     for (i=0;i<n_row_sub;++i) {
59     subpattern_row=row_list[i];
60     for (k=A->pattern->ptr[subpattern_row]-index_offset;k<A->pattern->ptr[subpattern_row+1]-index_offset;++k) {
61     tmp=new_col_index[A->pattern->index[k]-index_offset];
62     if (tmp>-1) {
63     #pragma ivdep
64     for (m=out->pattern->ptr[i]-index_offset;m<out->pattern->ptr[i+1]-index_offset;++m) {
65     if (out->pattern->index[m]==tmp+index_offset) {
66 gross 1639 Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
67 ksteube 1315 break;
68     }
69     }
70     }
71     }
72     }
73     }
74     }
75     Paso_Pattern_free(sub_pattern);
76     }
77     return out;
78     }
79 artak 2659
80     Paso_SparseMatrix* Paso_SparseMatrix_getBlock(Paso_SparseMatrix* A, int blockid){
81    
82     dim_t blocksize=A->row_block_size,i;
83     dim_t n=A->numRows;
84     index_t iptr;
85    
86     Paso_SparseMatrix* out=NULL;
87    
88     out=Paso_SparseMatrix_alloc(A->type,A->pattern, 1, 1, 0);
89    
90     if (blocksize==1) {
91     if (blockid==1) {
92 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
93 artak 2659 for(i=0;i<n;++i) {
94     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
95     out->val[iptr]=A->val[iptr];
96     }
97     }
98     }
99     else {
100 caltinay 3642 Esys_setError(VALUE_ERROR, "Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
101 artak 2659 }
102     }
103     else if (blocksize==2) {
104     if (blockid==1) {
105 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
106 artak 2659 for(i=0;i<n;i++) {
107     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
108     out->val[iptr]=A->val[4*iptr];
109     }
110     }
111     }
112     else if (blockid==2) {
113 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
114 artak 2659 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     }
120     else {
121 caltinay 3642 Esys_setError(VALUE_ERROR,"Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
122 artak 2659 }
123     }
124     else if (blocksize==3) {
125     if (blockid==1) {
126 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
127 artak 2659 for(i=0;i<n;i++) {
128     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
129     out->val[iptr]=A->val[9*iptr];
130     }
131     }
132     }
133     else if (blockid==2) {
134 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
135 artak 2659 for(i=0;i<n;i++) {
136     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
137     out->val[iptr]=A->val[9*iptr+4];
138     }
139     }
140     }
141     else if (blockid==3) {
142 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
143 artak 2659 for(i=0;i<n;i++) {
144     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
145     out->val[iptr]=A->val[9*iptr+8];
146     }
147     }
148     }
149     else {
150 caltinay 3642 Esys_setError(VALUE_ERROR,"Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
151 artak 2659 }
152     }
153    
154 caltinay 3642 return out;
155 artak 2659 }

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