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?

  • 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$ – Tyler Olsen Jun 17 '15 at 2:12
  • 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.
  • $\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 Jun 16 '15 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$ – Shivam Malhotra Jun 17 '15 at 12:51
  • $\begingroup$ Should be configure --enable-debug=0, no? $\endgroup$ – G. Meyer Dec 6 '16 at 19:10
  • $\begingroup$ No (this is PETSc's configure, not autotools if that's where you are getting that flag). $\endgroup$ – Patrick Sanan Dec 7 '16 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.