[petsc-users] How to use PETSc4py/SLEPc4py to solve an eigenvalue problem in parallel
Mengqi Zhang
jollage at gmail.com
Wed Oct 29 21:30:30 CDT 2014
Hi again,
I read the demo's and also consulted the src folder. Now, the PETSc part
assembling the matrices is clear to me. I put together a very simple
example by modifying the ex1.py. My code is attached. The problem now for
me is that it seems I can't switch the SLEPc.EPS to a parallel one.
I tried to run the attached code on my laptop which has 2 physical cores.
The results of parallel running are (I use mpirun -np 2 python
matricesEigenvalue.py to run parallelly)
from 0 to 8192 on rank 0 # The
matrix is of 128*128, the first half is allocated on rank 0
from 8192 to 16384 on rank 1 # so it's from
0 to 8192, the rank 1 for the rest
******************************
Using SLEPc4py for solving the EVP
******************************
Elapsed time of EPS is 4.9312 on rank 0
******************************
*** SLEPc Solution Results ***
******************************
Number of iterations of the method: 90
Solution method: krylovschur
Number of requested eigenvalues: 3
Stopping condition: tol=1e-08, maxit=1820
Number of converged eigenpairs 3
k ||Ax-kx||/||kx||
----------------- ------------------
129012.869061 7.58376e-09
128984.178324 7.86259e-09
128955.487588 8.10532e-09
while, the results of serial running are
from 0 to 16384 on rank 0
******************************
Using SLEPc4py for solving the EVP
******************************
Elapsed time of EPS is 4.5439 on rank 0
******************************
*** SLEPc Solution Results ***
******************************
Number of iterations of the method: 90
Solution method: krylovschur
Number of requested eigenvalues: 3
Stopping condition: tol=1e-08, maxit=1820
Number of converged eigenpairs 3
k ||Ax-kx||/||kx||
----------------- ------------------
129012.869061 7.58376e-09
128984.178324 7.86259e-09
128955.487588 8.10532e-09
It seems that the parallel running doesn't work, the elapsed time is
roughly the same. You see that in the process of assembling the matrix in
the parallel case, the two cores are working according to
from 0 to 8192 on rank 0
from 8192 to 16384 on rank 1
but in the SLEPc phase, only rank 0 is working (the print command only
works for rank 0, but not for rank 1). I also tried to run the ex1.py in
parallel and in serial, the computation times for a relative large matrix
are also roughly the same for the two runnings, or in some cases, parallel
running is even longer.
Could you help me on this? Thanks a lot.
2014-10-29 15:37 GMT-02:00 Mengqi Zhang <jollage at gmail.com>:
> Thanks a lot, Jose. I'll try to read and I'll come back to you if I have
> any problem.
>
> Mengqi
>
> 2014-10-29 12:23 GMT-02:00 Jose E. Roman <jroman at dsic.upv.es>:
>
>
>> El 29/10/2014, a las 14:56, Mengqi Zhang escribió:
>>
>> > Hi, Jose
>> >
>> > Thanks for your reply.
>> > I will specify the problem more exactly. I want to solve a big
>> generalized eigenvalue problem. The matrices are sparse. My question lies
>> on how to allocate the matrices among the processors. Do I have to do it by
>> myself? Or there is a routine to do so? I notice that one should do
>> something like
>> > from petsc4py import PETSc
>> >
>> >
>> > A = PETSc.Mat().create()
>> >
>> >
>> > A.setType('aij')
>> >
>> >
>> > A.setSizes([M,N])
>> >
>> >
>> > A.setPreallocationNNZ([diag_nz, offdiag_nz]) # optional
>> > A.setUp()
>> > I have several question regarding these lines.
>> > (1) I presume M and N are the dimension of the matrix. Then how do the
>> processors divide the matrix? I guess setPreallocationNNZ does the
>> allocation of the matrix among the processors. What does nz mean here? Why
>> here appears diag and offdiag?
>> > (2) I actually saw somewhere else that people use
>> A.setPreallocationNNZ(5), with a single parameter 5. What does 5 mean here?
>> > (3) I want to make sure that the matrix so generated is sparse (since
>> it uses aij). It is sparse right? I feel it tricky since if the matrix is
>> stored as sparse, will the allocation/parallelization destroy the
>> efficiency of sparse matrix?
>> >
>> >
>> > After the matrix is set up, I would like to use SLEPc4py to solve the
>> generalized eigenvalue problem. The example code I got online is like
>> > E = SLEPc.EPS(); E.create()
>> > E.setOperators(A)
>> > E.setProblemType(SLEPc.EPS.ProblemType.GNHEP)
>> > E.setFromOptions()
>> > E.solve()
>> > I'm afraid this script is not designed for the parallel computation
>> since in the options there is no indication of parallelization. Do you know
>> how to set it up?
>> >
>> > Thank you very much for your time. I appreciate it very much.
>> > Best,
>> > Mengqi
>> >
>>
>> Almost all examples under slepc4py/demo are parallel. You can take for
>> instance ex1.py as a basis for your own scripts. In these examples, every
>> process fills its part of the matrix (locally owned rows), as obtained from
>> getOwnershipRange(). See PETSc's documentation here:
>>
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetOwnershipRange.html
>>
>> The meaning of the preallocation arguments is also explained in PETSc's
>> manpages:
>>
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html
>>
>> petsc4py/slepc4py are just python wrappers to PETSc/SLEPc, so you must
>> understand how PETSc and SLEPc work, and dig into their manuals and
>> manpages.
>>
>> Jose
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20141030/8ea18aa5/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: matricesEigenvalue.py
Type: text/x-python-script
Size: 2732 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20141030/8ea18aa5/attachment-0001.bin>
More information about the petsc-users
mailing list