/[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 817 - (show annotations)
Sat Aug 26 03:08:52 2006 UTC (13 years, 10 months ago) by ksteube
File MIME type: text/plain
File size: 4908 byte(s)
Can now compile and run with MPI on shake71


1 /* $Id$ */
2
3 /*
4 ********************************************************************************
5 * Copyright 2006 by ACcESS MNRF *
6 * *
7 * http://www.access.edu.au *
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 /* Paso: SystemMatrixPattern: Paso_SystemMatrixPattern_mis
17
18 searches for a maximal independent set MIS in the matrix pattern
19 vertices in the maximal independent set are marked in mis_marker
20 nodes to be considered are marked by -1 on the input in mis_marker
21
22 */
23 /**********************************************************************/
24
25 /* Copyrights by ACcESS Australia 2003,2004,2005 */
26 /* Author: gross@access.edu.au */
27
28 /**************************************************************/
29
30 #ifdef PASO_MPI
31 #include <mpi.h>
32 #endif
33 #include "Paso.h"
34 #include "PasoUtil.h"
35 #include "SystemMatrixPattern.h"
36
37
38 /* used to generate pseudo random numbers: */
39
40 static double Paso_SystemMatrixPattern_mis_seed=.4142135623730951;
41
42
43 /***************************************************************/
44
45 #define IS_AVAILABLE -1
46 #define IS_IN_MIS_NOW -2
47 #define IS_IN_MIS -3
48 #define IS_CONNECTED_TO_MIS -4
49
50 void Paso_SystemMatrixPattern_mis(Paso_SystemMatrixPattern* pattern_p, index_t* mis_marker) {
51
52 index_t index_offset=(pattern_p->type & PATTERN_FORMAT_OFFSET1 ? 1:0);
53 dim_t i;
54 index_t naib,iptr;
55 bool_t flag;
56 dim_t n=pattern_p->n_ptr;
57 if (pattern_p->type & PATTERN_FORMAT_SYM) {
58 Paso_setError(TYPE_ERROR,"Paso_SystemMatrixPattern_mis: symmetric matrix pattern is not supported yet");
59 return;
60 }
61 double *value=TMPMEMALLOC(n,double);
62 if (!Paso_checkPtr(value)) {
63
64
65 /* is there any vertex available ?*/
66 while (Paso_Util_isAny(n,mis_marker,IS_AVAILABLE)) {
67 /* step 1: assign a random number in [0,1] to each vertex */
68 /* step 2: is the vertex is available, check if its value is the smaller than all values of its naigbours
69 if the answer is yes, the vertex is put into the independend set and all
70 its naighbours are removed from the graph by setting it mis_marker to FALSE */
71
72 /* step 2: is the vertex is available, check if its value is the smaller than all values of its naigbours */
73
74 /* assign random number in [0,1] to each vertex */
75 #pragma omp parallel for private(i) schedule(static)
76 for (i=0;i<n;++i) {
77 if (mis_marker[i]==IS_AVAILABLE) {
78 value[i]=fmod(Paso_SystemMatrixPattern_mis_seed*(i+1),1.);
79 } else {
80 value[i]=2.;
81 }
82 }
83 /* update the seed */
84 /* Paso_SystemMatrixPattern_mis_seed=fmod(sqrt(Paso_SystemMatrixPattern_mis_seed*(n+1)),1.); */
85 /* detect independent vertices as those vertices that have a value less than all values of its naigbours */
86 #pragma omp parallel for private(naib,i,iptr,flag) schedule(static)
87 for (i=0;i<n;++i) {
88 if (mis_marker[i]==IS_AVAILABLE) {
89 flag=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 && value[naib]<=value[i]) {
93 flag=IS_AVAILABLE;
94 break;
95 }
96 }
97 mis_marker[i]=flag;
98 }
99 }
100 /* detect independent vertices as those vertices that have a value less than all values of its naigbours */
101 #pragma omp parallel for private(naib,i,iptr) schedule(static)
102 for (i=0;i<n;i++) {
103 if (mis_marker[i]==IS_IN_MIS_NOW) {
104 for (iptr=pattern_p->ptr[i]-index_offset;iptr<pattern_p->ptr[i+1]-index_offset; ++iptr) {
105 naib=pattern_p->index[iptr]-index_offset;
106 if (naib!=i) mis_marker[naib]=IS_CONNECTED_TO_MIS;
107 }
108 mis_marker[i]=IS_IN_MIS;
109 }
110 }
111 }
112 /* swap to TRUE/FALSE in mis_marker */
113 #pragma omp parallel for private(i) schedule(static)
114 for (i=0;i<n;i++) mis_marker[i]=(mis_marker[i]==IS_IN_MIS);
115 }
116 TMPMEMFREE(value);
117 }
118 #undef IS_AVAILABLE
119 #undef IS_IN_MIS_NOW
120 #undef IS_IN_MIS
121 #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