[petsc-users] difference on MATLAB backslash and PETSc/external solvers

Umut Tabak u.tabak at tudelft.nl
Fri Apr 15 12:33:49 CDT 2011


Dear all,

I have been testing the factors of a symmetric matrix of size 4225 by 
4225 as a preconditioner for a pcg type iteration in MATLAB(Since I have 
these factors from an eigenvalue extraction process). I extract the main 
matrix from a commercial code and the sparsity pattern is not that 
optimum for the moment.

Using the built in profiler, I tried to check the performance of the 
implementation, most of my time was spent in the forward-backward 
substitutions resulting from the preconditioner usage, namely, the  p = 
M^{-1} r operation in the pcg algorithm, which was expected.

Moreover, I conducted a series of simple tests with the same operator 
matrix and right hand side in PETSc and with the external direct solver 
interfaces, I ended up some differences in the solution phases. I timed 
the process with PetscGetTime function. The related part of the code is 
given as

    std::cout << "First solve ... " << std::endl;
    ierr = PetscGetTime(&t1);CHKERRQ(ierr);
    ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
    ierr = PetscGetTime(&t2);CHKERRQ(ierr);
    std::cout << "Code took " << t2-t1 << " seconds .. " << std::endl;
    std::cout << "Second solve ... " << std::endl;
    ierr = PetscGetTime(&t3);CHKERRQ(ierr);
    ierr = KSPSolve(ksp,b,y);CHKERRQ(ierr);
    ierr = PetscGetTime(&t4);CHKERRQ(ierr);
    std::cout << "Code took " << t4-t3 << " seconds .. " << std::endl;
    std::cout << "Third  solve ... " << std::endl;
    ierr = PetscGetTime(&t5);CHKERRQ(ierr);
    ierr = KSPSolve(ksp,b,z);CHKERRQ(ierr);
    ierr = PetscGetTime(&t6);CHKERRQ(ierr);
    std::cout << "Code took " << t6-t5 << " seconds .. " << std::endl;

Basically, I do a first solve where the factorization is done( just to 
be sure, KSPSolve is the step where the factorization is done, right?) 
Then, the results for different factorization and forward backward 
substitutions are given below, when I use the ksp object the second 
time, it basically does a forward-backward solve, right? Then I compare 
the results with the MATLAB backslash which is also using UMFPACK as far 
as I can read from the documentation. PETSc is built in the default 
mode, which is the debug mode. Can this be the reason of this? Any 
explanations are welcome on this.
Actually the difference on the umfpack result was interesting to me.

Here are the results:

umfpack:
---------------------------------------------------
First solve ...
Code took 1.94039 seconds ..
Second solve ...
Code took 0.0264909 seconds ..
Third  solve ...
Code took 0.0264909 seconds ..

mumps:
---------------------------------------------------
First solve ...
Code took 1.40669 seconds ..
Second solve ...
Code took 0.0235441 seconds ..
Third  solve ...
Code took 0.023541 seconds ..

superlu:
---------------------------------------------------
First solve ...
Code took 3.20602 seconds ..
Second solve ...
Code took 0.0487978 seconds ..
Third  solve ...
Code took 0.048856 seconds ..

spooles:
----------------------------------------------------
First solve ...
Code took 1.43427 seconds ..
Second solve ...
Code took 0.0536189 seconds ..
Third  solve ...
Code took 0.053726 seconds ..

PETSc
----------------------------------------------------
First solve ...
Code took 1.3292 seconds ..
Second solve ...
Code took 0.0116079 seconds ..
Third  solve ...
Code took 0.011915 seconds ..

MATLAB by cputime function
-----------------------------------------------------
A \ b (native backslash)
3.800000000000006e-01 (with a bit fluctuation )

and by using the Factorize package also written by Timothy Davis;

t = cputime; factorOpA =factorize(OpA); factorOpA \ rhsA; cputime-t
6.300000000000026e-01

and a forward backward substitution using factorOpA

t = cputime; factorOpA \ rhsA; cputime-t
9.999999999998010e-03

Best,
Umut

-- 
If I have a thousand ideas and only one turns out to be good,
I am satisfied.
Alfred Nobel



More information about the petsc-users mailing list