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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1902 - (hide annotations)
Wed Oct 22 03:54:14 2008 UTC (10 years, 11 months ago) by artak
File MIME type: text/plain
File size: 6487 byte(s)
some bugs fixed in coresening methods
1 jfenwick 1851
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 artak 1890
46    
47 artak 1882 void Paso_Pattern_coup(Paso_SparseMatrix* A, index_t* mis_marker) {
48 jfenwick 1851
49     index_t index_offset=(A->pattern->type & PATTERN_FORMAT_OFFSET1 ? 1:0);
50 artak 1881 dim_t i,j;
51 jfenwick 1851 double threshold=0.05;
52 artak 1902 index_t iptr,*index,*where_p,diagptr;
53 jfenwick 1851 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(naib,i,iptr,flag) schedule(static)
64     for (i=0;i<n;++i) {
65     if (mis_marker[i]==IS_AVAILABLE) {
66 artak 1902 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 jfenwick 1851 for (iptr=A->pattern->ptr[i]-index_offset;iptr<A->pattern->ptr[i+1]-index_offset; ++iptr) {
80 artak 1902 j=A->pattern->index[iptr]-index_offset;
81     if (j!=i && A->val[iptr]>=threshold*A->val[diagptr]) {
82     flag=IS_AVAILABLE;
83 jfenwick 1851 break;
84     }
85     }
86     mis_marker[i]=flag;
87 artak 1902 }
88     }
89    
90     #pragma omp parallel for private(naib,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 jfenwick 1851 for (iptr=A->pattern->ptr[i]-index_offset;iptr<A->pattern->ptr[i+1]-index_offset; ++iptr) {
106 artak 1902 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 artak 1881 mis_marker[i]=IS_IN_MIS;
109 artak 1883 }
110     else {
111 artak 1881 mis_marker[i]=IS_CONNECTED_TO_MIS;
112 artak 1883 }
113 jfenwick 1851 }
114 artak 1902 }
115     }
116     }
117 jfenwick 1851 /* 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 artak 1890
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 naib,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 artak 1902 Paso_setError(TYPE_ERROR,"Paso_Pattern_RS: symmetric matrix pattern is not supported yet");
145 artak 1890 return;
146     }
147    
148     /* is there any vertex available ?*/
149 artak 1902 if (Paso_Util_isAny(n,mis_marker,IS_AVAILABLE)) {
150 artak 1890
151 artak 1902 #pragma omp parallel for private(i,iptr,min_offdiagonal,threshold) schedule(static)
152 artak 1890 for (i=0;i<n;++i) {
153 artak 1902 min_offdiagonal = A->val[A->pattern->ptr[i]-index_offset];
154 artak 1890 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 artak 1902 min_offdiagonal = MIN(min_offdiagonal,A->val[iptr-index_offset]);
157 artak 1890 }
158     }
159    
160     threshold = theta*min_offdiagonal;
161 artak 1902 mis_marker[i]=IS_CONNECTED_TO_MIS;
162 artak 1890 #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 artak 1902 if(-1.*(A->val[iptr-index_offset]) <= threshold){
165 artak 1890 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 jfenwick 1851 #undef IS_AVAILABLE
175     #undef IS_IN_MIS_NOW
176     #undef IS_IN_MIS
177     #undef IS_CONNECTED_TO_MIS

  ViewVC Help
Powered by ViewVC 1.1.26