[petsc-users] How to use petsc in a dynamically loaded shared library?

Jed Brown jedbrown at mcs.anl.gov
Wed Jul 18 06:27:52 CDT 2012


On Wed, Jul 18, 2012 at 5:50 AM, Florian Beck <Flo.44 at gmx.de> wrote:

> Hi,
>
> I want to use the petsc library in a shared library which I'm dynamically
> loading in my main program. Therefore I'm not using the functions to
> destroy a Vector such as VecDestroy. If I use the function I got an
> segmentation fault error.


Send the full error message (including stack trace).


> Of course I have a memory leak, because I'm not using the functions to
> destroy my vectors. Is there a simple example how to use the petsc-library
> in a program like the following pseudo-code:
>

Is MPI initialized before this is called? Did you plan to do this in
parallel? Are you linking PETSc dynamically (as in, you dlopen and dlsym
PETSc functions to call them, or perhaps you declare weak symbols in your
code), linking your app-specific solver module (you call PETSc normally and
use dlsym at a higher level), or something else? Remember to configure
PETSc --with-dynamic-loading if necessary.

The best way is to reuse data structures, but if you are going to destroy
them each iteration, make sure you destroy all of them. Note that MPI
cannot be initialized more than once, but presumably you aren't doing that
because the rest of the app needs MPI to formulate the original problem.

Note that doing everything dynamic is more work and defers more errors from
compile and link time to run time. It is possible, but it takes more effort
and some familiarity with requirements for dynamic loading.


>
> main{
>
>  for 1 to 10
>
>    do_something
>
>    call function_to_solve_Ax=b_with_petsc
>
>    do_something
>
>  end
>
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120718/e18bf9d7/attachment.html>


More information about the petsc-users mailing list