Thank you very much! Using MatDuplicate solved the problem.
On Sun, Dec 30, 2012 at 4:52 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote: > You might rather use MatDuplicate(similarity,MAT_DO_NOT_COPY_VALUES,&aux). > > Can you try these? > > 1. using the debugger to get a stack trace > 2. run in valgrind to check for memory errors > 3. set up a test case so we can reproduce > > > > On Sat, Dec 29, 2012 at 9:41 PM, Jelena Slivka <slivkaje at gmail.com> wrote: > >> 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]PETSCERROR: >> 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/d077dfbf/attachment-0001.html>
