[petsc-dev] calling petsc from a mex file

Munson, Todd tmunson at mcs.anl.gov
Tue May 8 13:53:58 CDT 2018

> On May 8, 2018, at 1:02 PM, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
>> On May 8, 2018, at 12:30 PM, Munson, Todd <tmunson at mcs.anl.gov> wrote:
>> Hi,
>> I wonder if anyone has experience calling petsc from matlab using mex.  I have the 
>> simplest possible mexFunction that just calls PetscInitialize() and 
>> PetscFinalize().  That part seems to work fine, but when I exit 
>> from matlab I get a segmentation violation and a petsc error
>> message.
>   What are all the error messages? Cut and paste. I've done this in the past but not for years.

Below is the matlab session and error message.  I do note that if I issue PetscFinalize() and 
that command completes, the Petsc signal handlers remain installed/active.  If I do a
PetscPopSignalHandler() immediately after PetscInitialize(), I do not get the error
message, but a "Segmentation fault: 11" output at the end.

Because petsc is being loaded as a dynamic library, are there possibly uninitialized global
variables or state?

Thanks, Todd.

[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: --------------------- Error Message --------------------------------------------------------------
[0]PETSC ERROR: Signal received
[0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.
[0]PETSC ERROR: Petsc Development GIT revision: v3.9.1-409-gf553c6556e  GIT Date: 2018-05-07 17:17:17 -0500
[0]PETSC ERROR: Unknown Name on a arch-darwin-c-debug named eduroam062-089.wl.anl-external.org by tmunson Tue May  8 12:04:45 2018
[0]PETSC ERROR: Configure options --download-mpich CC=/usr/bin/clang CXX=/usr/bin/clang++ FC=/opt/local/bin/gfortran
[0]PETSC ERROR: #1 User provided function() line 0 in  unknown file
application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0
[unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=59
system msg for write_line failure : Bad file descriptor

More information about the petsc-dev mailing list