[petsc-users] Rectangular matrix

Jed Brown jedbrown at mcs.anl.gov
Tue Jun 26 18:43:19 CDT 2012


What do you mean by "solve"? You may be able to use LSQR.

On Tue, Jun 26, 2012 at 3:13 PM, Jin, Shuangshuang <
Shuangshuang.Jin at pnnl.gov> wrote:

>  Hello,
>
>         I would like to ask if there’s any special setup for PTESc to
> solve an Ax=b problem where A is a rectangular matrix instead of a square
> matrix. For example, when my A matrix is 3*3, the problem can be solved
> properly. But when my A matrix is 4*3, the error message is:
>
> [0]PETSC ERROR: Arguments are incompatible!
> [0]PETSC ERROR: Incompatible vector local lengths 4 != 3!
>
> PS: I created the matrix in SeqAIJ format and I could view the matrix was
> constructed correctly by MatView.
>
>   // determine number of nonzeros per row in the new matrix
>   PetscMalloc((n+1)*sizeof(PetscInt),&cnt);
>   for (i=0;i<n;i++) {
>     cnt[i]=irow[i+1]-irow[i];
>   }
>   MatCreateSeqAIJ(PETSC_COMM_SELF,n,m,0,cnt,&A);
>   MatSetOption(A,MAT_IGNORE_ZERO_ENTRIES,PETSC_TRUE);
>   // copy over the matrix entries from the inputs
>   for (i=0;i<n;i++) {
>     PetscMalloc(cnt[i]*sizeof(PetscInt),&col);
>     for (j=0;j<cnt[i];j++) {
>       col[j]=icol[irow[i]+j-1]-1;
>     }
>     MatSetValues(A,1,&i,cnt[i],col,&ival[irow[i]-1],INSERT_VALUES);
>   }
>   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
>   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
>   ierr=PetscPrintf(PETSC_COMM_WORLD,"Matrix A:\n");CHKERRQ(ierr);
>   MatView(A,PETSC_VIEWER_STDOUT_SELF);
>
>         I’m new to PETSc. Sorry if my questions is naïve to you. But any
> comment is highly appreciated!
>
> Thanks,
> Shuangshuang
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120626/09a7a58e/attachment-0001.html>


More information about the petsc-users mailing list