Re: [petsc-users] Initializing a large sparse matrix

2022-10-17 Thread fujisan
Can I preallocate space for a rectangular matrix using MatCreateAIJ() in
parallel?
It is not clear to me how I have to define d_nnz when the matrix is
rectangular?

X * * * *
* X * * *
* * X * *
* * * X *
* * * * X
* * * * *
* * * * *

The example shown is for an 8x8 matrix on 3 cpu
X * *
* X *
* * X

On Mon, Oct 17, 2022 at 9:02 AM Jose E. Roman  wrote:

> You have to preallocate, see
> https://petsc.org/release/docs/manual/mat/#sec-matsparse
>
> > El 17 oct 2022, a las 8:37, fujisan  escribió:
> >
> > Hi everyone,
> >
> > I initialize a large sparse matrix (5x2) using MatCreate() and
> then filling it with MatSetValues() line by line
> > but it takes a bit more than an hour on 80 cores to fill in the matrix.
> >
> > Is there a way to optimize this initialization?
> >
> > Fuji
>
>


[petsc-users] Initializing a large sparse matrix

2022-10-16 Thread fujisan
Hi everyone,

I initialize a large sparse matrix (5x2) using MatCreate() and then
filling it with MatSetValues() line by line
but it takes a bit more than an hour on 80 cores to fill in the matrix.

Is there a way to optimize this initialization?

Fuji


Re: [petsc-users] Problem reading and HDF5 binary file

2022-10-04 Thread fujisan
I see from https://petsc.org/main/docs/manualpages/Mat/MatLoad/ that
MatView for HDF5 binary format is not yet implemented.
Any idea when this will be implemented?

F.
Current HDF5 (MAT-File) limitations
<https://petsc.org/main/docs/manualpages/Mat/MatLoad/#current-hdf5-mat-file-limitations>

This reader currently supports only real MATSEQAIJ, MATMPIAIJ, MATSEQDENSE
 and MATMPIDENSE matrices.

Corresponding MatView() is not yet implemented.

The loaded matrix is actually a transpose of the original one in MATLAB,
unless you push PETSC_VIEWER_HDF5_MAT format (see examples above). With
this format, matrix is automatically transposed by PETSc, unless the matrix
is marked as SPD or symmetric (see MatSetOption(), MAT_SPD, MAT_SYMMETRIC).

On Tue, Oct 4, 2022 at 9:42 AM fujisan  wrote:

