/[escript]/trunk/paso/src/Pattern_multiply.c
ViewVC logotype

Contents of /trunk/paso/src/Pattern_multiply.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3303 - (show annotations)
Mon Oct 25 04:33:31 2010 UTC (8 years, 10 months ago) by gross
File MIME type: text/plain
File size: 2960 byte(s)
more clean up work on the AMG
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15
16 /**************************************************************/
17
18 /* Paso: Pattern */
19
20 /**************************************************************/
21
22 /* Author: Lutz Gross, l.gross@uq.edu.au */
23
24 /**************************************************************/
25
26 #include "Paso.h"
27 #include "Pattern.h"
28
29 /**************************************************************/
30
31 /* computes the pattern coming from matrix-matrix multiplication
32 *
33 **/
34
35 Paso_Pattern* Paso_Pattern_multiply(int type, Paso_Pattern* A, Paso_Pattern* B) {
36 Paso_Pattern*out=NULL;
37 index_t iptrA,iptrB;
38 dim_t i,j,k;
39 Paso_IndexListArray* index_list = Paso_IndexListArray_alloc(A->numOutput);
40
41 #pragma omp parallel for private(i,iptrA,j,iptrB,k) schedule(static)
42 for(i = 0; i < A->numOutput; i++) {
43 for(iptrA = A->ptr[i]; iptrA < A->ptr[i+1]; ++iptrA) {
44 j = A->index[iptrA];
45 for(iptrB = B->ptr[j]; iptrB < B->ptr[j+1]; ++iptrB) {
46 k = B->index[iptrB];
47 Paso_IndexListArray_insertIndex(index_list,i,k);
48 }
49 }
50 }
51
52 out=Paso_Pattern_fromIndexListArray(0, index_list,0,B->numInput,0);
53
54 /* clean up */
55 Paso_IndexListArray_free(index_list);
56
57 return out;
58 }
59
60
61
62 /*
63 * Computes the pattern of C = A binary operation B for CSR matrices A,B
64 *
65 * Note: we do not check whether A_ij(op)B_ij=0
66 *
67 */
68 Paso_Pattern* Paso_Pattern_binop(int type, Paso_Pattern* A, Paso_Pattern* B) {
69 Paso_Pattern *out=NULL;
70 index_t iptrA,iptrB;
71 dim_t i,j,k;
72
73 Paso_IndexListArray* index_list = Paso_IndexListArray_alloc(A->numOutput);
74
75 #pragma omp parallel for private(i,iptrA,j,iptrB,k) schedule(static)
76 for(i = 0; i < B->numOutput; i++){
77 iptrA = A->ptr[i],
78 iptrB = B->ptr[i];
79
80 while (iptrA < A->ptr[i+1] && iptrB < B->ptr[i+1]) {
81 j = A->index[iptrA];
82 k = B->index[iptrB];
83 if (j<k) {
84 Paso_IndexListArray_insertIndex(index_list,i,j);
85 iptrA++;
86 } else if (j>k) {
87 Paso_IndexListArray_insertIndex(index_list,i,k);
88 iptrB++;
89 } else if (j==k) {
90 Paso_IndexListArray_insertIndex(index_list,i,j);
91 iptrB++;
92 iptrA++;
93 }
94 }
95 while(iptrA < A->ptr[i+1]) {
96 j = A->index[iptrA];
97 Paso_IndexListArray_insertIndex(index_list,i,j);
98 iptrA++;
99 }
100 while(iptrB < B->ptr[i+1]) {
101 k = B->index[iptrB];
102 Paso_IndexListArray_insertIndex(index_list,i,k);
103 iptrB++;
104 }
105 }
106
107 out=Paso_Pattern_fromIndexListArray(0, index_list,0,A->numInput,0);
108
109
110 /* clean up */
111 Paso_IndexListArray_free(index_list);
112
113 return out;
114 }

  ViewVC Help
Powered by ViewVC 1.1.26