[petsc-users] MatAXPY Segmentation violation

Jelena Slivka slivkaje at gmail.com
Sat Dec 29 21:41:47 CST 2012


Hello,

I am experiencing the strange behavior when calling the MatAXPY function.
Here is my code:
matrix similarity is a square matrix (n=m)
I create the matrix aux that has all zero elements, except for the
diagonal. The elements of the diagonal in matrix aux are sums of rows in
matrix similarity.

    MatSetFromOptions(similarity);
    int n, m;
    MatGetSize(similarity, &n, &m);

    Vec tmp;
    VecCreate(PETSC_COMM_WORLD, &tmp);
    VecSetSizes(tmp, PETSC_DECIDE, n);
    VecSetFromOptions(tmp);
    MatGetRowSum(similarity, tmp);

    Mat aux;
    MatCreate(PETSC_COMM_WORLD, &aux);
    MatSetSizes(aux, PETSC_DECIDE, PETSC_DECIDE, n, m);
    MatSetFromOptions(aux);
    MatSetUp(aux);
    MatZeroEntries(aux);
    MatDiagonalSet(aux, tmp, INSERT_VALUES);
    VecDestroy(&tmp);

    MatAXPY(aux, -1, similarity, DIFFERENT_NONZERO_PATTERN);

If I execute this code using only one process I get the segmentation
violation error:

[0]PETSC ERROR:
------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation,
probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see
http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC ERROR:
or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory
corruption errors
[0]PETSC ERROR: likely location of problem given in stack below
[0]PETSC ERROR: ---------------------  Stack Frames
------------------------------------
[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,
[0]PETSC ERROR:       INSTEAD the line number of the start of the function
[0]PETSC ERROR:       is given.
[0]PETSC ERROR: [0] MatAXPYGetPreallocation_SeqAIJ line 2562
src/mat/impls/aij/seq/aij.c
[0]PETSC ERROR: [0] MatAXPY_SeqAIJ line 2587 src/mat/impls/aij/seq/aij.c
[0]PETSC ERROR: [0] MatAXPY line 29 src/mat/utils/axpy.c
[0]PETSC ERROR: --------------------- Error Message
------------------------------------
[0]PETSC ERROR: Signal received!

However, if I run the same code using two processes it runs ok and gives
the good result.
Could you please tell me what am I doing wrong?
Grateful in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20121230/f1617172/attachment.html>


More information about the petsc-users mailing list