> It turns out there is nothing in the hdf5 file:
>
> $ h5dump data/matrix3.mat.h5
> HDF5 "data/matrix3.mat.h5" {
> GROUP "/" {
> }
> }
>
>
> On Tue, Oct 4, 2022 at 9:19 AM fujisan  wrote:
>
>> Hi everyone,
>>
>> I have written a matrix in an HDF5 binary file without problem using
>> PetscViewerHDF5Open function like this:
>>
>> ! Write
>> if (ishdf5) then
>> PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD,trim(filename
>> ),FILE_MODE_WRITE,view,ierr))
>> else
>> PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,trim(filename
>> ),FILE_MODE_WRITE,view,ierr))
>> endif
>> PetscCall(MatView(A,view,ierr))
>> PetscCall(PetscViewerDestroy(view,ierr))
>>
>> But when I want to read that HDF5 file like this:
>>
>> ! Read
>> if (ishdf5) then
>> PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD,trim(filename
>> ),FILE_MODE_READ,view,ierr))
>> else
>> PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,trim(filename
>> ),FILE_MODE_READ,view,ierr))
>> endif
>> PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))
>> PetscCall(MatSetType(A,MATMPIAIJ,ierr))
>> PetscCall(MatLoad(A,view,ierr))
>> PetscCall(PetscViewerDestroy(view,ierr))
>>
>> I get this kind of error message below.
>> I don't have any problem writing / reading using PetscViewerBinaryOpen,
>> and no problem writing / reading a vector using PetscViewerHDF5Open either.
>>
>> What am I missing ?
>>
>> Fuji
>>
>> [0]PETSC ERROR: - Error Message
>> --
>> [0]PETSC ERROR: Unexpected data in file
>> [0]PETSC ERROR: Attribute /Mat_0xc416_0/MATLAB_sparse does not exist
>> and default value not provided
>> [0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
>> [0]PETSC ERROR: Petsc Release Version 3.18.0, unknown
>> [0]PETSC ERROR: ./bin/solve on a x86_64 named master by beauduin Tue Oct
>> 4 08:55:55 2022
>> [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 --with-hdf5=1 --download-hdf5=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
>> [0]PETSC ERROR: #1 PetscViewerHDF5ReadAttribute() at
>> /data/softs/petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c:1245
>> [0]PETSC ERROR: #2 MatLoad_AIJ_HDF5() at
>> /data/softs/petsc/src/mat/impls/aij/seq/aijhdf5.c:63
>> [0]PETSC ERROR: #3 MatLoad_MPIAIJ() at
>> /data/softs/petsc/src/mat/impls/aij/mpi/mpiaij.c:3034
>> [0]PETSC ERROR: #4 MatLoad() at
>> /data/softs/petsc/src/mat/interface/matrix.c:1304
>> [0]PETSC ERROR: #5 bigmat.F90:62
>> [0]PETSC ERROR: #6 MatCreateVecs() at
>> /data/softs/petsc/src/mat/interface/matrix.c:9336
>> [0]PETSC ERROR: #7 solve.F90:143
>> Abort(73) on node 0 (rank 0 in comm 16): application called
>> MPI_Abort(MPI_COMM_SELF, 73) - process 0
>> forrtl: severe (174): SIGSEGV, segmentation fault occurred
>> Image  PCRoutineLine
>> Source
>> solve  0043258A  Unknown   Unknown
>> Unknown
>> libpthread-2.28.s  7FCAF0B78C20  Unknown   Unknown
>> Unknown
>> libmpi.so.12.0.0   7FCAF17A09D3  Unknown   Unknown
>> Unknown
>> 
>>
>


Re: [petsc-users] Problem reading and HDF5 binary file

2022-10-04 Thread fujisan
It turns out there is nothing in the hdf5 file:

$ h5dump data/matrix3.mat.h5
HDF5 "data/matrix3.mat.h5" {
GROUP "/" {
}
}


On Tue, Oct 4, 2022 at 9:19 AM fujisan  wrote:

> Hi everyone,
>
> I have written a matrix in an HDF5 binary file without problem using
> PetscViewerHDF5Open function like this:
>
> ! Write
> if (ishdf5) then
> PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD,trim(filename
> ),FILE_MODE_WRITE,view,ierr))
> else
> PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,trim(filename
> ),FILE_MODE_WRITE,view,ierr))
> endif
> PetscCall(MatView(A,view,ierr))
> PetscCall(PetscViewerDestroy(view,ierr))
>
> But when I want to read that HDF5 file like this:
>
> ! Read
> if (ishdf5) then
> PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD,trim(filename
> ),FILE_MODE_READ,view,ierr))
> else
> PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,trim(filename
> ),FILE_MODE_READ,view,ierr))
> endif
> PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))
> PetscCall(MatSetType(A,MATMPIAIJ,ierr))
> PetscCall(MatLoad(A,view,ierr))
> PetscCall(PetscViewerDestroy(view,ierr))
>
> I get this kind of error message below.
> I don't have any problem writing / reading using PetscViewerBinaryOpen,
> and no problem writing / reading a vector using PetscViewerHDF5Open either.
>
> What am I missing ?
>
> Fuji
>
> [0]PETSC ERROR: - Error Message
> --
> [0]PETSC ERROR: Unexpected data in file
> [0]PETSC ERROR: Attribute /Mat_0xc416_0/MATLAB_sparse does not exist
> and default value not provided
> [0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
> [0]PETSC ERROR: Petsc Release Version 3.18.0, unknown
> [0]PETSC ERROR: ./bin/solve on a x86_64 named master by beauduin Tue Oct
> 4 08:55:55 2022
> [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 --with-hdf5=1 --download-hdf5=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
> [0]PETSC ERROR: #1 PetscViewerHDF5ReadAttribute() at
> /data/softs/petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c:1245
> [0]PETSC ERROR: #2 MatLoad_AIJ_HDF5() at
> /data/softs/petsc/src/mat/impls/aij/seq/aijhdf5.c:63
> [0]PETSC ERROR: #3 MatLoad_MPIAIJ() at
> /data/softs/petsc/src/mat/impls/aij/mpi/mpiaij.c:3034
> [0]PETSC ERROR: #4 MatLoad() at
> /data/softs/petsc/src/mat/interface/matrix.c:1304
> [0]PETSC ERROR: #5 bigmat.F90:62
> [0]PETSC ERROR: #6 MatCreateVecs() at
> /data/softs/petsc/src/mat/interface/matrix.c:9336
> [0]PETSC ERROR: #7 solve.F90:143
> Abort(73) on node 0 (rank 0 in comm 16): application called
> MPI_Abort(MPI_COMM_SELF, 73) - process 0
> forrtl: severe (174): SIGSEGV, segmentation fault occurred
> Image  PCRoutineLine
> Source
> solve  0043258A  Unknown   Unknown  Unknown
> libpthread-2.28.s  7FCAF0B78C20  Unknown   Unknown  Unknown
> libmpi.so.12.0.0   7FCAF17A09D3  Unknown   Unknown  Unknown
> 
>


[petsc-users] Problem reading and HDF5 binary file

2022-10-04 Thread fujisan
Hi everyone,

I have written a matrix in an HDF5 binary file without problem using
PetscViewerHDF5Open function like this:

! Write
if (ishdf5) then
PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD,trim(filename
),FILE_MODE_WRITE,view,ierr))
else
PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,trim(filename
),FILE_MODE_WRITE,view,ierr))
endif
PetscCall(MatView(A,view,ierr))
PetscCall(PetscViewerDestroy(view,ierr))

