<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Yes, but you need to use a KSP that handles rectangular Mat, such as KSPLSQR (-ksp_type lsqr).</div><div class="">PCLU does not handle rectangular Pmat. The only PC that handle rectangular Pmat are PCQR, PCNONE.</div><div class="">If you supply the normal equations as the Pmat for LSQR, then you can use “standard” PC.</div><div class="">You can have a look at <a href="https://petsc.org/main/src/ksp/ksp/tutorials/ex27.c.html" class="">https://petsc.org/main/src/ksp/ksp/tutorials/ex27.c.html</a> that covers most of these cases.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Pierre</div><div class=""><br class=""></div><div class="">(sorry for the earlier answer sent wrongfully to petsc-maint, please discard the previous email)</div><div><br class=""><blockquote type="cite" class=""><div class="">On 21 Sep 2022, at 10:03 AM, fujisan <<a href="mailto:fujisan43@gmail.com" class="">fujisan43@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class="">I'm trying to solve Ax=b with a sparse rectangular matrix A (of size 33x17 in my test) using</div><div dir="ltr" class="">options '<font face="monospace" class="">-ksp_type stcg -pc_type lu</font>' on 1 or 2 cpus.</div><div class=""><br class=""></div><div class="">And I always get an error saying "<font face="monospace" class="">Incompatible vector local lengths</font>" (see below).</div><div class=""><br class=""></div><div class="">Here is the relevant lines of my code:</div><div class=""><div class=""><br class=""></div><div class=""><font face="monospace" class="">program test</font></div><div class=""><font face="monospace" class=""> ...</font></div><div class=""><font face="monospace" class=""> ! Variable declarations</font></div><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><font face="monospace" class=""> PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,ierr))</font></div></div><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><div class=""><font face="monospace" class=""> PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))</font></div><div class=""><font face="monospace" class=""> PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n,ierr))</font></div></div><div class=""><div class=""><font face="monospace" class=""> PetscCall(MatSetType(A,MATMPIAIJ,ierr))</font></div></div><div class=""><div class=""><font face="monospace" class=""> PetscCall(MatSetFromOptions(A,ierr))</font></div><div class=""><font face="monospace" class=""> PetscCall(MatSetUp(A,ierr))</font></div></div><div class=""><div class=""><font face="monospace" class=""> PetscCall(MatGetOwnershipRange(A,istart,iend,ierr))</font></div></div><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><div class=""><font face="monospace" class=""> do irow=istart,iend-1</font></div></div><div class=""><font face="monospace" class=""> ... Reading from file ...</font></div><div class=""><div class=""><font face="monospace" class=""> PetscCall(MatSetValues(A,1,irow,nzv,col,val,ADD_VALUES,ierr))</font></div></div><div class=""><font face="monospace" class=""> ...</font></div><div class=""><div class=""><font face="monospace" class=""> enddo</font></div></div><div class=""><font face="monospace" class=""><br class=""></font></div><div class=""><font face="monospace" class=""><div class=""> PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr))</div><div class=""> PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr))</div><div class=""><div class=""> </div><div class=""> ! Creating vectors x and b</div><div class=""> PetscCallA(MatCreateVecs(A,x,b,ierr))</div></div><div class=""><br class=""></div><div class=""> ! Duplicating x in u.</div><div class=""><div class=""> PetscCallA(VecDuplicate(x,u,ierr))</div></div><div class=""><br class=""></div><div class=""><div class=""> ! u is used to calculate b</div><div class=""> PetscCallA(VecSet(u,1.0,ierr))</div><div class=""><br class=""></div><div class=""> PetscCallA(VecAssemblyBegin(u,ierr))</div><div class=""> PetscCallA(VecAssemblyEnd(u,ierr))</div></div><div class=""><div class=""><div class=""><br class=""></div><div class=""> ! Calculating Au = b</div><div class=""> PetscCallA(MatMult(A,u,b,ierr)) ! A.u = b</div></div><div class=""><br class=""></div><div class=""> PetscCallA(KSPSetType(ksp,KSPCG,ierr))</div></div><div class=""><div class=""><br class=""></div><div class=""> PetscCallA(KSPSetOperators(ksp,A,A,ierr))</div></div><div class=""><div class=""><br class=""></div><div class=""> PetscCallA(KSPSetFromOptions(ksp,ierr))</div></div><div class=""><div class=""><br class=""></div><div class=""> ! Solving Ax = b, x unknown</div><div class=""> PetscCallA(KSPSolve(ksp,b,x,ierr))</div></div><div class=""><div class=""><br class=""></div><div class=""> PetscCallA(VecDestroy(x,ierr))</div><div class=""> PetscCallA(VecDestroy(u,ierr))</div><div class=""> PetscCallA(VecDestroy(b,ierr))</div><div class=""> PetscCallA(MatDestroy(A,ierr))</div><div class=""> PetscCallA(KSPDestroy(ksp,ierr))</div></div><div class=""><div class=""><br class=""></div><div class=""> call PetscFinalize(ierr)</div></div><div class="">end program</div></font></div><div dir="ltr" class=""><br class=""></div><div dir="ltr" class="">The code reads a sparse matrix from a binary file.<br class=""><div class="">I also output the sizes of matrix A and vectors b, x, u.</div><div class="">They all seem consistent.</div><div class=""><br class=""></div><div class="">What am I doing wrong?</div><div class="">Is it possible to solve Ax=b with A rectangular?</div><div class=""><br class=""></div><div class="">Thank you in advance for your help.</div><div class="">Have a nice day.</div><div class=""><br class=""></div><div class="">Fuji</div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace" class=""> Matrix size : m= 33 n= 17 cpu size: 1</font></div><div class=""><span style="font-family:monospace" class=""> Size of matrix A : 33 17</span><br class=""></div><div class=""><font face="monospace" class=""> Size of vector b : 33</font></div><div class=""><font face="monospace" class=""> Size of vector x : 17</font></div><div class=""><span style="font-family:monospace" class=""> Size of vector u : 17</span><br class=""></div><div class=""><span style="font-family:monospace" class="">[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------</span><br class=""></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: Arguments are incompatible</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: Incompatible vector local lengths parameter # 1 local size 33 != parameter # 2 local size 17</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: See <a href="https://petsc.org/release/faq/" class="">https://petsc.org/release/faq/</a> for trouble shooting.</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: Petsc Development GIT revision: v3.17.4-1341-g91b2b62a00 GIT Date: 2022-09-15 19:26:07 +0000</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: ./bin/solve on a x86_64 named master by fujisan Tue Sep 20 16:56:37 2022</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: Configure options --with-petsc-arch=x86_64 --COPTFLAGS="-g -O3" --FOPTFLAGS="-g -O3" --CXXOPTFLAGS="-g -O3" --with-debugging=0 --with-cc=mpiicc --with-cxx=mpiicpc --with-fc=mpiifort --with-single-library=1 --with-mpiexec=mpiexec --with-precision=double --with-fortran-interfaces=1 --with-make=1 --with-mpi=1 --with-mpi-compilers=1 --download-fblaslapack=0 --download-hypre=1 --download-cmake=0 --with-cmake=1 --download-metis=1 --download-parmetis=1 --download-ptscotch=0 --download-suitesparse=1 --download-triangle=1 --download-superlu=1 --download-superlu_dist=1 --download-scalapack=1 --download-mumps=1 --download-elemental=1 --download-spai=0 --download-parms=1 --download-moab=1 --download-chaco=0 --download-fftw=1 --with-petsc4py=1 --download-mpi4py=1 --download-saws --download-concurrencykit=1 --download-revolve=1 --download-cams=1 --download-p4est=0 --with-zlib=1 --download-mfem=1 --download-glvis=0 --with-opengl=0 --download-libpng=1 --download-libjpeg=1 --download-slepc=1 --download-hpddm=1 --download-bamg=1 --download-mmg=0 --download-parmmg=0 --download-htool=1 --download-egads=0 --download-opencascade=0 PETSC_ARCH=x86_64</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: #1 VecCopy() at /data/softs/petsc/src/vec/vec/interface/vector.c:1607</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: #2 KSPSolve_BiCG() at /data/softs/petsc/src/ksp/ksp/impls/bicg/bicg.c:40</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: #3 KSPSolve_Private() at /data/softs/petsc/src/ksp/ksp/interface/itfunc.c:877</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: #4 KSPSolve() at /data/softs/petsc/src/ksp/ksp/interface/itfunc.c:1048</font></div><div class=""><font face="monospace" class="">[0]PETSC ERROR: #5 solve.F90:218</font></div><div class=""><font face="monospace" class="">Abort(75) on node 0 (rank 0 in comm 16): application called MPI_Abort(MPI_COMM_SELF, 75) - process 0</font></div></div><div class=""><br class=""></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div></blockquote></div><br class=""></body></html>