[petsc-users] MatGetRow_MPIAIJ error
Jose E. Roman
jroman at dsic.upv.es
Wed Mar 20 04:45:13 CDT 2019
Mat objects in PETSc are parallel, meaning that the data structure is distributed. You should use MatGetOwnershipRange() so that each process accesses its local rows only. https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetOwnershipRange.html
This is very basic usage. You should read the manual and the online documentation including examples, and try hard to solve these issues before asking to the list.
Jose
> El 20 mar 2019, a las 8:52, Eda Oktay via petsc-users <petsc-users at mcs.anl.gov> escribió:
>
> Hello,
>
> I wrote a code computing element wise absolute value of a matrix. When I run the code sequentially, it works. However, when I try to use it in parallel with the same matrix, I get the following error:
>
> [1]PETSC ERROR: Argument out of range
> [1]PETSC ERROR: Only local rows
>
> The absolute value code is:
>
> ierr = MatGetSize(A,&n,NULL);CHKERRQ(ierr);
> ierr = MatDuplicate(A,MAT_COPY_VALUES,AbsA);CHKERRQ(ierr);
>
> for (i=0; i<n; i++) {
> ierr = MatGetRow(A,i,&nc,&aj,&aa);CHKERRQ(ierr);
>
> PetscMalloc1(nc,&absaa);
> for (j=0; j<nc; j++){
> absaa[j] = fabs(aa[j]);
> }
>
> ierr = MatSetValues(*AbsA,1,&i,nc,aj,absaa,INSERT_VALUES);CHKERRQ(ierr);
> ierr = MatRestoreRow(A,i,&nc,&aj,&aa);CHKERRQ(ierr);
> }
>
> I didn't understand how I fix this problem since I am new to PETSc.
>
> Thanks
>
> Eda
More information about the petsc-users
mailing list