But when I want to read that HDF5 file like this:

! Read
if (ishdf5) then
PetscCall(PetscViewerHDF5Open(PETSC_COMM_WORLD,trim(filename
),FILE_MODE_READ,view,ierr))
else
PetscCall(PetscViewerBinaryOpen(PETSC_COMM_WORLD,trim(filename
),FILE_MODE_READ,view,ierr))
endif
PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))
PetscCall(MatSetType(A,MATMPIAIJ,ierr))
PetscCall(MatLoad(A,view,ierr))
PetscCall(PetscViewerDestroy(view,ierr))

I get this kind of error message below.
I don't have any problem writing / reading using PetscViewerBinaryOpen, and
no problem writing / reading a vector using PetscViewerHDF5Open either.

What am I missing ?

Fuji

[0]PETSC ERROR: - Error Message
--
[0]PETSC ERROR: Unexpected data in file
[0]PETSC ERROR: Attribute /Mat_0xc416_0/MATLAB_sparse does not exist
and default value not provided
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.18.0, unknown
[0]PETSC ERROR: ./bin/solve on a x86_64 named master by beauduin Tue Oct  4
08:55:55 2022
[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 --with-hdf5=1 --download-hdf5=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
[0]PETSC ERROR: #1 PetscViewerHDF5ReadAttribute() at
/data/softs/petsc/src/sys/classes/viewer/impls/hdf5/hdf5v.c:1245
[0]PETSC ERROR: #2 MatLoad_AIJ_HDF5() at
/data/softs/petsc/src/mat/impls/aij/seq/aijhdf5.c:63
[0]PETSC ERROR: #3 MatLoad_MPIAIJ() at
/data/softs/petsc/src/mat/impls/aij/mpi/mpiaij.c:3034
[0]PETSC ERROR: #4 MatLoad() at
/data/softs/petsc/src/mat/interface/matrix.c:1304
[0]PETSC ERROR: #5 bigmat.F90:62
[0]PETSC ERROR: #6 MatCreateVecs() at
/data/softs/petsc/src/mat/interface/matrix.c:9336
[0]PETSC ERROR: #7 solve.F90:143
Abort(73) on node 0 (rank 0 in comm 16): application called
MPI_Abort(MPI_COMM_SELF, 73) - process 0
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image  PCRoutineLineSource

solve  0043258A  Unknown   Unknown  Unknown
libpthread-2.28.s  7FCAF0B78C20  Unknown   Unknown  Unknown
libmpi.so.12.0.0   7FCAF17A09D3  Unknown   Unknown  Unknown



Re: [petsc-users] Differences between main and release branches?

2022-10-03 Thread fujisan
I probably did:

git clone -b release https://gitlab.com/petsc/petsc.git petsc

like the documentation says. But I found out that I was in branch main.
Cloning 3.17.4 is an abuse of language. I ment cloning petsc when that
release was 3.17.4.

Anyway I git pulled this morning and checked out branch release.

Fuji



On Mon, Oct 3, 2022 at 5:29 PM Satish Balay  wrote:

> What were the git commands used here [for each of these cases]?
>
> Normally you would checkout a branch - and pull on it. So "cloning 3.17.4"
> doesn't really make sense - as there is no "3.17.4" branch.
>
> you ether checkout a tag - v3.17.4 - then you don't get a branch to pull
> on. [sure you can do "git clone -b release" - but that's a branch].
>
> So the statement "3.17.4 gave main branch, 3.18.0 gave release branch"
> doesn't really make sense to me [from the way git work]
>
> Satish
>
> On Mon, 3 Oct 2022, Jose E. Roman wrote:
>
> > 'main' is the development version, 'release' is the latest release
> version.
> > You can select the branch when cloning or later with git checkout.
> > See https://petsc.org/release/install/download/#recommended-download
> >
> > Jose
> >
> >
> > > El 3 oct 2022, a las 11:08, fujisan  escribió:
> > >
> > > Hi everyone,
> > > What are the differences between the 'main' and 'release' branches?
> > >
> > > Where I git cloned version 3.17.4, I was by default in the 'main'
> branch.
> > > Where I git cloned version 3.18.0 (I haven't git pulled from 3.17.4
> yet), I was by default in the 'release' branch.
> > >
> > > Fuji
> >
>


[petsc-users] Differences between main and release branches?

2022-10-03 Thread fujisan
Hi everyone,
What are the differences between the 'main' and 'release' branches?

Where I git cloned version 3.17.4, I was by default in the 'main' branch.
Where I git cloned version 3.18.0 (I haven't git pulled from 3.17.4 yet), I
was by default in the 'release' branch.

Fuji


Re: [petsc-users] Problem solving Ax=b with rectangular matrix A

2022-09-26 Thread fujisan
Ok, Thank you.
I didn't know about MatCreateNormal.

In terms of computer performance, what is best to solve Ax=b with A
rectangular?
Is it to keep A rectangular and use KSPLSQR along with PCNONE or
to convert to normal equations using MatCreateNormal and use another ksp
type with another pc type?

In the future, our A will be very sparse and will be something like up to
100 millions lines and 10 millions columns in size.

I will study all that.

Fuji

On Mon, Sep 26, 2022 at 11:45 AM Pierre Jolivet  wrote:

> I’m sorry, solving overdetermined systems, alongside (overlapping) domain
> decomposition preconditioners and solving systems with multiple right-hand
> sides, is one of the topic for which I need to stop pushing new features
> and update the users manual instead…
> The very basic documentation of PCQR is here:
> https://petsc.org/main/docs/manualpages/PC/PCQR (I’m guessing you are
> using the release documentation in which it’s indeed not present).
> Some comments about your problem of solving Ax=b with a rectangular matrix
> A.
> 1) if you switch to KSPLSQR, it is wrong to use KSPSetOperators(ksp, A, A).
> You can get away with murder if your PCType is PCNONE, but otherwise, you
> should always supply the normal equations as the Pmat (you will get runtime
> errors otherwise).
> To get the normal equations, you can use
> https://petsc.org/main/docs/manualpages/Mat/MatCreateNormal/
> The following two points only applies if your Pmat is sparse (or sparse
> with some dense rows).
> 2) there are a couple of PC that handle MATNORMAL: PCNONE, PCQR, PCJACOBI,
> PCBJACOBI, PCASM, PCHPDDM
> Currently, PCQR needs SuiteSparse, and thus runs only if the Pmat is
> distributed on a single MPI process (if your Pmat is distributed on
> multiple processes, you should first use PCREDUNDANT).
> 3) if you intend to make your problem scale in sizes, most of these
> preconditioners will not be very robust.
> In that case, if your problem does not have any dense rows, you should
> either use PCHPDDM or MatConvert(Pmat, MATAIJ, PmatAIJ) and then use
> PCCHOLESKY, PCHYPRE or PCGAMG (you can have a look at
> https://epubs.siam.org/doi/abs/10.1137/21M1434891 for a comparison)
> If your problem has dense rows, I have somewhere the code to recast it
> into an augmented system then solved using PCFIELDSPLIT (see
> https://link.springer.com/article/10.1007/s11075-018-0478-2). I can send
> it to you if needed.
> Let me know if I can be of further assistance or if something is not clear
> to you.
>
> Thanks,
> Pierre
>
> On 26 Sep 2022, at 10:56 AM, fujisan  wrote:
>
> OK thank you.
>
> On Mon, Sep 26, 2022 at 10:53 AM Jose E. Roman  wrote:
>
>> The QR factorization from SuiteSparse is sequential only, cannot be used
>> in parallel.
>> In parallel you can try PCBJACOBI with a PCQR local preconditioner.
>> Pierre may have additional suggestions.
>>
>> Jose
>>
>>
>> > El 26 sept 2022, a las 10:47, fujisan  escribió:
>> >
>> > I did configure Petsc with the option --download-suitesparse.
>> >
>> > The error is more like this:
>> > PETSC ERROR: Could not locate a solver type for factorization type QR
>> and matrix type mpiaij.
>> >
>> > Fuji
>> >
>> > On Mon, Sep 26, 2022 at 10:25 AM Jose E. Roman 
>> wrote:
>> > If the error message is "Could not locate a solver type for
>> factorization type QR" then you should configure PETSc with
>> --download-suitesparse
>> >
>> > Jose
>> >
>> >
>> > > El 26 sept 2022, a las 9:06, fujisan  escribió:
>> > >
>> > > Thank you Pierre,
>> > >
>> > > I used PCNONE along with KSPLSQR and it worked.
>> > > But as for PCQR, it cannot be found. There is nothing about it in the
>> documentation as well.
>> > >
>> > > Fuji
>> > >
>> > > On Wed, Sep 21, 2022 at 12:20 PM Pierre Jolivet 
>> wrote:
>> > > Yes, but you need to use a KSP that handles rectangular Mat, such as
>> KSPLSQR (-ksp_type lsqr).
>> > > PCLU does not handle rectangular Pmat. The only PC that handle
>> rectangular Pmat are PCQR, PCNONE.
>> > > If you supply the normal equations as the Pmat for LSQR, then you can
>> use “standard” PC.
>> > > You can have a look at
>> https://petsc.org/main/src/ksp/ksp/tutorials/ex27.c.html that covers
>> most of these cases.
>> > >
>> > > Thanks,
>> > > Pierre
>> > >
>> > > (sorry for the earlier answer sent wrongfully to petsc-maint, please
>> discard the previous email)
>> > &g

Re: [petsc-users] Problem solving Ax=b with rectangular matrix A

2022-09-26 Thread fujisan
OK thank you.

On Mon, Sep 26, 2022 at 10:53 AM Jose E. Roman  wrote:

> The QR factorization from SuiteSparse is sequential only, cannot be used
> in parallel.
> In parallel you can try PCBJACOBI with a PCQR local preconditioner.
> Pierre may have additional suggestions.
>
> Jose
>
>
> > El 26 sept 2022, a las 10:47, fujisan  escribió:
> >
> > I did configure Petsc with the option --download-suitesparse.
> >
> > The error is more like this:
> > PETSC ERROR: Could not locate a solver type for factorization type QR
> and matrix type mpiaij.
> >
> > Fuji
> >
> > On Mon, Sep 26, 2022 at 10:25 AM Jose E. Roman 
> wrote:
> > If the error message is "Could not locate a solver type for
> factorization type QR" then you should configure PETSc with
> --download-suitesparse
> >
> > Jose
> >
> >
> > > El 26 sept 2022, a las 9:06, fujisan  escribió:
> > >
> > > Thank you Pierre,
> > >
> > > I used PCNONE along with KSPLSQR and it worked.
> > > But as for PCQR, it cannot be found. There is nothing about it in the
> documentation as well.
> > >
> > > Fuji
> > >
> > > On Wed, Sep 21, 2022 at 12:20 PM Pierre Jolivet 
> wrote:
> > > Yes, but you need to use a KSP that handles rectangular Mat, such as
> KSPLSQR (-ksp_type lsqr).
> > > PCLU does not handle rectangular Pmat. The only PC that handle
> rectangular Pmat are PCQR, PCNONE.
> > > If you supply the normal equations as the Pmat for LSQR, then you can
> use “standard” PC.
> > > You can have a look at
> https://petsc.org/main/src/ksp/ksp/tutorials/ex27.c.html that covers most
> of these cases.
> > >
> > > Thanks,
> > > Pierre
> > >
> > > (sorry for the earlier answer sent wrongfully to petsc-maint, please
> discard the previous email)
> > >
> > >> On 21 Sep 2022, at 10:03 AM, fujisan  wrote:
> > >>
> > >> I'm trying to solve Ax=b with a sparse rectangular matrix A (of size
> 33x17 in my test) using
> > >> options '-ksp_type stcg -pc_type lu' on 1 or 2 cpus.
> > >>
> > >> And I always get an error saying "Incompatible vector local lengths"
> (see below).
> > >>
> > >> Here is the relevant lines of my code:
> > >>
> > >> program test
> > >> ...
> > >> ! Variable declarations
> > >>
> > >> PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,ierr))
> > >>
> > >> PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))
> > >> PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n,ierr))
> > >> PetscCall(MatSetType(A,MATMPIAIJ,ierr))
> > >> PetscCall(MatSetFromOptions(A,ierr))
> > >> PetscCall(MatSetUp(A,ierr))
> > >> PetscCall(MatGetOwnershipRange(A,istart,iend,ierr))
> > >>
> > >> do irow=istart,iend-1
> > >> ... Reading from file ...
> > >> PetscCall(MatSetValues(A,1,irow,nzv,col,val,ADD_VALUES,ierr))
> > >> ...
> > >> enddo
> > >>
> > >> PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr))
> > >> PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr))
> > >>
> > >> ! Creating vectors x and b
> > >> PetscCallA(MatCreateVecs(A,x,b,ierr))
> > >>
> > >> ! Duplicating x in u.
> > >> PetscCallA(VecDuplicate(x,u,ierr))
> > >>
> > >> ! u is used to calculate b
> > >> PetscCallA(VecSet(u,1.0,ierr))
> > >>
> > >> PetscCallA(VecAssemblyBegin(u,ierr))
> > >> PetscCallA(VecAssemblyEnd(u,ierr))
> > >>
> > >> ! Calculating Au = b
> > >> PetscCallA(MatMult(A,u,b,ierr)) ! A.u = b
> > >>
> > >> PetscCallA(KSPSetType(ksp,KSPCG,ierr))
> > >>
> > >> PetscCallA(KSPSetOperators(ksp,A,A,ierr))
> > >>
> > >> PetscCallA(KSPSetFromOptions(ksp,ierr))
> > >>
> > >> ! Solving Ax = b, x unknown
> > >> PetscCallA(KSPSolve(ksp,b,x,ierr))
> > >>
> > >> PetscCallA(VecDestroy(x,ierr))
> > >> PetscCallA(VecDestroy(u,ierr))
> > >> PetscCallA(VecDestroy(b,ierr))
> > >> PetscCallA(MatDestroy(A,ierr))
> > >> PetscCallA(KSPDestroy(ksp,ierr))
> > >>
> > >> call PetscFinalize(i

Re: [petsc-users] Problem solving Ax=b with rectangular matrix A

2022-09-26 Thread fujisan
I did configure Petsc with the option --download-suitesparse.

The error is more like this:
PETSC ERROR: Could not locate a solver type for factorization type QR and
matrix type mpiaij.

Fuji

On Mon, Sep 26, 2022 at 10:25 AM Jose E. Roman  wrote:

> If the error message is "Could not locate a solver type for factorization
> type QR" then you should configure PETSc with --download-suitesparse
>
> Jose
>
>
> > El 26 sept 2022, a las 9:06, fujisan  escribió:
> >
> > Thank you Pierre,
> >
> > I used PCNONE along with KSPLSQR and it worked.
> > But as for PCQR, it cannot be found. There is nothing about it in the
> documentation as well.
> >
> > Fuji
> >
> > On Wed, Sep 21, 2022 at 12:20 PM Pierre Jolivet  wrote:
> > Yes, but you need to use a KSP that handles rectangular Mat, such as
> KSPLSQR (-ksp_type lsqr).
> > PCLU does not handle rectangular Pmat. The only PC that handle
> rectangular Pmat are PCQR, PCNONE.
> > If you supply the normal equations as the Pmat for LSQR, then you can
> use “standard” PC.
> > You can have a look at
> https://petsc.org/main/src/ksp/ksp/tutorials/ex27.c.html that covers most
> of these cases.
> >
> > Thanks,
> > Pierre
> >
> > (sorry for the earlier answer sent wrongfully to petsc-maint, please
> discard the previous email)
> >
> >> On 21 Sep 2022, at 10:03 AM, fujisan  wrote:
> >>
> >> I'm trying to solve Ax=b with a sparse rectangular matrix A (of size
> 33x17 in my test) using
> >> options '-ksp_type stcg -pc_type lu' on 1 or 2 cpus.
> >>
> >> And I always get an error saying "Incompatible vector local lengths"
> (see below).
> >>
> >> Here is the relevant lines of my code:
> >>
> >> program test
> >> ...
> >> ! Variable declarations
> >>
> >> PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,ierr))
> >>
> >> PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))
> >> PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n,ierr))
> >> PetscCall(MatSetType(A,MATMPIAIJ,ierr))
> >> PetscCall(MatSetFromOptions(A,ierr))
> >> PetscCall(MatSetUp(A,ierr))
> >> PetscCall(MatGetOwnershipRange(A,istart,iend,ierr))
> >>
> >> do irow=istart,iend-1
> >> ... Reading from file ...
> >> PetscCall(MatSetValues(A,1,irow,nzv,col,val,ADD_VALUES,ierr))
> >> ...
> >> enddo
> >>
> >> PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr))
> >> PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr))
> >>
> >> ! Creating vectors x and b
> >> PetscCallA(MatCreateVecs(A,x,b,ierr))
> >>
> >> ! Duplicating x in u.
> >> PetscCallA(VecDuplicate(x,u,ierr))
> >>
> >> ! u is used to calculate b
> >> PetscCallA(VecSet(u,1.0,ierr))
> >>
> >> PetscCallA(VecAssemblyBegin(u,ierr))
> >> PetscCallA(VecAssemblyEnd(u,ierr))
> >>
> >> ! Calculating Au = b
> >> PetscCallA(MatMult(A,u,b,ierr)) ! A.u = b
> >>
> >> PetscCallA(KSPSetType(ksp,KSPCG,ierr))
> >>
> >> PetscCallA(KSPSetOperators(ksp,A,A,ierr))
> >>
> >> PetscCallA(KSPSetFromOptions(ksp,ierr))
> >>
> >> ! Solving Ax = b, x unknown
> >> PetscCallA(KSPSolve(ksp,b,x,ierr))
> >>
> >> PetscCallA(VecDestroy(x,ierr))
> >> PetscCallA(VecDestroy(u,ierr))
> >> PetscCallA(VecDestroy(b,ierr))
> >> PetscCallA(MatDestroy(A,ierr))
> >> PetscCallA(KSPDestroy(ksp,ierr))
> >>
> >> call PetscFinalize(ierr)
> >> end program
> >>
> >> The code reads a sparse matrix from a binary file.
> >> I also output the sizes of matrix A and vectors b, x, u.
> >> They all seem consistent.
> >>
> >> What am I doing wrong?
> >> Is it possible to solve Ax=b with A rectangular?
> >>
> >> Thank you in advance for your help.
> >> Have a nice day.
> >>
> >> Fuji
> >>
> >>  Matrix size : m=  33  n=  17  cpu size:1
> >>  Size of matrix A  :   33  17
> >>  Size of vector b :   33
> >>  Size of vector x :   17
> >>  Size of vector u :   17
> >> [0]PETSC ERROR: - Error Message
> --
> >&g

