<div dir="ltr">I suspect this has to do with Fortran declarations. First, make sure you are using the latest release. Second, look at <div><br></div><div> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/UsingFortran.html">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/UsingFortran.html</a></div><div><br></div><div>Make sure you have the right modules.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 23, 2017 at 5:43 PM, Samuel Lanthaler <span dir="ltr"><<a href="mailto:s.lanthaler@gmail.com" target="_blank">s.lanthaler@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>Hi there, <br>
</p>
<p>I'm new to PETSc and have been trying to do some basic
manipulation of matrices in fortran, but don't seem to be able to
set a row/column to zero using the MatZeroRowsColumns command: The
following is a small example program:<code><br>
</code></p>
<p><code> ! initialize PETSc</code><code><br>
</code><code> CALL PetscInitialize(PETSC_NULL_<wbr>CHARACTER,ierr)</code><code><br>
</code><code><br>
</code><code> ! Set up a new matrix</code><code><br>
</code><code> m = 3</code><code><br>
</code><code> CALL MatCreate(PETSC_COMM_WORLD,<wbr>matA,ierr);
CHKERRQ(ierr);</code><code><br>
</code><code> CALL MatSetType(matA,MATMPIAIJ,<wbr>ierr);
CHKERRQ(ierr);</code><code><br>
</code><code> CALL
MatSetSizes(matA,PETSC_DECIDE,<wbr>PETSC_DECIDE,m,m,ierr);
CHKERRQ(ierr);</code><code><br>
</code><code> CALL
MatMPIAIJSetPreallocation(<wbr>matA,3,PETSC_NULL_INTEGER,3,<wbr>PETSC_NULL_INTEGER,ierr);
CHKERRQ(ierr);</code><code><br>
</code><code><br>
</code><code> ! set values of matrix</code><code><br>
</code><code> vals(1,:) = (/1.,2.,3./)</code><code><br>
</code><code> vals(2,:) = (/4.,5.,6./)</code><code><br>
</code><code> vals(3,:) = (/7.,8.,9./)</code><code><br>
</code><code> ! </code><code><br>
</code><code> idxm = (/0,1,2/)</code><code><br>
</code><code> idxn = (/0,1,2/)</code><code><br>
</code><code> !</code><code><br>
</code><code> CALL
MatSetValues(matA,3,idxm,3,<wbr>idxn,vals,INSERT_VALUES,ierr);
CHKERRQ(ierr);</code><code><br>
</code><code> </code><code><br>
</code><code> ! assemble matrix</code><code><br>
</code><code> CALL
MatAssemblyBegin(matA,MAT_<wbr>FINAL_ASSEMBLY,ierr); CHKERRQ(ierr);</code><code><br>
</code><code> CALL MatAssemblyEnd(matA,MAT_FINAL_<wbr>ASSEMBLY,ierr);
CHKERRQ(ierr);</code><code><br>
</code><code> </code><code><br>
</code><code> ! set one row/column to zero, put 6.0d0 on diagonal</code><code><br>
</code><code> idone(1) = 2</code><code><br>
</code><code> val = 6.0d0</code><code><br>
</code><code> CALL MatZeroRowsColumns(matA,1,<wbr>idone,val,ierr);
CHKERRQ(ierr);</code><code></code></p>
<p><code>! finalize PETSc</code><code><br>
</code><code> CALL PetscFinalize(PETSC_NULL_<wbr>CHARACTER,ierr)</code><code><br>
</code><code><br>
</code>When running the program, I get the following error
message:</p>
<p><code>[0]PETSC ERROR:
------------------------------<wbr>------------------------------<wbr>------------</code><code><br>
</code><code>[0]PETSC ERROR: Caught signal number 11 SEGV:
Segmentation Violation, probably memory access out of range</code><code><br>
</code><code>[0]PETSC ERROR: Try option -start_in_debugger or
-on_error_attach_debugger</code><code><br>
</code><code>[0]PETSC ERROR: or see
<a class="m_-7121360866786311282moz-txt-link-freetext" href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>documentation/faq.html#<wbr>valgrind</a></code><code><br>
</code><code>[0]PETSC ERROR: or try <a class="m_-7121360866786311282moz-txt-link-freetext" href="http://valgrind.org" target="_blank">http://valgrind.org</a> on
GNU/linux and Apple Mac OS X to find memory corruption errors</code><code><br>
</code><code>[0]PETSC ERROR: likely location of problem given in
stack below</code><code><br>
</code><code>[0]PETSC ERROR: --------------------- Stack Frames
------------------------------<wbr>------</code><code><br>
</code><code>[0]PETSC ERROR: Note: The EXACT line numbers in the
stack are not available,</code><code><br>
</code><code>[0]PETSC ERROR: INSTEAD the line number of the
start of the function</code><code><br>
</code><code>[0]PETSC ERROR: is given.</code><code><br>
</code><code>[0]PETSC ERROR: --------------------- Error Message
------------------------------<wbr>------------------------------<wbr>--</code><code><br>
</code><code>[0]PETSC ERROR: Signal received</code><code><br>
</code><code>[0]PETSC ERROR: See
<a class="m_-7121360866786311282moz-txt-link-freetext" href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">http://www.mcs.anl.gov/petsc/<wbr>documentation/faq.html</a> for trouble
shooting.</code><code><br>
</code><code>[0]PETSC ERROR: Petsc Release Version 3.8.2, Nov, 09,
2017 </code><code><br>
</code><code>[0]PETSC ERROR: ./test on a arch-complex-debug named
sam-ThinkPad-T450s by sam Thu Nov 23 23:28:15 2017</code><code><br>
</code><code>[0]PETSC ERROR: Configure options
PETSC_DIR=/home/sam/Progs/<wbr>petsc-3.8.2
PETSC_ARCH=arch-complex-debug --with-scalar-type=complex</code><code><br>
</code><code>[0]PETSC ERROR: #1 User provided function() line 0
in unknown file</code><code><br>
</code><code>------------------------------<wbr>------------------------------<wbr>--------------</code><code><br>
</code><code>MPI_ABORT was invoked on rank 0 in communicator
MPI_COMM_WORLD </code><code><br>
</code><code>with errorcode 59.</code><br>
</p>
<p>Would someone be so kind as to tell me what I'm doing wrong?
Thank you!</p>
Best regards,<br>
Sam<br>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.caam.rice.edu/~mk51/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div>
</div>