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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2307 - (show annotations)
Mon Mar 16 00:38:09 2009 UTC (10 years, 3 months ago) by artak
File MIME type: text/plain
File size: 4442 byte(s)
some clean up. RS and Aggregiation are removed.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 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 /* Paso: Pattern: Paso_Pattern_coupling
18
19 searches for a maximal independent set MIS in the matrix pattern
20 vertices in the maximal independent set are marked in mis_marker
21 nodes to be considered are marked by -1 on the input in mis_marker
22
23 */
24 /**********************************************************************/
25
26 /* Copyrights by ACcESS Australia 2003,2004,2005 */
27 /* Author: artak@uq.edu.au */
28
29 /**************************************************************/
30
31 #include "PasoUtil.h"
32 #include "Pattern_coupling.h"
33
34
35 /***************************************************************/
36
37 #define IS_AVAILABLE -1
38 #define IS_IN_SET -3
39 #define IS_REMOVED -4
40
41 void Paso_Pattern_coup(Paso_SparseMatrix* A, index_t* mis_marker, double threshold) {
42
43 dim_t i,j;
44 /*double threshold=0.05;*/
45 double sum;
46 index_t iptr,*index,*where_p,*diagptr;
47 bool_t passed=FALSE;
48 dim_t n=A->numRows;
49 diagptr=MEMALLOC(n,index_t);
50
51 if (A->pattern->type & PATTERN_FORMAT_SYM) {
52 Paso_setError(TYPE_ERROR,"Paso_Pattern_coup: symmetric matrix pattern is not supported yet");
53 return;
54 }
55
56 #pragma omp parallel for private(i) schedule(static)
57 for (i=0;i<n;++i)
58 if(mis_marker[i]==IS_AVAILABLE)
59 mis_marker[i]=IS_IN_SET;
60
61 #pragma omp parallel for private(i,index,where_p) schedule(static)
62 for (i=0;i<n;++i) {
63 diagptr[i]=A->pattern->ptr[i];
64 index=&(A->pattern->index[diagptr[i]]);
65 where_p=(index_t*)bsearch(&i,
66 index,
67 A->pattern->ptr[i + 1]-A->pattern->ptr[i],
68 sizeof(index_t),
69 Paso_comparIndex);
70 if (where_p==NULL) {
71 Paso_setError(VALUE_ERROR, "Paso_Pattern_coup: main diagonal element missing.");
72 } else {
73 diagptr[i]+=(index_t)(where_p-index);
74 }
75 }
76
77
78
79 /*This loop cannot be parallelized, as order matters here.*/
80 for (i=0;i<n;++i) {
81 if (mis_marker[i]==IS_IN_SET) {
82 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
83 j=A->pattern->index[iptr];
84 if (j!=i && ABS(A->val[iptr])>=threshold*ABS(A->val[diagptr[i]])) {
85 mis_marker[j]=IS_REMOVED;
86 }
87 }
88 }
89 }
90
91
92
93 /*This loop cannot be parallelized, as order matters here.*/
94 for (i=0;i<n;i++) {
95 if (mis_marker[i]==IS_REMOVED) {
96 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
97 j=A->pattern->index[iptr];
98 if (mis_marker[j]==IS_IN_SET) {
99 if ((A->val[iptr]/A->val[diagptr[i]])>=-threshold) {
100 passed=TRUE;
101 }
102 else {
103 passed=FALSE;
104 break;
105 }
106 }
107 }
108 if (passed) {
109 mis_marker[i]=IS_IN_SET;
110 passed=FALSE;
111 }
112 }
113 }
114
115 /* This check is to make sure we dont get some nusty rows which were not removed durring coarsing process.*/
116 /* TODO: we have to mechanism that this does not happend at all, and get rid of this 'If'. */
117 #pragma omp parallel for private(i,ipr,j,sum) schedule(static)
118 for (i=0;i<n;i++) {
119 if (mis_marker[i]==IS_REMOVED) {
120 sum=0;
121 for (iptr=A->pattern->ptr[i];iptr<A->pattern->ptr[i+1]; ++iptr) {
122 j=A->pattern->index[iptr];
123 if (mis_marker[j]==IS_REMOVED)
124 sum+=A->val[iptr];
125 }
126 if(ABS(sum)<1.e-12)
127 mis_marker[i]=IS_IN_SET;
128 }
129 }
130
131
132 /* swap to TRUE/FALSE in mis_marker */
133 #pragma omp parallel for private(i) schedule(static)
134 for (i=0;i<n;i++) mis_marker[i]=(mis_marker[i]!=IS_IN_SET);
135
136 MEMFREE(diagptr);
137 }
138
139
140 #undef IS_AVAILABLE
141 #undef IS_IN_SET
142 #undef IS_REMOVED

  ViewVC Help
Powered by ViewVC 1.1.26