39 namespace it = Input::Type;
43 "Relative residual tolerance (to initial error).")
45 "Maximum number of outer iterations of the linear solver.");
59 vec_ds(vec_lsize, PETSC_COMM_WORLD),
61 positive_definite(false),
66 VecCreateMPIWithArray(PETSC_COMM_WORLD,1, this->
vec_lsize(), PETSC_DECIDE,
v_rhs, &
rhs);
84 finalize(MAT_FLUSH_ASSEMBLY);
90 ASSERT(0,
"Can not set values. Matrix is not preallocated.\n");
102 finalize(MAT_FLUSH_ASSEMBLY);
108 ASSERT(0,
"Can not set values. Matrix is not preallocated.\n");
114 void LinSys::finalize(MatAssemblyType assembly_type)
117 xprintf(
Warn,
"Finalizing linear system without setting values.\n");
120 MatAssemblyBegin(
matrix, assembly_type);
121 VecAssemblyBegin(
rhs);
122 if (assembly_type == MAT_FINAL_ASSEMBLY)
status=
DONE;
123 MatAssemblyEnd(
matrix, assembly_type);
127 void view(std::ostream output_stream,
int * output_mapping = NULL)
147 void LSView(LinSystem *ls)
152 const PetscInt *cols;
153 const PetscScalar *vals;
159 MatGetInfo(ls->A,MAT_GLOBAL_SUM,&info);
161 if (ls->ds->myp() == 0) {
162 f=
xfopen(
"matrix.dat",
"w");
163 xfprintf(f,
"%d %d 0.0\n",ls->size, ls->size);
168 for(n=0;n<ls->ds->np();n++) {
170 if (n==ls->ds->myp()) {
171 f=
xfopen(
"matrix.dat",
"a");
172 for(i=ls->ds->begin(); i<ls->ds->end();i++) {
173 MatGetRow(ls->A,i,&ncols,&cols,&vals);
175 xfprintf(f,
"%d %d %f\n",ls->old_4_new[i]+1,ls->old_4_new[cols[j]]+1,vals[j]);
176 MatRestoreRow(ls->A,i,&ncols,&cols,&vals);
182 if (ls->ds->myp() == 0) {
184 xfprintf(f,
"yyy = zeros(%d,2)\n yyy=[\n",ls->size);
188 for(n=0; n<ls->ds->np(); n++) {
190 if (n==ls->ds->myp()) {
192 for(i=ls->ds->begin(); i<ls->ds->end(); i++) {
193 xfprintf(f,
"%d %f\n",ls->old_4_new[i]+1,ls->vb[i-ls->ds->begin()]);
199 if (ls->ds->myp() == 0) {
201 xfprintf(f,
"];\n xxx=sortrows(yyy); Vec=xxx(:,2);\n");
209 void MyVecView(Vec v,
int *order,
const char* fname) {
224 xfprintf(f,
"yyy = zeros(%d,2)\n yyy=[\n",ds.size());
228 for(n=0; n<ds.np(); n++) {
231 VecGetArray(v,&array);
233 for(i=ds.begin(); i<ds.end(); i++) {
234 xfprintf(f,
"%d %f\n",order[i]+1,array[i-ds.begin()]);
236 VecRestoreArray(v,&array);
243 xfprintf(f,
"];\n xxx=sortrows(yyy); Vec=xxx(:,2);\n");
257 void LSSetCSR( LinSystem *mtx )
261 const PetscInt *cols;
262 const PetscScalar *vals;
267 MatGetInfo(mtx->A,MAT_LOCAL,&info);
268 nnz=(int)(info.nz_used)+1;
270 if (mtx->i == NULL) mtx->i=(
int *)
xmalloc( (mtx->size+1)*
sizeof(int) );
271 if (mtx->j == NULL) mtx->j=(
int *)
xmalloc( nnz*
sizeof(
int) );
272 if (mtx->a == NULL) mtx->a=(
double *)
xmalloc( nnz*
sizeof(
double) );
273 DBGMSG(
"mtx size: %d nnz: %d\n",mtx->size,nnz);
276 for( row=0; row< mtx->size; row++ ) {
278 MatGetRow(mtx->A,row,&nnz_loc,&cols,&vals);
279 DBGMSG(
"CSR row: %d nnz_loc %d\n",row,nnz_loc);
280 for(i=0; i<nnz_loc; i++) {
281 ASSERT(pos<nnz,
"More nonzeroes then allocated! row: %d entry: %d\n",row,i);
286 MatRestoreRow(mtx->A,row,&nnz_loc,&cols,&vals);
291 void LSFreeCSR( LinSystem *mtx )
318 PetscScalar *on_array, *off_array;
332 VecGetArray(
on_vec,&on_array);
333 VecGetArray(
off_vec,&off_array);
336 on_nz[i]=min((
unsigned int)(on_array[i]+0.1),
vec_ds.
lsize());
337 off_nz[i]=(int)(off_array[i]+0.1);
340 VecRestoreArray(
on_vec,&on_array);
341 VecRestoreArray(
off_vec,&off_array);
347 0, on_nz, 0, off_nz, &
matrix);
350 MatSetOption(
matrix, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_TRUE);
360 for (i=0; i<nrow; i++) {
362 for(j=0; j<ncol; j++) {
365 VecSetValue(
on_vec,row,1.0,ADD_VALUES);
367 VecSetValue(
off_vec,row,1.0,ADD_VALUES);
375 xprintf(
Msg,
"Printing of local matrix is not supported yet for MPIAIJ matrix. \n");
391 :
LinSys(global_row_4_sub_row->get_distr()->lsize(), sol_array), lg_map(global_row_4_sub_row)
399 if (lg_map->get_distr()->size() > numeric_limits<PetscInt>::max())
xprintf(
Err,
"Index range doesn't fit into signed int!");
400 err = ISLocalToGlobalMappingCreate(PETSC_COMM_WORLD,
402 (
const PetscInt*)(&(lg_map->get_map_vector()[0])),
403 PETSC_COPY_VALUES, &map_local_to_global);
405 ASSERT(err == 0,
"Error in ISLocalToGlobalMappingCreate.");
409 loc_rows =
new int[loc_rows_size];
417 ASSERT(0,
"Not implemented");
457 MatSetOption(
matrix, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_TRUE);
464 int i,row, n_loc_rows;
476 ASSERT(err == 0,
"Error in ISGlobalToLocalMappingApply.");
477 ASSERT(nrow == n_loc_rows,
"Not all global indices translated to local indices.");
493 for (i=0; i<n_loc_rows; i++) {
512 ASSERT(err == 0,
"Error in MatView.");
539 ASSERT(err == 0,
"Error in ISLocalToGlobalMappingDestroy.");
554 #ifdef HAVE_ATLAS_ONLY_LAPACK
561 void dgeqrf_(
int m,
int n,
double **A,
double *TAU,
double *work,
int lwork,
int info)