3
$\begingroup$

I am trying to do a simple parallel sparse matrix vector multiplications using PETSC. My sparse matrix is a simple tridiagonal laplacian matrix, which is distributed over multiple processors using PETSC.

My main question is that if I do the same operation by simply iterating over the vector and updating each value A[i] = -1*A[i-1] + 2*A[i] + -1*A[i+1], it takes much lesser time than by using the PETSC SpMV. Why is it so? Or am I doing something wrong?

$\endgroup$
1
  • 1
    $\begingroup$ One note that may or may not be relevant: unless you're doing a Gauss-Seidel solve of a tridiagonal system, you likely have a bug in your hard-coded method. As written, you're updating A[i] in one loop iteration and using it again in the next, which is different than computing the matrix-vector product. $\endgroup$ Commented Jun 17, 2015 at 2:12

1 Answer 1

1
$\begingroup$
  • I assume that you are comparing multiplication with an assembled PETSc matrix with your hand-coded matrix-free method. The latter may indeed be faster, but this could be because no entries of A need be loaded from memory. A more meaningful comparison might be to a matrix-free operator in PETSc (see Section 3.3 in the manual).
  • Once you have an apples-to-apples comparison, you can try to determine if any remaining speed differences are due to PETSc overhead or not by using an optimized build (configure --with-debugging=0) and running your code with the -log_summary option to see timings of various operations.
$\endgroup$
4
  • $\begingroup$ @ShivamMalhotra, it would be good if you could say what part of this answer led to the solution and what the ultimate performance improvement was. $\endgroup$
    – Bill Barth
    Commented Jun 16, 2015 at 23:33
  • 2
    $\begingroup$ @BillBarth : Loading repeated entries of A again and again from memory were one of the reasons of the bad performance $\endgroup$
    – user16651
    Commented Jun 17, 2015 at 12:51
  • $\begingroup$ Should be configure --enable-debug=0, no? $\endgroup$ Commented Dec 6, 2016 at 19:10
  • $\begingroup$ No (this is PETSc's configure, not autotools if that's where you are getting that flag). $\endgroup$ Commented Dec 7, 2016 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.