45 #include "paz_aztec.h"
48 int *N_global,
int *N_blk_global,
49 int *n_nonzeros,
int *n_blk_nonzeros,
50 int *N_update,
int **update,
51 int *bindx_msr,
double *val_msr,
52 double **val,
int **indx,
int **rpntr,
int **cpntr,
53 int **bpntr,
int **bindx)
64 int i, n_entries, N_columns;
67 int max_ii = 0, max_jj = 0;
71 int *pntr, *indx1, *pntr1;
73 int blocksize, N_blk_equations, N_block_entries, n_vbr_nonzeros, n_msr_nonzeros;
74 int total_msr_storage, total_vbr_storage;
75 int variable_block_size, blk_type;
76 int cur_blk_ptr=0, prev_blk_ptr;
78 if(proc_config[PAZ_node] == 0)
83 printf(
"***************************************************************\n");
84 if (partition_file[0] >=
'0' && partition_file[0] <=
'9')
86 blocksize = atoi(partition_file);
87 printf(
"Using block size of %d to convert from MSR to VBR\n",blocksize);
88 N_blk_equations = *N_global/blocksize;
91 *cpntr = (
int *) calloc(N_blk_equations+2,
sizeof(
int)) ;
94 for (i=0; i<N_blk_equations; i++) (*cpntr)[i] = blocksize;
97 variable_block_size = *N_global%blocksize;
100 if (variable_block_size)
103 (*cpntr)[N_blk_equations-1] = variable_block_size;
104 blk_type = -blocksize;
119 printf(
"Using partition from %s to convert from MSR to VBR\n",
121 data = fopen(partition_file,
"r") ;
123 while(cur_blk_ptr !=*N_global)
125 fscanf(data,
"%d", &cur_blk_ptr);
131 *cpntr = (
int *) calloc(N_blk_equations+1,
sizeof(
int)) ;
134 data = fopen(partition_file,
"r") ;
135 fscanf(data,
"%d", &prev_blk_ptr);
137 while(cur_blk_ptr !=*N_global)
139 fscanf(data,
"%d", &cur_blk_ptr);
140 (*cpntr)[N_blk_equations] = cur_blk_ptr - prev_blk_ptr;
141 prev_blk_ptr = cur_blk_ptr;
151 N_block_entries = *n_nonzeros;
152 n_vbr_nonzeros =
min(abs(*n_nonzeros * blocksize * blocksize),
154 *N_blk_global = N_blk_equations;
156 printf(
"\nEstimated Storage parameters for VBR:\n");
157 printf(
" Number of block equations = %d\n",N_blk_equations);
158 printf(
" Number of block entries = %d\n",N_block_entries);
159 printf(
" Number of scalar entries = %d\n",n_vbr_nonzeros);
162 *bpntr = (
int *) calloc(N_blk_equations+1,
sizeof(
int)) ;
163 *rpntr = (
int *) calloc(N_blk_equations+1,
sizeof(
int)) ;
164 *bindx = (
int *) calloc(N_block_entries+1,
sizeof(
int)) ;
165 *indx = (
int *) calloc(N_block_entries+1,
sizeof(
int)) ;
166 *val = (
double *) calloc(n_vbr_nonzeros+1,
sizeof(
double)) ;
169 while (n_vbr_nonzeros >= *n_nonzeros && (*val) == NULL)
171 printf(
"Error: Unable to allocate %d bytes to create VBR matrix.\n",
172 n_vbr_nonzeros*
sizeof(
double));
173 printf(
" Trying to allocate %d bytes.\n",
174 n_vbr_nonzeros*
sizeof(
double)/2);
176 *val = (
double *) calloc(n_vbr_nonzeros+1,
sizeof(
double)) ;
179 PAZ_msr2vbr(*val, *indx, *rpntr, *cpntr, *bpntr, *bindx, bindx_msr,val_msr,
180 N_blk_equations, N_blk_equations, N_block_entries,
181 n_vbr_nonzeros, blk_type);
183 n_msr_nonzeros = *n_nonzeros;
185 *n_nonzeros = (*indx)[(*bpntr)[*N_blk_global]];
186 *n_blk_nonzeros = (*bpntr)[*N_blk_global];
188 *bindx = (
int *) realloc((
void *) (*bindx),
189 (*n_blk_nonzeros+1)*
sizeof(
int)) ;
190 *indx = (
int *) realloc((
void *) (*indx),
191 (*n_blk_nonzeros+1)*
sizeof(
int)) ;
192 *val = (
double *) realloc((
void *) (*val),
193 (*n_nonzeros+1)*
sizeof(
double)) ;
194 printf(
"\nActual Storage parameters for VBR:\n");
195 printf(
" Number of block equations = %d\n",N_blk_equations);
196 printf(
" Number of block entries = %d\n",*n_blk_nonzeros);
197 printf(
" Number of scalar entries = %d\n",*n_nonzeros);
199 total_msr_storage = 4* (n_msr_nonzeros+1) + 8*(n_msr_nonzeros+1);
200 total_vbr_storage = 4*3*(N_blk_equations+1) + 4*2*(*n_blk_nonzeros+1) +
202 printf(
"\nTotal MSR storage (bytes) = %d\n",total_msr_storage);
203 printf(
"Total VBR storage (bytes) = %d\n",total_vbr_storage);
204 printf(
"Ratio of VBR to MSR storage = %5.2f\n",
205 (
float)total_vbr_storage/(
float)total_msr_storage);
208 printf(
"***************************************************************\n");
void create_vbr(char *partition_file, int *proc_config, int *N_global, int *N_blk_global, int *n_nonzeros, int *n_blk_nonzeros, int *N_update, int **update, int *bindx_msr, double *val_msr, double **val, int **indx, int **rpntr, int **cpntr, int **bpntr, int **bindx)