[petsc-users] Rectangular matrix
Jin, Shuangshuang
Shuangshuang.Jin at pnnl.gov
Tue Jun 26 18:13:50 CDT 2012
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/9e7c7b8a/attachment.html>
More information about the petsc-users
mailing list