/[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 2309 - (hide annotations)
Mon Mar 16 02:42:13 2009 UTC (10 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 4443 byte(s)
Fixed a typo affecting OpenMP usage.

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 phornby 1914 #include "PasoUtil.h"
32 phornby 1913 #include "Pattern_coupling.h"
33 jfenwick 1851
34    
35     /***************************************************************/
36    
37     #define IS_AVAILABLE -1
38 artak 1975 #define IS_IN_SET -3
39     #define IS_REMOVED -4
40 jfenwick 1851
41 artak 1931 void Paso_Pattern_coup(Paso_SparseMatrix* A, index_t* mis_marker, double threshold) {
42 jfenwick 1851
43 artak 1881 dim_t i,j;
44 artak 1931 /*double threshold=0.05;*/
45 artak 2122 double sum;
46 artak 2107 index_t iptr,*index,*where_p,*diagptr;
47     bool_t passed=FALSE;
48 artak 1954 dim_t n=A->numRows;
49 artak 2107 diagptr=MEMALLOC(n,index_t);
50 artak 2122
51 jfenwick 1851 if (A->pattern->type & PATTERN_FORMAT_SYM) {
52 artak 2159 Paso_setError(TYPE_ERROR,"Paso_Pattern_coup: symmetric matrix pattern is not supported yet");
53 jfenwick 1851 return;
54     }
55    
56 artak 2107 #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 jfenwick 1851
61 artak 2107 #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 artak 2159 Paso_setError(VALUE_ERROR, "Paso_Pattern_coup: main diagonal element missing.");
72 artak 2107 } 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 artak 1902 }
102 artak 2107 else {
103     passed=FALSE;
104     break;
105 artak 1902 }
106 artak 2307 }
107 artak 1902 }
108 artak 2107 if (passed) {
109     mis_marker[i]=IS_IN_SET;
110     passed=FALSE;
111     }
112 artak 1902 }
113 artak 2107 }
114    
115 artak 2122 /* 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 caltinay 2309 #pragma omp parallel for private(i,iptr,j,sum) schedule(static)
118 artak 2122 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 jfenwick 1851 /* swap to TRUE/FALSE in mis_marker */
133     #pragma omp parallel for private(i) schedule(static)
134 artak 2107 for (i=0;i<n;i++) mis_marker[i]=(mis_marker[i]!=IS_IN_SET);
135    
136     MEMFREE(diagptr);
137 jfenwick 1851 }
138 artak 1890
139    
140 jfenwick 1851 #undef IS_AVAILABLE
141 artak 1975 #undef IS_IN_SET
142     #undef IS_REMOVED

  ViewVC Help
Powered by ViewVC 1.1.26