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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 415 - (show annotations)
Wed Jan 4 05:37:33 2006 UTC (13 years, 11 months ago) by gross
File MIME type: text/plain
File size: 4257 byte(s)
a better way of representing the matrix format type is introduced. this is needed for the Paradiso and UMFPACK interface
1 /* $Id$ */
2
3 /**********************************************************************/
4
5 /* Paso: SystemMatrixPattern: Paso_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 "Paso.h"
19 #include "Util.h"
20 #include "SystemMatrixPattern.h"
21
22
23 /* used to generate pseudo random numbers: */
24
25 static double Paso_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 Paso_SystemMatrixPattern_mis(Paso_SystemMatrixPattern* pattern_p, index_t* mis_marker) {
36
37 index_t index_offset=(pattern_p->type & PATTERN_FORMAT_OFFSET1 ? 1:0);
38 dim_t i;
39 index_t naib,iptr;
40 bool_t flag;
41 dim_t n=pattern_p->n_ptr;
42 if (pattern_p->type & PATTERN_FORMAT_SYM) {
43 Paso_setError(TYPE_ERROR,"Paso_SystemMatrixPattern_mis: symmetric matrix pattern is not supported yet");
44 return;
45 }
46 double *value=TMPMEMALLOC(n,double);
47 if (!Paso_checkPtr(value)) {
48 #pragma omp parallel for private(i) schedule(static)
49 for (i=0;i<n;++i) mis_marker[i]=IS_AVAILABLE;
50
51 /* is there any vertex available ?*/
52 while (Paso_Util_isAny(n,mis_marker,IS_AVAILABLE)) {
53 /* step 1: assign a random number in [0,1] to each vertex */
54 /* step 2: is the vertex is available, check if its value is the smaller than all values of its naigbours
55 if the answer is yes, the vertex is put into the independend set and all
56 its naighbours are removed from the graph by setting it mis_marker to FALSE */
57
58 /* step 2: is the vertex is available, check if its value is the smaller than all values of its naigbours */
59
60 /* assign random number in [0,1] to each vertex */
61 #pragma omp parallel for private(i) schedule(static)
62 for (i=0;i<n;++i) {
63 if (mis_marker[i]==IS_AVAILABLE) {
64 value[i]=fmod(Paso_SystemMatrixPattern_mis_seed*(i+1),1.);
65 } else {
66 value[i]=2.;
67 }
68 }
69 /* update the seed */
70 /* Paso_SystemMatrixPattern_mis_seed=fmod(sqrt(Paso_SystemMatrixPattern_mis_seed*(n+1)),1.); */
71 /* detect independent vertices as those vertices that have a value less than all values of its naigbours */
72 #pragma omp parallel for private(naib,i,iptr,flag) schedule(static)
73 for (i=0;i<n;++i) {
74 if (mis_marker[i]==IS_AVAILABLE) {
75 flag=IS_IN_MIS_NOW;
76 for (iptr=pattern_p->ptr[i]-index_offset;iptr<pattern_p->ptr[i+1]-index_offset; ++iptr) {
77 naib=pattern_p->index[iptr]-index_offset;
78 if (naib!=i && value[naib]<=value[i]) {
79 flag=IS_AVAILABLE;
80 break;
81 }
82 }
83 mis_marker[i]=flag;
84 }
85 }
86 /* detect independent vertices as those vertices that have a value less than all values of its naigbours */
87 #pragma omp parallel for private(naib,i,iptr) schedule(static)
88 for (i=0;i<n;i++) {
89 if (mis_marker[i]==IS_IN_MIS_NOW) {
90 for (iptr=pattern_p->ptr[i]-index_offset;iptr<pattern_p->ptr[i+1]-index_offset; ++iptr) {
91 naib=pattern_p->index[iptr]-index_offset;
92 if (naib!=i) mis_marker[naib]=IS_CONNECTED_TO_MIS;
93 }
94 mis_marker[i]=IS_IN_MIS;
95 }
96 }
97 }
98 /* swap to TRUE/FALSE in mis_marker */
99 #pragma omp parallel for private(i) schedule(static)
100 for (i=0;i<n;i++) mis_marker[i]=(mis_marker[i]==IS_IN_MIS);
101 }
102 TMPMEMFREE(value);
103 }
104 #undef IS_AVAILABLE
105 #undef IS_IN_MIS_NOW
106 #undef IS_IN_MIS
107 #undef IS_CONNECTED_TO_MIS

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26