<div dir="ltr"><div><div><div>Hello,<br><br></div>I am experiencing the strange behavior when calling the MatAXPY function. Here is my code:<br></div>matrix similarity is a square matrix (n=m)<br></div>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.  <br>


<div><div><div><div>    <br><div>    MatSetFromOptions(similarity);<br>    int n, m;<br>    MatGetSize(similarity, &n, &m);<br>    <br>    Vec tmp;<br>    VecCreate(PETSC_COMM_WORLD, &tmp);<br>    VecSetSizes(tmp, PETSC_DECIDE, n);<br>


    VecSetFromOptions(tmp);<br>    MatGetRowSum(similarity, tmp);<br>    <br>    Mat aux;<br>    MatCreate(PETSC_COMM_WORLD, &aux);<br>    MatSetSizes(aux, PETSC_DECIDE, PETSC_DECIDE, n, m);<br>    MatSetFromOptions(aux);    <br>


    MatSetUp(aux);<br>    MatZeroEntries(aux);<br>    MatDiagonalSet(aux, tmp, INSERT_VALUES); <br>    VecDestroy(&tmp);<br>    <br>    MatAXPY(aux, -1, similarity, DIFFERENT_NONZERO_PATTERN);<br><br></div><div>If I execute this code using only one process I get the segmentation violation error:<br>


<br>[0]PETSC ERROR: ------------------------------------------------------------------------<br>[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range<br>[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger<br>

[0]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC" target="_blank">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC</a> ERROR: or try <a href="http://valgrind.org" target="_blank">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors<br>

[0]PETSC ERROR: likely location of problem given in stack below<br>[0]PETSC ERROR: ---------------------  Stack Frames ------------------------------------<br>[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,<br>

[0]PETSC ERROR:       INSTEAD the line number of the start of the function<br>[0]PETSC ERROR:       is given.<br>[0]PETSC ERROR: [0] MatAXPYGetPreallocation_SeqAIJ line 2562 src/mat/impls/aij/seq/aij.c<br>[0]PETSC ERROR: [0] MatAXPY_SeqAIJ line 2587 src/mat/impls/aij/seq/aij.c<br>

[0]PETSC ERROR: [0] MatAXPY line 29 src/mat/utils/axpy.c<br>[0]PETSC ERROR: --------------------- Error Message ------------------------------------<br>[0]PETSC ERROR: Signal received!<br><br></div><div>However, if I run the same code using two processes it runs ok and gives the good result.<br>

</div><div>Could you please tell me what am I doing wrong?<br></div><div>Grateful in advance<br></div><div><br><br></div><div><br></div></div></div></div></div></div>