source: CIVL/examples/mpi-omp/AMG2013/struct_mv/new_box_neighbors.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: 10.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#include "headers.h"
15
16#define DEBUG 0
17#if DEBUG
18char filename[255];
19FILE *file;
20int my_rank;
21hypre_Box *box;
22static int debug_count = 0;
23#endif
24
25
26/*--------------------------------------------------------------------------
27 * NEW hypre_BoxNeighborsCreate (for use with "no global partition" option)
28 * here we assign the box nums - we don't compute.
29 * also the ids are the same as the boxnums (no longer globally unique)
30 * AHB 6/05
31 *--------------------------------------------------------------------------*/
32
33
34int
35hypre_BoxNeighborsCreateWithAP( hypre_BoxArray *boxes,
36 int *procs,
37 int *boxnums,
38 int first_local,
39 int num_local,
40 hypre_Index *pshifts,
41 hypre_BoxNeighbors **neighbors_ptr )
42{
43 hypre_BoxNeighbors *neighbors;
44 int *ids, i;
45
46 neighbors = hypre_CTAlloc(hypre_BoxNeighbors, 1);
47 hypre_BoxNeighborsRankLinks(neighbors) =
48 hypre_CTAlloc(hypre_RankLink *, num_local);
49
50 hypre_BoxNeighborsBoxes(neighbors) = boxes;
51 hypre_BoxNeighborsProcs(neighbors) = procs;
52
53 hypre_BoxNeighborsBoxnums(neighbors) = boxnums;
54
55 /*these ids are not used anymore - just make them
56 the same as the boxnums - eventually get rid of these */
57 ids = hypre_CTAlloc(int, hypre_BoxArraySize(boxes));
58 hypre_ForBoxI(i, boxes)
59 {
60 ids [i] = boxnums[i];
61 }
62 hypre_BoxNeighborsIDs(neighbors) = ids;
63
64
65 hypre_BoxNeighborsFirstLocal(neighbors) = first_local;
66 hypre_BoxNeighborsNumLocal(neighbors) = num_local;
67
68
69 hypre_BoxNeighborsPShifts(neighbors) = pshifts;
70
71
72
73 *neighbors_ptr = neighbors;
74
75 return 0;
76}
77
78
79
80/*--------------------------------------------------------------------------
81 * hypre_BoxNeighborsAssembleWithAP:
82 *
83 * NOte: Now we do not keep nearby boxes with the same proc id (AB 10/04)
84 * as a "neighbor" box
85 *
86 * Add "periodic boxes" to the 'boxes' BoxArray, then find boxes that
87 * are "near" (defined by 'max_distance') the local boxes. The ranks
88 * (in the 'boxes' array) of the nearby boxes of each local box are
89 * stored in a linked list (called 'rank_links') for fast access in
90 * other algorithms.
91 *
92 *
93 * NOTE: A box is not a neighbor of itself.
94 *
95 * NOTE: Periodic boxes are not assigned unique ids. The generating
96 * box and its associated processor/ID information can be found with
97 * index 'i % num_boxes', where 'i' is the index for the periodic box.
98 *
99 *--------------------------------------------------------------------------*/
100
101int
102hypre_BoxNeighborsAssembleWithAP( hypre_BoxNeighbors *neighbors,
103 hypre_Index periodic,
104 int max_distance,
105 int prune )
106{
107 hypre_BoxArray *boxes;
108 int *procs;
109 int *boxnums;
110 int *ids;
111 int first_local;
112 int num_local;
113 int num_periods;
114 hypre_Index *pshifts;
115
116 hypre_IndexRef pshift;
117 int keep_box;
118 int num_boxes, num_nonperiodic_boxes;
119
120 hypre_RankLink **rank_links;
121 hypre_RankLink *rank_link;
122
123 hypre_Box *local_box;
124 hypre_Box *neighbor_box;
125
126 int distance;
127 int diff;
128 int i, j, p, d, ilocal, inew;
129
130 int px = hypre_IndexX(periodic);
131 int py = hypre_IndexY(periodic);
132 int pz = hypre_IndexZ(periodic);
133
134 int i_periodic = px ? 1 : 0;
135 int j_periodic = py ? 1 : 0;
136 int k_periodic = pz ? 1 : 0;
137
138 int ierr = 0;
139
140 int *tmp_p;
141
142 int first_local_orig, check_loc;;
143
144
145
146 /*--------------------------------------------------
147 * Create periodic boxes
148 *--------------------------------------------------*/
149
150 /* periodic boxes are given box numbers also */
151
152
153 /*prune = 0;*/
154
155 boxes = hypre_BoxNeighborsBoxes(neighbors);
156 procs = hypre_BoxNeighborsProcs(neighbors);
157 boxnums = hypre_BoxNeighborsBoxnums(neighbors); /* boxnums and ids are
158 the same values */
159 ids = hypre_BoxNeighborsIDs(neighbors);
160 num_boxes = hypre_BoxArraySize(boxes);
161
162 num_nonperiodic_boxes = num_boxes;
163
164
165 num_periods = (1+2*i_periodic) * (1+2*j_periodic) * (1+2*k_periodic);
166 pshifts = hypre_BoxNeighborsPShifts(neighbors);
167
168
169 tmp_p = hypre_CTAlloc(int, num_boxes);
170
171
172 if( num_periods > 1 )
173 {
174
175 hypre_BoxArraySetSize(boxes, num_periods*num_boxes);
176 procs = hypre_TReAlloc(procs, int, num_periods*num_boxes);
177 /* 11/19 */
178 boxnums = hypre_TReAlloc(boxnums, int, num_periods*num_boxes);
179 ids = hypre_TReAlloc(ids, int, num_periods*num_boxes);
180 tmp_p = hypre_TReAlloc(tmp_p, int, num_periods*num_boxes);
181
182 /* spshifts are already set */
183 for (p = 1; p < num_periods; p++)
184 {
185 pshift = pshifts[p];
186 for (i = 0; i < num_boxes; i++)
187 {
188 inew = i + p*num_boxes;
189 local_box = hypre_BoxArrayBox(boxes, inew);
190 hypre_CopyBox(hypre_BoxArrayBox(boxes, i), local_box);
191 hypre_BoxShiftPos(local_box, pshift);
192 procs[inew] = procs[i];
193 /* 11/19 */
194 /* give periodic boxes a boxnum and id also */
195 boxnums[inew] = boxnums[i];
196 ids[inew] = ids[i];
197 tmp_p[inew] = p;
198
199
200 }
201 }
202
203
204 } /* end of make periodic boxes */
205
206
207 hypre_BoxNeighborsBoxnums(neighbors) = boxnums;
208 hypre_BoxNeighborsIDs(neighbors)= ids;
209
210 hypre_BoxNeighborsBoxes(neighbors) = boxes;
211 hypre_BoxNeighborsProcs(neighbors) = procs;
212 hypre_CopyIndex(periodic, hypre_BoxNeighborsPeriodic(neighbors));
213 hypre_BoxNeighborsNumPeriods(neighbors) = num_periods;
214
215
216 /*-----------------------------------------------------------------
217 * Find neighboring boxes:
218 *
219 * Keep boxes that are nearby. - Don't treat periodic differently!
220 *-----------------------------------------------------------------*/
221
222
223 rank_links = hypre_BoxNeighborsRankLinks(neighbors);
224 first_local = hypre_BoxNeighborsFirstLocal(neighbors);
225 num_local = hypre_BoxNeighborsNumLocal(neighbors);
226 inew = 0;
227 num_boxes = 0;
228
229 first_local_orig = first_local;
230
231
232
233 /* loop over all potential neighbor boxes */
234 hypre_ForBoxI(i, boxes)
235 {
236 keep_box = 0;
237 neighbor_box = hypre_BoxArrayBox(boxes, i);
238
239 /*moved from above 1/11*/
240 if (i < num_nonperiodic_boxes)
241 {
242 tmp_p[i] = 0;
243 }
244
245 /* 1/19/05 - this added because we are copying boxes
246 in the loop - so local boxes coupld be separated */
247 check_loc = 0;
248
249 if ((first_local < first_local_orig) && (i < (first_local_orig + num_local)))
250 {
251 check_loc = 1;
252 }
253
254
255 /*check each of my local boxes against this box*/
256 for (j = 0; j < num_local; j++)
257 {
258 ilocal = first_local + j;
259
260 /* 1/19/05 - recalculate if the local boxes are separated*/
261 if (check_loc && ilocal >= num_boxes)
262 {
263 ilocal = first_local_orig + j;
264 }
265
266
267 if (i == ilocal) /* if neighbor box and local box are the same box */
268 {
269 keep_box = 1;
270 }
271 else
272 {
273 local_box = hypre_BoxArrayBox(boxes, ilocal);
274
275 /* compute distance info */
276 distance = 0;
277 for (d = 0; d < 3; d++)
278 {
279 diff = hypre_BoxIMinD(neighbor_box, d) -
280 hypre_BoxIMaxD(local_box, d);
281 if (diff > 0)
282 {
283 distance = hypre_max(distance, diff);
284 }
285
286 diff = hypre_BoxIMinD(local_box, d) -
287 hypre_BoxIMaxD(neighbor_box, d);
288 if (diff > 0)
289 {
290 distance = hypre_max(distance, diff);
291 }
292 }
293
294 /* if close enough, keep the box */
295 if (distance <= max_distance)
296 {
297 keep_box = 1;
298
299 p = tmp_p[i]; /* periodic number for neighbor box */
300
301
302 /* create new rank_link and prepend to the list */
303 hypre_RankLinkCreate(num_boxes, p, &rank_link);
304 hypre_RankLinkNext(rank_link) = rank_links[j];
305 rank_links[j] = rank_link;
306
307
308 }
309 } /*end of "if neighbor and my box are the same box "*/
310 } /* end of local boxes loop */
311
312 if (prune)
313 {
314
315 if (keep_box)
316 {
317
318
319
320 /* copy now - avoid an extra loop */
321 hypre_CopyBox(hypre_BoxArrayBox(boxes, i),
322 hypre_BoxArrayBox(boxes, num_boxes));
323 boxnums[num_boxes] = boxnums[i];
324 ids[num_boxes] = ids[i];
325 procs[num_boxes] = procs[i];
326
327 if (i == first_local)
328 {
329 first_local = num_boxes;
330 }
331
332
333 num_boxes++;
334
335 }
336 }
337 else
338 {
339 /* keep all of the boxes */
340 num_boxes++;
341 }
342
343 }/*end of loop through each box */
344
345 /*-----------------------------------------------------------------
346 * Prune the array of neighbor boxes
347 *-----------------------------------------------------------------*/
348
349
350
351 hypre_BoxArraySetSize(boxes, num_boxes);
352 hypre_BoxNeighborsFirstLocal(neighbors) = first_local;
353
354
355 hypre_TFree(tmp_p);
356
357
358 return ierr;
359}
360
361
362
Note: See TracBrowser for help on using the repository browser.