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 "mpi_C.h" |
32 |
#include "Paso.h" |
33 |
#include "PasoUtil.h" |
34 |
#include "Pattern.h" |
35 |
#include "Solver.h" |
36 |
|
37 |
|
38 |
/***************************************************************/ |
39 |
|
40 |
#define IS_AVAILABLE -1 |
41 |
#define IS_IN_MIS_NOW -2 |
42 |
#define IS_IN_MIS -3 |
43 |
#define IS_CONNECTED_TO_MIS -4 |
44 |
|
45 |
|
46 |
|
47 |
void Paso_Pattern_coup(Paso_SparseMatrix* A, index_t* mis_marker) { |
48 |
|
49 |
index_t index_offset=(A->pattern->type & PATTERN_FORMAT_OFFSET1 ? 1:0); |
50 |
dim_t i,j; |
51 |
double threshold=0.05; |
52 |
index_t iptr,*index,*where_p,diagptr; |
53 |
bool_t flag; |
54 |
dim_t n=A->pattern->numOutput; |
55 |
if (A->pattern->type & PATTERN_FORMAT_SYM) { |
56 |
Paso_setError(TYPE_ERROR,"Paso_Pattern_mis: symmetric matrix pattern is not supported yet"); |
57 |
return; |
58 |
} |
59 |
|
60 |
/* is there any vertex available ?*/ |
61 |
while (Paso_Util_isAny(n,mis_marker,IS_AVAILABLE)) { |
62 |
|
63 |
#pragma omp parallel for private(i,iptr,flag) schedule(static) |
64 |
for (i=0;i<n;++i) { |
65 |
if (mis_marker[i]==IS_AVAILABLE) { |
66 |
flag=IS_IN_MIS; |
67 |
diagptr=A->pattern->ptr[i]; |
68 |
index=&(A->pattern->index[diagptr]); |
69 |
where_p=(index_t*)bsearch(&i, |
70 |
index, |
71 |
A->pattern->ptr[i + 1]-A->pattern->ptr[i], |
72 |
sizeof(index_t), |
73 |
Paso_comparIndex); |
74 |
if (where_p==NULL) { |
75 |
Paso_setError(VALUE_ERROR, "Paso_Solver_getAMG: main diagonal element missing."); |
76 |
} else { |
77 |
diagptr+=(index_t)(where_p-index); |
78 |
} |
79 |
for (iptr=A->pattern->ptr[i]-index_offset;iptr<A->pattern->ptr[i+1]-index_offset; ++iptr) { |
80 |
j=A->pattern->index[iptr]-index_offset; |
81 |
if (j!=i && A->val[iptr]>=threshold*A->val[diagptr]) { |
82 |
flag=IS_AVAILABLE; |
83 |
break; |
84 |
} |
85 |
} |
86 |
mis_marker[i]=flag; |
87 |
} |
88 |
} |
89 |
|
90 |
#pragma omp parallel for private(i,iptr) schedule(static) |
91 |
for (i=0;i<n;i++) { |
92 |
if (mis_marker[i]==IS_AVAILABLE) { |
93 |
diagptr=A->pattern->ptr[i]; |
94 |
index=&(A->pattern->index[diagptr]); |
95 |
where_p=(index_t*)bsearch(&i, |
96 |
index, |
97 |
A->pattern->ptr[i + 1]-A->pattern->ptr[i], |
98 |
sizeof(index_t), |
99 |
Paso_comparIndex); |
100 |
if (where_p==NULL) { |
101 |
Paso_setError(VALUE_ERROR, "Paso_Solver_getAMG: main diagonal element missing."); |
102 |
} else { |
103 |
diagptr+=(index_t)(where_p-index); |
104 |
} |
105 |
for (iptr=A->pattern->ptr[i]-index_offset;iptr<A->pattern->ptr[i+1]-index_offset; ++iptr) { |
106 |
j=A->pattern->index[iptr]-index_offset; |
107 |
if (j!=i && mis_marker[j]==IS_IN_MIS && (A->val[iptr]/A->val[diagptr])>=-threshold){ |
108 |
mis_marker[i]=IS_IN_MIS; |
109 |
} |
110 |
else { |
111 |
mis_marker[i]=IS_CONNECTED_TO_MIS; |
112 |
} |
113 |
} |
114 |
} |
115 |
} |
116 |
} |
117 |
/* swap to TRUE/FALSE in mis_marker */ |
118 |
#pragma omp parallel for private(i) schedule(static) |
119 |
for (i=0;i<n;i++) mis_marker[i]=(mis_marker[i]==IS_IN_MIS); |
120 |
} |
121 |
|
122 |
/* |
123 |
* |
124 |
* Return a strength of connection mask using the classical |
125 |
* strength of connection measure by Ruge and Stuben. |
126 |
* |
127 |
* Specifically, an off-diagonal entry A[i.j] is a strong |
128 |
* connection if: |
129 |
* |
130 |
* -A[i,j] >= theta * max( -A[i,k] ) where k != i |
131 |
* |
132 |
* Otherwise, the connection is weak. |
133 |
* |
134 |
*/ |
135 |
void Paso_Pattern_RS(Paso_SparseMatrix* A, index_t* mis_marker, double theta) |
136 |
{ |
137 |
index_t index_offset=(A->pattern->type & PATTERN_FORMAT_OFFSET1 ? 1:0); |
138 |
dim_t i,j; |
139 |
index_t iptr; |
140 |
double threshold,min_offdiagonal; |
141 |
bool_t flag; |
142 |
dim_t n=A->pattern->numOutput; |
143 |
if (A->pattern->type & PATTERN_FORMAT_SYM) { |
144 |
Paso_setError(TYPE_ERROR,"Paso_Pattern_RS: symmetric matrix pattern is not supported yet"); |
145 |
return; |
146 |
} |
147 |
|
148 |
/* is there any vertex available ?*/ |
149 |
if (Paso_Util_isAny(n,mis_marker,IS_AVAILABLE)) { |
150 |
|
151 |
#pragma omp parallel for private(i,iptr,min_offdiagonal,threshold) schedule(static) |
152 |
for (i=0;i<n;++i) { |
153 |
min_offdiagonal = A->val[A->pattern->ptr[i]-index_offset]; |
154 |
for (iptr=A->pattern->ptr[i]-index_offset;iptr<A->pattern->ptr[i+1]-index_offset; ++iptr) { |
155 |
if(A->pattern->index[iptr] != i){ |
156 |
min_offdiagonal = MIN(min_offdiagonal,A->val[iptr-index_offset]); |
157 |
} |
158 |
} |
159 |
|
160 |
threshold = theta*min_offdiagonal; |
161 |
mis_marker[i]=IS_CONNECTED_TO_MIS; |
162 |
#pragma omp parallel for private(iptr) schedule(static) |
163 |
for (iptr=A->pattern->ptr[i]-index_offset;iptr<A->pattern->ptr[i+1]-index_offset; ++iptr) { |
164 |
if(-1.*(A->val[iptr-index_offset]) <= threshold){ |
165 |
mis_marker[i]=IS_IN_MIS; |
166 |
} |
167 |
} |
168 |
} |
169 |
} |
170 |
/* swap to TRUE/FALSE in mis_marker */ |
171 |
#pragma omp parallel for private(i) schedule(static) |
172 |
for (i=0;i<n;i++) mis_marker[i]=(mis_marker[i]==IS_IN_MIS); |
173 |
} |
174 |
#undef IS_AVAILABLE |
175 |
#undef IS_IN_MIS_NOW |
176 |
#undef IS_IN_MIS |
177 |
#undef IS_CONNECTED_TO_MIS |