source: CIVL/examples/mpi-omp/AMG2013/struct_mv/struct_io.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: 11.0 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 * Functions for scanning and printing "box-dimensioned" data.
17 *
18 *****************************************************************************/
19
20#ifdef HYPRE_USE_PTHREADS
21#undef HYPRE_USE_PTHREADS
22#endif
23
24#include "headers.h"
25
26
27/*--------------------------------------------------------------------------
28 * hypre_PrintBoxArrayData
29 *--------------------------------------------------------------------------*/
30
31int
32hypre_PrintBoxArrayData( FILE *file,
33 hypre_BoxArray *box_array,
34 hypre_BoxArray *data_space,
35 int num_values,
36 double *data )
37{
38 int ierr = 0;
39
40 hypre_Box *box;
41 hypre_Box *data_box;
42
43 int data_box_volume;
44 int datai;
45
46 hypre_Index loop_size;
47 hypre_IndexRef start;
48 hypre_Index stride;
49
50 int i, j;
51 int loopi, loopj, loopk;
52
53 /*----------------------------------------
54 * Print data
55 *----------------------------------------*/
56
57 hypre_SetIndex(stride, 1, 1, 1);
58
59 hypre_ForBoxI(i, box_array)
60 {
61 box = hypre_BoxArrayBox(box_array, i);
62 data_box = hypre_BoxArrayBox(data_space, i);
63
64 start = hypre_BoxIMin(box);
65 data_box_volume = hypre_BoxVolume(data_box);
66
67 hypre_BoxGetSize(box, loop_size);
68
69 hypre_BoxLoop1Begin(loop_size,
70 data_box, start, stride, datai);
71
72 hypre_BoxLoop1For(loopi, loopj, loopk, datai)
73 {
74 for (j = 0; j < num_values; j++)
75 {
76 fprintf(file, "%d: (%d, %d, %d; %d) %.14e\n",
77 i,
78 hypre_IndexX(start) + loopi,
79 hypre_IndexY(start) + loopj,
80 hypre_IndexZ(start) + loopk,
81 j,
82 data[datai + j*data_box_volume]);
83 }
84 }
85 hypre_BoxLoop1End(datai);
86
87 data += num_values*data_box_volume;
88 }
89
90 return ierr;
91}
92
93/*--------------------------------------------------------------------------
94 * hypre_PrintCCVDBoxArrayData
95 * Note that the the stencil loop (j) is _outside_ the space index loop (datai),
96 * unlie hypre_PrintBoxArrayData (there is no j loop in hypre_PrintCCBoxArrayData)
97 *--------------------------------------------------------------------------*/
98
99int
100hypre_PrintCCVDBoxArrayData( FILE *file,
101 hypre_BoxArray *box_array,
102 hypre_BoxArray *data_space,
103 int num_values,
104 int center_rank,
105 int stencil_size,
106 int *symm_elements,
107 double *data )
108{
109 int ierr = 0;
110
111 hypre_Box *box;
112 hypre_Box *data_box;
113
114 int data_box_volume, datai;
115
116 hypre_Index loop_size;
117 hypre_IndexRef start;
118 hypre_Index stride;
119
120 int i, j;
121 int loopi, loopj, loopk;
122
123 /*----------------------------------------
124 * Print data
125 *----------------------------------------*/
126
127 hypre_SetIndex(stride, 1, 1, 1);
128
129 /* First is the constant, off-diagonal, part of the matrix: */
130 for ( j=0; j<stencil_size; ++j )
131 {
132 if (symm_elements[j] < 0 && j!=center_rank )
133 {
134 fprintf( file, "*: (*, *, *; %d) %.14e\n",
135 j, data[0] );
136 }
137 ++data;
138 }
139
140
141 /* Then each box has a variable, diagonal, part of the matrix: */
142 hypre_ForBoxI(i, box_array)
143 {
144 box = hypre_BoxArrayBox(box_array, i);
145 data_box = hypre_BoxArrayBox(data_space, i);
146
147 start = hypre_BoxIMin(box);
148 data_box_volume = hypre_BoxVolume(data_box);
149
150 hypre_BoxGetSize(box, loop_size);
151
152 hypre_BoxLoop1Begin(loop_size,
153 data_box, start, stride, datai);
154
155 hypre_BoxLoop1For(loopi, loopj, loopk, datai)
156 {
157 fprintf(file, "%d: (%d, %d, %d; %d) %.14e\n",
158 i,
159 hypre_IndexX(start) + loopi,
160 hypre_IndexY(start) + loopj,
161 hypre_IndexZ(start) + loopk,
162 center_rank,
163 data[datai]);
164 }
165 hypre_BoxLoop1End(datai);
166 data += data_box_volume;
167 }
168
169 return ierr;
170}
171
172/*--------------------------------------------------------------------------
173 * hypre_PrintCCBoxArrayData
174 * same as hypre_PrintBoxArrayData but for constant coefficients
175 *--------------------------------------------------------------------------*/
176
177int
178hypre_PrintCCBoxArrayData( FILE *file,
179 hypre_BoxArray *box_array,
180 hypre_BoxArray *data_space,
181 int num_values,
182 double *data )
183{
184 int ierr = 0;
185
186 hypre_Box *box;
187
188 int datai;
189
190 hypre_IndexRef start;
191
192 int i, j;
193
194 /*----------------------------------------
195 * Print data
196 *----------------------------------------*/
197
198 hypre_ForBoxI(i, box_array)
199 {
200 box = hypre_BoxArrayBox(box_array, i);
201
202 start = hypre_BoxIMin(box);
203
204 datai = hypre_CCBoxIndexRank_noargs();
205
206 for (j = 0; j < num_values; j++)
207 {
208 fprintf( file, "*: (*, *, *; %d) %.14e\n",
209 j, data[datai + j] );
210 }
211
212 data += num_values;
213 }
214
215 return ierr;
216}
217
218/*--------------------------------------------------------------------------
219 * hypre_ReadBoxArrayData (for non-constant coefficients)
220 *--------------------------------------------------------------------------*/
221
222int
223hypre_ReadBoxArrayData( FILE *file,
224 hypre_BoxArray *box_array,
225 hypre_BoxArray *data_space,
226 int num_values,
227 double *data )
228{
229 int ierr = 0;
230
231 hypre_Box *box;
232 hypre_Box *data_box;
233
234 int data_box_volume;
235 int datai;
236
237 hypre_Index loop_size;
238 hypre_IndexRef start;
239 hypre_Index stride;
240
241 int i, j, idummy;
242 int loopi, loopj, loopk;
243
244 /*----------------------------------------
245 * Read data
246 *----------------------------------------*/
247
248 hypre_SetIndex(stride, 1, 1, 1);
249
250 hypre_ForBoxI(i, box_array)
251 {
252 box = hypre_BoxArrayBox(box_array, i);
253 data_box = hypre_BoxArrayBox(data_space, i);
254
255 start = hypre_BoxIMin(box);
256 data_box_volume = hypre_BoxVolume(data_box);
257
258 hypre_BoxGetSize(box, loop_size);
259
260 hypre_BoxLoop1Begin(loop_size,
261 data_box, start, stride, datai);
262
263 hypre_BoxLoop1For(loopi, loopj, loopk, datai)
264 {
265 for (j = 0; j < num_values; j++)
266 {
267 fscanf(file, "%d: (%d, %d, %d; %d) %le\n",
268 &idummy,
269 &idummy,
270 &idummy,
271 &idummy,
272 &idummy,
273 &data[datai + j*data_box_volume]);
274 }
275 }
276 hypre_BoxLoop1End(datai);
277
278 data += num_values*data_box_volume;
279 }
280
281 return ierr;
282}
283
284
285/*--------------------------------------------------------------------------
286 * hypre_ReadBoxArrayData_CC (for when there are some constant coefficients)
287 *--------------------------------------------------------------------------*/
288
289int
290hypre_ReadBoxArrayData_CC( FILE *file,
291 hypre_BoxArray *box_array,
292 hypre_BoxArray *data_space,
293 int stencil_size,
294 int real_stencil_size,
295 int constant_coefficient,
296 double *data )
297{
298 int ierr = 0;
299
300 hypre_Box *box;
301 hypre_Box *data_box;
302
303 int data_box_volume, constant_stencil_size;
304 int datai;
305
306 hypre_Index loop_size;
307 hypre_IndexRef start;
308 hypre_Index stride;
309
310 int i, j, idummy;
311 int loopi, loopj, loopk;
312
313 /*----------------------------------------
314 * Read data
315 *----------------------------------------*/
316
317 if ( constant_coefficient==1 ) constant_stencil_size = stencil_size;
318 if ( constant_coefficient==2 ) constant_stencil_size = stencil_size - 1;
319
320 hypre_SetIndex(stride, 1, 1, 1);
321
322 hypre_ForBoxI(i, box_array)
323 {
324 box = hypre_BoxArrayBox(box_array, i);
325 data_box = hypre_BoxArrayBox(data_space, i);
326
327 start = hypre_BoxIMin(box);
328 data_box_volume = hypre_BoxVolume(data_box);
329
330 hypre_BoxGetSize(box, loop_size);
331
332 /* First entries will be the constant part of the matrix.
333 There is one entry for each constant stencil element,
334 excluding ones which are redundant due to symmetry.*/
335 for (j=0; j <constant_stencil_size; j++)
336 {
337 fscanf(file, "*: (*, *, *; %d) %le\n",
338 &idummy,
339 &data[j]);
340 }
341
342 /* Next entries, if any, will be for a variable diagonal: */
343 data += real_stencil_size;
344
345 if ( constant_coefficient==2 )
346 {
347 hypre_BoxLoop1Begin(loop_size,
348 data_box, start, stride, datai);
349
350 hypre_BoxLoop1For(loopi, loopj, loopk, datai)
351 {
352 fscanf(file, "%d: (%d, %d, %d; %d) %le\n",
353 &idummy,
354 &idummy,
355 &idummy,
356 &idummy,
357 &idummy,
358 &data[datai]);
359 }
360 hypre_BoxLoop1End(datai);
361 data += data_box_volume;
362 }
363
364 }
365
366 return ierr;
367}
368
Note: See TracBrowser for help on using the repository browser.