45 #include "paz_aztec.h"
49 int *n_nonzeros,
int *N_update,
int **update,
50 double **val,
int **bindx,
51 double **x,
double **b,
double **bt,
double **xexact)
55 int i, n_entries, N_columns, n_global_nonzeros;
56 int ii, j, row, have_xexact = 0 ;
58 int max_ii = 0, max_jj = 0;
62 int *pntr, *bindx1, *pntr1;
63 double *val1, *b1, *bt1, *x1, *xexact1;
65 printf(
"Processor %d of %d entering distrib_matrix.\n",
66 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
70 if(proc_config[PAZ_node] == 0)
72 if ((*xexact) != NULL) have_xexact = 1;
73 printf(
"Broadcasting exact solution\n");
76 if(proc_config[PAZ_N_procs] > 1) {
78 PAZ_broadcast((
char *) N_global,
sizeof(
int), proc_config, PAZ_PACK);
79 PAZ_broadcast((
char *) n_nonzeros,
sizeof(
int), proc_config, PAZ_PACK);
80 PAZ_broadcast((
char *) &have_xexact,
sizeof(
int), proc_config, PAZ_PACK);
81 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
83 if(proc_config[PAZ_node] != 0)
85 (*bindx) = (
int *) calloc(*n_nonzeros+1,
sizeof(
int)) ;
86 (*val) = (
double *) calloc(*n_nonzeros+1,
sizeof(
double)) ;
89 PAZ_broadcast((
char *) (*bindx),
sizeof(
int) *(*n_nonzeros+1),
90 proc_config, PAZ_PACK);
91 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
92 PAZ_broadcast((
char *) (*val),
sizeof(
double)*(*n_nonzeros+1),
93 proc_config, PAZ_PACK);
94 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
96 printf(
"Processor %d of %d done with matrix broadcast.\n",
97 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
100 if(proc_config[PAZ_node] != 0)
102 (*b) = (
double *) calloc(*N_global,
sizeof(
double)) ;
103 (*bt) = (
double *) calloc(*N_global,
sizeof(
double)) ;
104 (*x) = (
double *) calloc(*N_global,
sizeof(
double)) ;
106 (*xexact) = (
double *) calloc(*N_global,
sizeof(
double)) ;
109 PAZ_broadcast((
char *) (*x),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
110 PAZ_broadcast((
char *) (*b),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
111 PAZ_broadcast((
char *) (*bt),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
113 PAZ_broadcast((
char *)
114 (*xexact),
sizeof(
double)*(*N_global), proc_config, PAZ_PACK);
115 PAZ_broadcast(NULL, 0, proc_config, PAZ_SEND);
116 printf(
"Processor %d of %d done with rhs/guess broadcast.\n",
117 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
123 PAZ_read_update(N_update, update, proc_config, (*N_global),
126 printf(
"Processor %d of %d has %d rows of %d total rows.\n",
127 proc_config[PAZ_node],proc_config[PAZ_N_procs],*N_update,(*N_global)) ;
136 if(proc_config[PAZ_N_procs] > 1) {
137 n_global_nonzeros = *n_nonzeros;
139 *n_nonzeros = *N_update;
141 for (i=0; i<*N_update; i++)
142 *n_nonzeros += (*bindx)[(*update)[i]+1] - (*bindx)[(*update)[i]];
144 printf(
"Processor %d of %d has %d nonzeros of %d total nonzeros.\n",
145 proc_config[PAZ_node],proc_config[PAZ_N_procs],
146 *n_nonzeros,n_global_nonzeros) ;
150 for (i=0;i<(*N_global); i++) sum1 += (*b)[i];
152 printf(
"Processor %d of %d has sum of b = %12.4g.\n",
153 proc_config[PAZ_node],proc_config[PAZ_N_procs],sum1) ;
159 bindx1 = (
int *) calloc(*n_nonzeros+1,
sizeof(
int)) ;
160 val1 = (
double *) calloc(*n_nonzeros+1,
sizeof(
double)) ;
161 b1 = (
double *) calloc(*N_update,
sizeof(
double)) ;
162 bt1 = (
double *) calloc(*N_update,
sizeof(
double)) ;
163 x1 = (
double *) calloc(*N_update,
sizeof(
double)) ;
165 xexact1 = (
double *) calloc(*N_update,
sizeof(
double)) ;
167 bindx1[0] = *N_update+1;
169 for (i=0; i<*N_update; i++)
175 if (have_xexact) xexact1[i] = (*xexact)[row];
176 val1[i] = (*val)[row];
177 bindx1[i+1] = bindx1[i];
180 printf(
"Proc %d of %d: Global row = %d: Local row = %d:
181 b = %12.4g: x = %12.4g: bindx = %d: val = %12.4g \n",
182 proc_config[PAZ_node],proc_config[PAZ_N_procs],
183 row, i, b1[i], x1[i], bindx1[i], val1[i]) ;
186 for (j = (*bindx)[row]; j < (*bindx)[row+1]; j++)
188 val1[ bindx1 [i+1] ] = (*val)[j];
189 bindx1[bindx1 [i+1] ] = (*bindx)[j];
194 printf(
"Processor %d of %d done with extracting local operators.\n",
195 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
200 "The residual using MSR format and exact solution on processor %d is %12.4g\n",
201 proc_config[PAZ_node],
202 smsrres (*N_update, (*N_global), val1, bindx1, xexact1, (*xexact), b1));
207 free ((
void *) (*val));
208 free ((
void *) (*bindx));
209 free ((
void *) (*b));
210 free ((
void *) (*bt));
211 free ((
void *) (*x));
212 if (have_xexact) free((
void *) *xexact);
221 if (have_xexact) *xexact = xexact1;
224 if (have_xexact && proc_config[PAZ_N_procs] == 1)
227 "The residual using MSR format and exact solution on processor %d is %12.4g\n",
228 proc_config[PAZ_node],
229 smsrres (*N_update, (*N_global), (*val), (*bindx),
230 (*xexact), (*xexact), (*b)));
234 printf(
"Processor %d of %d leaving distrib_matrix.\n",
235 proc_config[PAZ_node],proc_config[PAZ_N_procs]) ;
double smsrres(int m, int n, double *val, int *indx, double *xlocal, double *x, double *b)
void distrib_msr_matrix(int *proc_config, int *N_global, int *n_nonzeros, int *N_update, int **update, double **val, int **bindx, double **x, double **b, double **bt, double **xexact)