/[escript]/trunk/esys2/finley/src/finleyC/SystemPattern_mis.c
ViewVC logotype

Contents of /trunk/esys2/finley/src/finleyC/SystemPattern_mis.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 115 - (show annotations)
Fri Mar 4 07:12:47 2005 UTC (15 years, 1 month ago) by jgs
File MIME type: text/plain
File size: 4159 byte(s)
*** empty log message ***

1 /* $Id$ */
2
3 /**********************************************************************/
4
5 /* Finley: SystemMatrixPattern: Finley_SystemMatrixPattern_mis
6
7 searches for a maximal independent set MIS in the matrix pattern
8 vertices in the maximal independent set are marked in mis_marker
9
10 */
11 /**********************************************************************/
12
13 /* Copyrights by ACcESS Australia 2003,2004,2005 */
14 /* Author: gross@access.edu.au */
15
16 /**************************************************************/
17
18 #include "Finley.h"
19 #include "System.h"
20 #include "Util.h"
21
22
23 /* used to generate pseudo random numbers: */
24
25 static double Finley_SystemMatrixPattern_mis_seed=.4142135623730951;
26
27
28 /***************************************************************/
29
30 #define IS_AVAILABLE -1
31 #define IS_IN_MIS_NOW -2
32 #define IS_IN_MIS -3
33 #define IS_CONNECTED_TO_MIS -4
34
35 void Finley_SystemMatrixPattern_mis(Finley_SystemMatrixPattern* pattern_p, maybelong* mis_marker) {
36
37 maybelong i,naib,iptr;
38 int flag;
39 maybelong n=pattern_p->n_ptr;
40 double *value=TMPMEMALLOC(n,double);
41 if (!Finley_checkPtr(value)) {
42 #pragma omp parallel for private(i) schedule(static)
43 for (i=0;i<n;++i) mis_marker[i]=IS_AVAILABLE;
44
45 /* is there any vertex available ?*/
46 while (Finley_Util_isAny(n,mis_marker,IS_AVAILABLE)) {
47 /* step 1: assign a random number in [0,1] to each vertex */
48 /* step 2: is the vertex is available, check if its value is the smaller than all values of its naigbours
49 if the answer is yes, the vertex is put into the independend set and all
50 its naighbours are removed from the graph by setting it mis_marker to FALSE */
51
52 /* step 2: is the vertex is available, check if its value is the smaller than all values of its naigbours */
53
54 /* assign random number in [0,1] to each vertex */
55 #pragma omp parallel for private(i) schedule(static)
56 for (i=0;i<n;++i) {
57 if (mis_marker[i]==IS_AVAILABLE) {
58 value[i]=fmod(Finley_SystemMatrixPattern_mis_seed*(i+1),1.);
59 } else {
60 value[i]=2.;
61 }
62 }
63 /* update the seed */
64 Finley_SystemMatrixPattern_mis_seed=fmod(sqrt(Finley_SystemMatrixPattern_mis_seed*(n+1)),1.);
65 /* detect independent vertices as those vertices that have a value less than all values of its naigbours */
66 #pragma omp parallel for private(naib,i,iptr,flag) schedule(static)
67 for (i=0;i<n;++i) {
68 if (mis_marker[i]==IS_AVAILABLE) {
69 flag=IS_IN_MIS_NOW;
70 for (iptr=pattern_p->ptr[i];iptr<pattern_p->ptr[i+1]; ++iptr) {
71 naib=pattern_p->index[iptr];
72 if (naib!=i && value[naib]<=value[i]) {
73 flag=IS_AVAILABLE;
74 break;
75 }
76 }
77 mis_marker[i]=flag;
78 }
79 }
80 /* detect independent vertices as those vertices that have a value less than all values of its naigbours */
81 #pragma omp parallel for private(naib,i,iptr) schedule(static)
82 for (i=0;i<n;i++) {
83 if (mis_marker[i]==IS_IN_MIS_NOW) {
84 for (iptr=pattern_p->ptr[i];iptr<pattern_p->ptr[i+1]; ++iptr) {
85 naib=pattern_p->index[iptr];
86 if (naib!=i) mis_marker[naib]=IS_CONNECTED_TO_MIS;
87 }
88 mis_marker[i]=IS_IN_MIS;
89 }
90 }
91 }
92 /* swap to TRUE/FALSE in mis_marker */
93 #pragma omp parallel for private(i) schedule(static)
94 for (i=0;i<n;i++) mis_marker[i]=(mis_marker[i]==IS_IN_MIS);
95 }
96 TMPMEMFREE(value);
97 }
98 #undef IS_AVAILABLE
99 #undef IS_IN_MIS_NOW
100 #undef IS_IN_MIS
101 #undef IS_CONNECTED_TO_MIS
102
103 /*
104 * $Log$
105 * Revision 1.2 2005/03/04 07:12:46 jgs
106 * *** empty log message ***
107 *
108 * Revision 1.1.2.1 2005/03/02 23:35:06 gross
109 * reimplementation of the ILU in Finley. block size>1 still needs some testing
110 *
111 *
112 */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26