Re: [petsc-users] Problem solving Ax=b with rectangular matrix A

2022-09-26 Thread fujisan
Thank you Pierre,

I used PCNONE along with KSPLSQR and it worked.
But as for PCQR, it cannot be found. There is nothing about it in the
documentation as well.

Fuji

On Wed, Sep 21, 2022 at 12:20 PM Pierre Jolivet  wrote:

> Yes, but you need to use a KSP that handles rectangular Mat, such as
> KSPLSQR (-ksp_type lsqr).
> PCLU does not handle rectangular Pmat. The only PC that handle rectangular
> Pmat are PCQR, PCNONE.
> If you supply the normal equations as the Pmat for LSQR, then you can use
> “standard” PC.
> You can have a look at
> https://petsc.org/main/src/ksp/ksp/tutorials/ex27.c.html that covers most
> of these cases.
>
> Thanks,
> Pierre
>
> (sorry for the earlier answer sent wrongfully to petsc-maint, please
> discard the previous email)
>
> On 21 Sep 2022, at 10:03 AM, fujisan  wrote:
>
> I'm trying to solve Ax=b with a sparse rectangular matrix A (of size 33x17
> in my test) using
> options '-ksp_type stcg -pc_type lu' on 1 or 2 cpus.
>
> And I always get an error saying "Incompatible vector local lengths" (see
> below).
>
> Here is the relevant lines of my code:
>
> program test
> ...
> ! Variable declarations
>
> PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,ierr))
>
> PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))
> PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n,ierr))
> PetscCall(MatSetType(A,MATMPIAIJ,ierr))
> PetscCall(MatSetFromOptions(A,ierr))
> PetscCall(MatSetUp(A,ierr))
> PetscCall(MatGetOwnershipRange(A,istart,iend,ierr))
>
> do irow=istart,iend-1
> ... Reading from file ...
> PetscCall(MatSetValues(A,1,irow,nzv,col,val,ADD_VALUES,ierr))
> ...
> enddo
>
> PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr))
> PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr))
>
> ! Creating vectors x and b
> PetscCallA(MatCreateVecs(A,x,b,ierr))
>
> ! Duplicating x in u.
> PetscCallA(VecDuplicate(x,u,ierr))
>
> ! u is used to calculate b
> PetscCallA(VecSet(u,1.0,ierr))
>
> PetscCallA(VecAssemblyBegin(u,ierr))
> PetscCallA(VecAssemblyEnd(u,ierr))
>
> ! Calculating Au = b
> PetscCallA(MatMult(A,u,b,ierr)) ! A.u = b
>
> PetscCallA(KSPSetType(ksp,KSPCG,ierr))
>
> PetscCallA(KSPSetOperators(ksp,A,A,ierr))
>
> PetscCallA(KSPSetFromOptions(ksp,ierr))
>
> ! Solving Ax = b, x unknown
> PetscCallA(KSPSolve(ksp,b,x,ierr))
>
> PetscCallA(VecDestroy(x,ierr))
> PetscCallA(VecDestroy(u,ierr))
> PetscCallA(VecDestroy(b,ierr))
> PetscCallA(MatDestroy(A,ierr))
> PetscCallA(KSPDestroy(ksp,ierr))
>
> call PetscFinalize(ierr)
> end program
>
> The code reads a sparse matrix from a binary file.
> I also output the sizes of matrix A and vectors b, x, u.
> They all seem consistent.
>
> What am I doing wrong?
> Is it possible to solve Ax=b with A rectangular?
>
> Thank you in advance for your help.
> Have a nice day.
>
> Fuji
>
>  Matrix size : m=  33  n=  17  cpu size:1
>  Size of matrix A  :   33  17
>  Size of vector b :   33
>  Size of vector x :   17
>  Size of vector u :   17
> [0]PETSC ERROR: - Error Message
> --
> [0]PETSC ERROR: Arguments are incompatible
> [0]PETSC ERROR: Incompatible vector local lengths parameter # 1 local size
> 33 != parameter # 2 local size 17
> [0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
> [0]PETSC ERROR: Petsc Development GIT revision: v3.17.4-1341-g91b2b62a00
> GIT Date: 2022-09-15 19:26:07 +
> [0]PETSC ERROR: ./bin/solve on a x86_64 named master by fujisan Tue Sep 20
> 16:56:37 2022
> [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 --do

[petsc-users] Problem solving Ax=b with rectangular matrix A

2022-09-21 Thread fujisan
I'm trying to solve Ax=b with a sparse rectangular matrix A (of size 33x17
in my test) using
options '-ksp_type stcg -pc_type lu' on 1 or 2 cpus.

And I always get an error saying "Incompatible vector local lengths" (see
below).

Here is the relevant lines of my code:

program test
...
! Variable declarations

PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,ierr))

