source: CIVL/examples/mpi-omp/AMG2013/parcsr_ls/par_indepset.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*BHEADER**********************************************************************
2 * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
3 * Produced at the Lawrence Livermore National Laboratory.
4 * This file is part of HYPRE. See file COPYRIGHT for details.
5 *
6 * HYPRE is free software; you can redistribute it and/or modify it under the
7 * terms of the GNU Lesser General Public License (as published by the Free
8 * Software Foundation) version 2.1 dated February 1999.
9 *
10 * $Revision: 2.4 $
11 ***********************************************************************EHEADER*/
12
13
14
15/******************************************************************************
16 *
17 *****************************************************************************/
18
19#include "headers.h"
20
21/*==========================================================================*/
22/*==========================================================================*/
23/**
24 Augments measures by some random value between 0 and 1.
25
26 {\bf Input files:}
27 headers.h
28
29 @return Error code.
30
31 @param S [IN]
32 parent graph matrix in CSR format
33 @param measure_array [IN/OUT]
34 measures assigned to each node of the parent graph
35
36 @see hypre_AMGIndepSet */
37/*--------------------------------------------------------------------------*/
38
39int
40hypre_BoomerAMGIndepSetInit( hypre_ParCSRMatrix *S,
41 double *measure_array ,
42 int seq_rand)
43{
44 hypre_CSRMatrix *S_diag = hypre_ParCSRMatrixDiag(S);
45 MPI_Comm comm = hypre_ParCSRMatrixComm(S);
46 int S_num_nodes = hypre_CSRMatrixNumRows(S_diag);
47 HYPRE_BigInt i;
48 int j, my_id;
49 int ierr = 0;
50
51 MPI_Comm_rank(comm,&my_id);
52 j = 2747+my_id;
53 if (seq_rand) j = 2747;
54 hypre_SeedRand(j);
55 if (seq_rand)
56 {
57 for (i = 0; i < hypre_ParCSRMatrixFirstRowIndex(S); i++)
58 hypre_Rand();
59 }
60 for (j = 0; j < S_num_nodes; j++)
61 {
62 measure_array[j] += hypre_Rand();
63 }
64
65 return (ierr);
66}
67
68/*==========================================================================*/
69/*==========================================================================*/
70/**
71 Select an independent set from a graph. This graph is actually a
72 subgraph of some parent graph. The parent graph is described as a
73 matrix in compressed sparse row format, where edges in the graph are
74 represented by nonzero matrix coefficients (zero coefficients are
75 ignored). A positive measure is given for each node in the
76 subgraph, and this is used to pick the independent set. A measure
77 of zero must be given for all other nodes in the parent graph. The
78 subgraph is a collection of nodes in the parent graph.
79
80 Positive entries in the `IS\_marker' array indicate nodes in the
81 independent set. All other entries are zero.
82
83 The algorithm proceeds by first setting all nodes in `graph\_array'
84 to be in the independent set. Nodes are then removed from the
85 independent set by simply comparing the measures of adjacent nodes.
86
87 {\bf Input files:}
88 headers.h
89
90 @return Error code.
91
92 @param S [IN]
93 parent graph matrix in CSR format
94 @param measure_array [IN]
95 measures assigned to each node of the parent graph
96 @param graph_array [IN]
97 node numbers in the subgraph to be partitioned
98 @param graph_array_size [IN]
99 number of nodes in the subgraph to be partitioned
100 @param IS_marker [IN/OUT]
101 marker array for independent set
102
103 @see hypre_InitAMGIndepSet */
104/*--------------------------------------------------------------------------*/
105
106int
107hypre_BoomerAMGIndepSet( hypre_ParCSRMatrix *S,
108 double *measure_array,
109 int *graph_array,
110 int graph_array_size,
111 int *graph_array_offd,
112 int graph_array_offd_size,
113 int *IS_marker,
114 int *IS_marker_offd )
115{
116 hypre_CSRMatrix *S_diag = hypre_ParCSRMatrixDiag(S);
117 int *S_diag_i = hypre_CSRMatrixI(S_diag);
118 int *S_diag_j = hypre_CSRMatrixJ(S_diag);
119 hypre_CSRMatrix *S_offd = hypre_ParCSRMatrixOffd(S);
120 int *S_offd_i = hypre_CSRMatrixI(S_offd);
121 int *S_offd_j;
122
123 int local_num_vars = hypre_CSRMatrixNumRows(S_diag);
124 int i, j, ig, jS, jj;
125
126 int ierr = 0;
127
128 /*-------------------------------------------------------
129 * Initialize IS_marker by putting all nodes in
130 * the independent set.
131 *-------------------------------------------------------*/
132
133 if (hypre_CSRMatrixNumCols(S_offd))
134 {
135 S_offd_j = hypre_CSRMatrixJ(S_offd);
136 }
137
138 for (ig = 0; ig < graph_array_size; ig++)
139 {
140 i = graph_array[ig];
141 if (measure_array[i] > 1)
142 {
143 IS_marker[i] = 1;
144 }
145 }
146 for (ig = 0; ig < graph_array_offd_size; ig++)
147 {
148 i = graph_array_offd[ig];
149 if (measure_array[i+local_num_vars] > 1)
150 {
151 IS_marker_offd[i] = 1;
152 }
153 }
154
155 /*-------------------------------------------------------
156 * Remove nodes from the initial independent set
157 *-------------------------------------------------------*/
158
159 for (ig = 0; ig < graph_array_size; ig++)
160 {
161 i = graph_array[ig];
162 if (measure_array[i] > 1)
163 {
164 for (jS = S_diag_i[i]; jS < S_diag_i[i+1]; jS++)
165 {
166 j = S_diag_j[jS];
167 if (j < 0) j = -j-1;
168
169 /* only consider valid graph edges */
170 /* if ( (measure_array[j] > 1) && (S_diag_data[jS]) ) */
171 if (measure_array[j] > 1)
172 {
173 if (measure_array[i] > measure_array[j])
174 {
175 IS_marker[j] = 0;
176 }
177 else if (measure_array[j] > measure_array[i])
178 {
179 IS_marker[i] = 0;
180 }
181 }
182 }
183 for (jS = S_offd_i[i]; jS < S_offd_i[i+1]; jS++)
184 {
185 jj = S_offd_j[jS];
186 if (jj < 0) jj = -jj-1;
187 j = local_num_vars+jj;
188
189 /* only consider valid graph edges */
190 /* if ( (measure_array[j] > 1) && (S_offd_data[jS]) ) */
191 if (measure_array[j] > 1)
192 {
193 if (measure_array[i] > measure_array[j])
194 {
195 IS_marker_offd[jj] = 0;
196 }
197 else if (measure_array[j] > measure_array[i])
198 {
199 IS_marker[i] = 0;
200 }
201 }
202 }
203 }
204 }
205
206 return (ierr);
207}
208
Note: See TracBrowser for help on using the repository browser.