/[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 3981 - (hide annotations)
Fri Sep 21 02:47:54 2012 UTC (7 years, 2 months ago) by jfenwick
Original Path: trunk/paso/src/SparseMatrix_getSubmatrix.c
File MIME type: text/plain
File size: 6308 byte(s)
First pass of updating copyright notices
1 ksteube 1315
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 3911 * Copyright (c) 2003-2012 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     * Development since 2012 by School of Earth Sciences
13     *
14     *****************************************************************************/
15 ksteube 1315
16 ksteube 1811
17 jfenwick 3981 /************************************************************************************/
18 ksteube 1315
19     /* Paso: SparseMatrix */
20    
21 jfenwick 3981 /************************************************************************************/
22 ksteube 1315
23     /* Copyrights by ACcESS Australia 2003, 2004,2005 */
24 jfenwick 2608 /* Author: Lutz Gross, l.gross@uq.edu.au */
25 ksteube 1315
26 jfenwick 3981 /************************************************************************************/
27 ksteube 1315
28     #include "Paso.h"
29     #include "SparseMatrix.h"
30     #include "PasoUtil.h"
31    
32 jfenwick 3981 /************************************************************************************
33 ksteube 1315
34 caltinay 3642 Returns the submatrix of A where rows are gathered by index row_list
35 ksteube 1315 and columns are selected by non-negative values of new_col_index.
36 caltinay 3642 If new_col_index[i]>-1 new_col_index[i] gives the column of i in
37     the returned submatrix.
38 ksteube 1315 */
39    
40    
41     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){
42     Paso_Pattern* sub_pattern=NULL;
43     Paso_SparseMatrix* out=NULL;
44     index_t index_offset=(A->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
45     int i,k,tmp,m,subpattern_row;
46     int type=A->type;
47 jfenwick 3259 Esys_resetError();
48 ksteube 1315 if (A->type & MATRIX_FORMAT_CSC) {
49 caltinay 3642 Esys_setError(TYPE_ERROR, "Paso_SparseMatrix_getSubmatrix: gathering submatrices supports CSR matrix format only.");
50 ksteube 1315 } else {
51     sub_pattern=Paso_Pattern_getSubpattern(A->pattern,n_row_sub,n_col_sub,row_list,new_col_index);
52 jfenwick 3259 if (Esys_noError()) {
53 ksteube 1315 /* create the return object */
54 gross 2551 out=Paso_SparseMatrix_alloc(type,sub_pattern,A->row_block_size,A->col_block_size,TRUE);
55 jfenwick 3259 if (Esys_noError()) {
56 ksteube 1315 #pragma omp parallel for private(i,k,m,subpattern_row,tmp) schedule(static)
57     for (i=0;i<n_row_sub;++i) {
58     subpattern_row=row_list[i];
59     for (k=A->pattern->ptr[subpattern_row]-index_offset;k<A->pattern->ptr[subpattern_row+1]-index_offset;++k) {
60     tmp=new_col_index[A->pattern->index[k]-index_offset];
61     if (tmp>-1) {
62     #pragma ivdep
63     for (m=out->pattern->ptr[i]-index_offset;m<out->pattern->ptr[i+1]-index_offset;++m) {
64     if (out->pattern->index[m]==tmp+index_offset) {
65 gross 1639 Paso_copyShortDouble(A->block_size,&(A->val[k*A->block_size]),&(out->val[m*A->block_size]));
66 ksteube 1315 break;
67     }
68     }
69     }
70     }
71     }
72     }
73     }
74     Paso_Pattern_free(sub_pattern);
75     }
76     return out;
77     }
78 artak 2659
79     Paso_SparseMatrix* Paso_SparseMatrix_getBlock(Paso_SparseMatrix* A, int blockid){
80    
81     dim_t blocksize=A->row_block_size,i;
82     dim_t n=A->numRows;
83     index_t iptr;
84    
85     Paso_SparseMatrix* out=NULL;
86    
87     out=Paso_SparseMatrix_alloc(A->type,A->pattern, 1, 1, 0);
88    
89     if (blocksize==1) {
90     if (blockid==1) {
91 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
92 artak 2659 for(i=0;i<n;++i) {
93     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
94     out->val[iptr]=A->val[iptr];
95     }
96     }
97     }
98     else {
99 caltinay 3642 Esys_setError(VALUE_ERROR, "Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
100 artak 2659 }
101     }
102     else if (blocksize==2) {
103     if (blockid==1) {
104 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
105 artak 2659 for(i=0;i<n;i++) {
106     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
107     out->val[iptr]=A->val[4*iptr];
108     }
109     }
110     }
111     else if (blockid==2) {
112 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
113 artak 2659 for(i=0;i<n;i++) {
114     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
115     out->val[iptr]=A->val[4*iptr+3];
116     }
117     }
118     }
119     else {
120 caltinay 3642 Esys_setError(VALUE_ERROR,"Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
121 artak 2659 }
122     }
123     else if (blocksize==3) {
124     if (blockid==1) {
125 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
126 artak 2659 for(i=0;i<n;i++) {
127     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
128     out->val[iptr]=A->val[9*iptr];
129     }
130     }
131     }
132     else if (blockid==2) {
133 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
134 artak 2659 for(i=0;i<n;i++) {
135     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
136     out->val[iptr]=A->val[9*iptr+4];
137     }
138     }
139     }
140     else if (blockid==3) {
141 artak 2666 #pragma omp parallel for private(i,iptr) schedule(static)
142 artak 2659 for(i=0;i<n;i++) {
143     for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
144     out->val[iptr]=A->val[9*iptr+8];
145     }
146     }
147     }
148     else {
149 caltinay 3642 Esys_setError(VALUE_ERROR,"Paso_SparseMatrix_getBlock: Requested and actual block sizes do not match.");
150 artak 2659 }
151     }
152    
153 caltinay 3642 return out;
154 artak 2659 }

  ViewVC Help
Powered by ViewVC 1.1.26