45 #include "paz_aztec.h"
49 int *N_global,
int *N_blk_global,
50 int *n_nonzeros,
int *n_blk_nonzeros,
51 int *N_update,
int **update,
52 double **val,
int **indx,
int **rpntr,
int **cpntr,
53 int **bpntr,
int **bindx,
54 double **x,
double **b,
double **bt,
double **xexact)
58 int i, n_entries, N_columns, n_global_nonzeros, n_global_blk_nonzeros;
60 int ii, j, row, have_xexact = 0 ;
62 int max_ii = 0, max_jj = 0;
66 int *rpntr1, *bindx1, *bpntr1, *indx1;
67 double *val1, *b1, *bt1, *x1, *xexact1;
69 printf(
"Processor %d of %d entering distrib_matrix.\n",
70 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
74 if(proc_config[PAZ_node] == 0)
76 if ((*xexact) != NULL) have_xexact = 1;
77 printf(
"Broadcasting exact solution\n");
80 if(proc_config[PAZ_N_procs] > 1)
83 PAZ_broadcast((
char *) N_global,
sizeof(
int), proc_config, PAZ_PACK);
84 PAZ_broadcast((
char *) N_blk_global,
sizeof(
int), proc_config, PAZ_PACK);
85 PAZ_broadcast((
char *) n_nonzeros,
sizeof(
int), proc_config, PAZ_PACK);
86 PAZ_broadcast((
char *) n_blk_nonzeros,
sizeof(
int), proc_config, PAZ_PACK);
87 PAZ_broadcast((
char *) &have_xexact,
sizeof(
int), proc_config, PAZ_PACK);
88 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
90 printf(
"Processor %d of %d done with global parameter broadcast.\n",
91 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
93 if(proc_config[PAZ_node] != 0)
95 *bpntr = (
int *) calloc(*N_blk_global+1,
sizeof(
int)) ;
96 *rpntr = (
int *) calloc(*N_blk_global+1,
sizeof(
int)) ;
97 *bindx = (
int *) calloc(*n_blk_nonzeros+1,
sizeof(
int)) ;
98 *indx = (
int *) calloc(*n_blk_nonzeros+1,
sizeof(
int)) ;
99 *val = (
double *) calloc(*n_nonzeros+1,
sizeof(
double)) ;
100 printf(
"Processor %d of %d done with global calloc.\n",
101 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
104 PAZ_broadcast((
char *) (*bpntr),
sizeof(
int) *(*N_blk_global+1),
105 proc_config, PAZ_PACK);
106 PAZ_broadcast((
char *) (*rpntr),
sizeof(
int) *(*N_blk_global+1),
107 proc_config, PAZ_PACK);
108 PAZ_broadcast((
char *) (*bindx),
sizeof(
int) *(*n_blk_nonzeros+1),
109 proc_config, PAZ_PACK);
110 PAZ_broadcast((
char *) (*indx),
sizeof(
int) *(*n_blk_nonzeros+1),
111 proc_config, PAZ_PACK);
112 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
113 PAZ_broadcast((
char *) (*val),
sizeof(
double)*(*n_nonzeros+1),
114 proc_config, PAZ_PACK);
115 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
117 printf(
"Processor %d of %d done with matrix broadcast.\n",
118 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
121 if(proc_config[PAZ_node] != 0)
123 (*b) = (
double *) calloc(*N_global,
sizeof(
double)) ;
124 (*bt) = (
double *) calloc(*N_global,
sizeof(
double)) ;
125 (*x) = (
double *) calloc(*N_global,
sizeof(
double)) ;
127 (*xexact) = (
double *) calloc(*N_global,
sizeof(
double)) ;
130 PAZ_broadcast((
char *) (*x),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
131 PAZ_broadcast((
char *) (*b),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
132 PAZ_broadcast((
char *) (*bt),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
134 PAZ_broadcast((
char *)
135 (*xexact),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
136 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
137 printf(
"Processor %d of %d done with rhs/guess broadcast.\n",
138 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
144 PAZ_read_update(N_update, update, proc_config, *N_blk_global,
147 printf(
"Processor %d of %d has %d rows of %d total block rows.\n",
148 proc_config[PAZ_node],proc_config[PAZ_N_procs],*N_update,*N_blk_global) ;
157 if(proc_config[PAZ_N_procs] > 1)
159 n_global_nonzeros = *n_nonzeros;
160 n_global_blk_nonzeros = *n_blk_nonzeros;
166 for (i=0; i<*N_update; i++)
169 *n_nonzeros += (*indx)[(*bpntr)[row+1]] - (*indx)[(*bpntr)[row]];
170 *n_blk_nonzeros += (*bpntr)[row+1] - (*bpntr)[row];
171 N_local += (*rpntr)[row+1] - (*rpntr)[row];
175 printf(
"Processor %d of %d has %d nonzeros of %d total nonzeros.\n",
176 proc_config[PAZ_node],proc_config[PAZ_N_procs],
177 *n_nonzeros,n_global_nonzeros) ;
179 printf(
"Processor %d of %d has %d block nonzeros of %d total block nonzeros.\n",
180 proc_config[PAZ_node],proc_config[PAZ_N_procs],
181 *n_blk_nonzeros,n_global_blk_nonzeros) ;
183 printf(
"Processor %d of %d has %d equations of %d total equations.\n",
184 proc_config[PAZ_node],proc_config[PAZ_N_procs],
189 for (i=0;i<*N_global; i++) sum1 += (*b)[i];
191 printf(
"Processor %d of %d has sum of b = %12.4g.\n",
192 proc_config[PAZ_node],proc_config[PAZ_N_procs],sum1) ;
198 bpntr1 = (
int *) calloc(*N_update+1,
sizeof(
int)) ;
199 rpntr1 = (
int *) calloc(*N_update+1,
sizeof(
int)) ;
200 bindx1 = (
int *) calloc(*n_blk_nonzeros+1,
sizeof(
int)) ;
201 indx1 = (
int *) calloc(*n_blk_nonzeros+1,
sizeof(
int)) ;
202 val1 = (
double *) calloc(*n_nonzeros+1,
sizeof(
double)) ;
203 b1 = (
double *) calloc(N_local,
sizeof(
double)) ;
204 bt1 = (
double *) calloc(N_local,
sizeof(
double)) ;
205 x1 = (
double *) calloc(N_local,
sizeof(
double)) ;
207 xexact1 = (
double *) calloc(N_local,
sizeof(
double)) ;
210 int cur_blk_size, indx_offset, len_val, row_offset, row_offset1;
211 double *val_ptr, *val1_ptr;
216 for (i=0; i<*N_update; i++)
219 cur_blk_size = (*rpntr)[row+1] - (*rpntr)[row];
220 rpntr1[i+1] = rpntr1[i] + cur_blk_size;
221 row_offset = (*rpntr)[row];
222 row_offset1 = rpntr1[i];
223 for (j = 0; j<cur_blk_size; j++)
225 b1[row_offset1+j] = (*b)[row_offset+j];
226 x1[row_offset1+j] = (*x)[row_offset+j];
227 if (have_xexact) xexact1[row_offset1+j] = (*xexact)[row_offset+j];
229 bpntr1[i+1] = bpntr1[i];
232 printf(
"Proc %d of %d: Global row = %d: Local row = %d:
233 b = %12.4g: x = %12.4g: bindx = %d: val = %12.4g \n",
234 proc_config[PAZ_node],proc_config[PAZ_N_procs],
235 row, i, b1[i], x1[i], bindx1[i], val1[i]) ;
237 indx_offset = (*indx)[(*bpntr)[row]] - indx1[bpntr1[i]];
238 for (j = (*bpntr)[row]; j < (*bpntr)[row+1]; j++)
240 indx1[bpntr1 [i+1] + 1] = (*indx)[j+1] - indx_offset;
241 bindx1[bpntr1 [i+1] ] = (*bindx)[j];
244 len_val = indx1[bpntr1[i+1]] - indx1[bpntr1[i]];
245 val_ptr = (*val)+(*indx)[(*bpntr)[row]];
246 val1_ptr = val1+indx1[bpntr1[i]];
247 for (j = 0; j<len_val; j++)
249 *val1_ptr = *val_ptr;
250 val_ptr++; val1_ptr++;
254 printf(
"Processor %d of %d done with extracting local operators.\n",
255 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
260 "The residual using VBR format and exact solution on processor %d is %12.4g\n",
261 proc_config[PAZ_node],
262 svbrres (N_local, *N_global, *N_update, val1, indx1, bindx1,
263 rpntr1, (*rpntr), bpntr1, bpntr1+1,
269 free ((
void *) (*val));
270 free ((
void *) (*indx));
271 free ((
void *) (*bindx));
272 free ((
void *) (*bpntr));
273 free ((
void *) (*rpntr));
274 free ((
void *) (*b));
275 free ((
void *) (*bt));
276 free ((
void *) (*x));
277 if (have_xexact) free((
void *) *xexact);
289 if (have_xexact) *xexact = xexact1;
292 if (have_xexact && proc_config[PAZ_N_procs] == 1)
295 "The residual using VBR format and exact solution on processor %d is %12.4g\n",
296 proc_config[PAZ_node],
297 svbrres (*N_global, *N_global, *N_update, (*val), (*indx), (*bindx),
298 (*rpntr), (*rpntr), (*bpntr), (*bpntr)+1,
303 printf(
"Processor %d of %d leaving distrib_matrix.\n",
304 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
double svbrres(int m, int n, int m_blk, double *val, int *indx, int *bindx, int *rpntr, int *cpntr, int *bpntrb, int *bpntre, double *x, double *b)
void distrib_vbr_matrix(int *proc_config, int *N_global, int *N_blk_global, int *n_nonzeros, int *n_blk_nonzeros, int *N_update, int **update, double **val, int **indx, int **rpntr, int **cpntr, int **bpntr, int **bindx, double **x, double **b, double **bt, double **xexact)