PetscCall(MatCreate(PETSC_COMM_WORLD,A,ierr))
PetscCall(MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n,ierr))
PetscCall(MatSetType(A,MATMPIAIJ,ierr))
PetscCall(MatSetFromOptions(A,ierr))
PetscCall(MatSetUp(A,ierr))
PetscCall(MatGetOwnershipRange(A,istart,iend,ierr))

do irow=istart,iend-1
... Reading from file ...
PetscCall(MatSetValues(A,1,irow,nzv,col,val,ADD_VALUES,ierr))
...
enddo

PetscCall(MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr))
PetscCall(MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr))

! Creating vectors x and b
PetscCallA(MatCreateVecs(A,x,b,ierr))

! Duplicating x in u.
PetscCallA(VecDuplicate(x,u,ierr))

! u is used to calculate b
PetscCallA(VecSet(u,1.0,ierr))

PetscCallA(VecAssemblyBegin(u,ierr))
PetscCallA(VecAssemblyEnd(u,ierr))

! Calculating Au = b
PetscCallA(MatMult(A,u,b,ierr)) ! A.u = b

PetscCallA(KSPSetType(ksp,KSPCG,ierr))

PetscCallA(KSPSetOperators(ksp,A,A,ierr))

PetscCallA(KSPSetFromOptions(ksp,ierr))

! Solving Ax = b, x unknown
PetscCallA(KSPSolve(ksp,b,x,ierr))

PetscCallA(VecDestroy(x,ierr))
PetscCallA(VecDestroy(u,ierr))
PetscCallA(VecDestroy(b,ierr))
PetscCallA(MatDestroy(A,ierr))
PetscCallA(KSPDestroy(ksp,ierr))

call PetscFinalize(ierr)
end program

The code reads a sparse matrix from a binary file.
I also output the sizes of matrix A and vectors b, x, u.
They all seem consistent.

What am I doing wrong?
Is it possible to solve Ax=b with A rectangular?

Thank you in advance for your help.
Have a nice day.

Fuji

 Matrix size : m=  33  n=  17  cpu size:1
 Size of matrix A  :   33  17
 Size of vector b :   33
 Size of vector x :   17
 Size of vector u :   17
[0]PETSC ERROR: - Error Message
--
[0]PETSC ERROR: Arguments are incompatible
[0]PETSC ERROR: Incompatible vector local lengths parameter # 1 local size
33 != parameter # 2 local size 17
[0]PETSC ERROR: See https://petsc.org/release/faq/ for trouble shooting.
[0]PETSC ERROR: Petsc Development GIT revision: v3.17.4-1341-g91b2b62a00
GIT Date: 2022-09-15 19:26:07 +
[0]PETSC ERROR: ./bin/solve on a x86_64 named master by fujisan Tue Sep 20
16:56:37 2022
[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
[0]PETSC ERROR: #1 VecCopy() at
/data/softs/petsc/src/vec/vec/interface/vector.c:1607
[0]PETSC ERROR: #2 KSPSolve_BiCG() at
/data/softs/petsc/src/ksp/ksp/impls/bicg/bicg.c:40
[0]PETSC ERROR: #3 KSPSolve_Private() at
/data/softs/petsc/src/ksp/ksp/interface/itfunc.c:877
[0]PETSC ERROR: #4 KSPSolve() at
/data/softs/petsc/src/ksp/ksp/interface/itfunc.c:1048
[0]PETSC ERROR: #5 solve.F90:218
Abort(75) on node 0 (rank 0 in comm 16): application called
MPI_Abort(MPI_COMM_SELF, 75) - process 0