<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi Matthew,<br>
    </p>
    <div class="moz-cite-prefix">On 2025-03-14 13:09, Matthew Knepley
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAMYG4Gk=dOdKnYHgbX9XHK5aERy49LBO0HvS-tD-scU+fV9Hyw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr">On Fri, Mar 14, 2025 at 12:53 PM Eric Chamberland
          <<a href="mailto:Eric.Chamberland@giref.ulaval.ca"
            moz-do-not-send="true" class="moz-txt-link-freetext">Eric.Chamberland@giref.ulaval.ca</a>>
          wrote:</div>
        <div class="gmail_quote gmail_quote_container">
          <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div>
              <p>Thanks Matthew!</p>
              <p>I hope you're doing well.<br>
              </p>
            </div>
          </blockquote>
          <div><br>
          </div>
          <div>Hi! I know there is still a Plex bug submitted, but this
            is the busiest time of the year. I will fix it soon.</div>
        </div>
      </div>
    </blockquote>
    No rush, we are working on 2D examples for now, take your time!<br>
    <blockquote type="cite"
cite="mid:CAMYG4Gk=dOdKnYHgbX9XHK5aERy49LBO0HvS-tD-scU+fV9Hyw@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote gmail_quote_container">
          <div> </div>
          <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div>
              <p>I have a question regarding a change I did on our code:
                I modified the code to call <code>PetscPythonInitialize(PETSC_NULLPTR,
                  PETSC_NULLPTR)</code> after <code>SlepcInitialize</code>.</p>
              <p>Our CI ran successfully across 20 different
                environments (including Valgrind), but we encountered a
                segmentation fault on Ubuntu 24.04 when calling <code>PetscPythonInitialize</code>
                within our Python module (built using Pybind11
                bindings).</p>
              <p>On Ubuntu, calling <code>PetscPythonInitialize</code>
                from within our Python 3 module results in a segfault
                with the following backtrace:</p>
              <p><span style="font-family:monospace"><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"></span></span></p>
            </div>
          </blockquote>
          <div>This is weird. When I have seen things like this before,
            it is because someone is not dynamically linking properly,
            so that</div>
          <div>static variables are duplicated, and they get out of
            sync.</div>
          <div><br>
          </div>
          <div>This is why I always use  -python to have PETSc do that
            initialization automatically, and it guaranteed to be linked
            to the same</div>
          <div>libpython that the SNESPYTHON is using.</div>
        </div>
      </div>
    </blockquote>
    <p>Ok, my colleague René and I have built a reproducer, see
      <a class="moz-txt-link-freetext" href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/issues/1717__;!!G_uCfscf7eWS!Y9u6eJnvOw3IsoL2l2NE4TRAuerg63WS_QF4KnevrJSvCcetF4dyqWweHkPeGbZJ27D_p1cH1cvdr5RhjeMhZ82J5axUqPoNQMXT6pFI$">https://gitlab.com/petsc/petsc/-/issues/1717</a>.</p>
    <p>Thanks,</p>
    <p>Eric<br>
    </p>
    <blockquote type="cite"
cite="mid:CAMYG4Gk=dOdKnYHgbX9XHK5aERy49LBO0HvS-tD-scU+fV9Hyw@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote gmail_quote_container">
          <div><br>
          </div>
          <div>  Thanks,</div>
          <div><br>
          </div>
          <div>     Matt</div>
          <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div>
              <p><span style="font-family:monospace"><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">Thread 1
                    "python3" received signal SIGSEGV, Segmentation
                    fault. </span><br>
                  <span
style="color:rgb(24,24,178);background-color:rgb(255,255,255)">0x00001555339b372a</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> in </span><span
style="color:rgb(178,104,24);background-color:rgb(255,255,255)">PyList_New</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> () from </span><span
style="color:rgb(24,178,24);background-color:rgb(255,255,255)">/lib/x86_64-linux-gnu/libpython3.12.so.1.0</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><br>
                  (gdb) bt <br>
                  #0  <span
style="color:rgb(24,24,178);background-color:rgb(255,255,255)">0x00001555339b372a</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> in </span><span
style="color:rgb(178,104,24);background-color:rgb(255,255,255)">PyList_New</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> () from </span><span
style="color:rgb(24,178,24);background-color:rgb(255,255,255)">/lib/x86_64-linux-gnu/libpython3.12.so.1.0</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><br>
                  #1  <span
style="color:rgb(24,24,178);background-color:rgb(255,255,255)">0x0000155533ad89d7</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> in </span><span
style="color:rgb(178,104,24);background-color:rgb(255,255,255)">PyImport_Import</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> () from </span><span
style="color:rgb(24,178,24);background-color:rgb(255,255,255)">/lib/x86_64-linux-gnu/libpython3.12.so.1.0</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><br>
                  #2  <span
style="color:rgb(24,24,178);background-color:rgb(255,255,255)">0x0000155533ad8c80</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> in </span><span
style="color:rgb(178,104,24);background-color:rgb(255,255,255)">PyImport_ImportModule</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> () from </span><span
style="color:rgb(24,178,24);background-color:rgb(255,255,255)">/lib/x86_64-linux-gnu/libpython3.12.so.1.0</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> </span><br>
                  #3  <span
style="color:rgb(24,24,178);background-color:rgb(255,255,255)">0x000015553f437c0c</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> in </span><span
style="color:rgb(178,104,24);background-color:rgb(255,255,255)">PetscPythonInitialize</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> (</span><span
style="color:rgb(24,178,178);background-color:rgb(255,255,255)">pyexe</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">=0x0, </span><span
style="color:rgb(24,178,178);background-color:rgb(255,255,255)">pylib</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">=0x0) at </span><span
style="color:rgb(24,178,24);background-color:rgb(255,255,255)">/tmp/build_openmpi-4.1.6-opt/petsc-3.21.6-debug/src/sys/python/pythonsys.c</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">:242</span><br>
                </span></p>
              <p>I am puzzled by this segfault...</p>
              <p>Some relevant details:<br>
              </p>
              <p><span style="font-family:monospace"><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">grep -r
                    PETSC_PYTHON_EXE
                    /opt/petsc-3.21.6_debug_openmpi-4.1.6/include/ </span><br>
                  <span
style="color:rgb(178,24,178);background-color:rgb(255,255,255)">/opt/petsc-3.21.6_debug_openmpi-4.1.6/include/petscconf.h</span><span
style="color:rgb(24,178,178);background-color:rgb(255,255,255)">:</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">#define </span><span
style="font-weight:bold;color:rgb(255,84,84);background-color:rgb(255,255,255)">PETSC_PYTHON_EXE</span><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
                    "/usr/bin/python3"</span></span></p>
              <p><span style="font-family:monospace"><span
style="color:rgb(0,0,0);background-color:rgb(255,255,255)">ls -la
                    /lib/x86_64-linux-gnu/libpython3.12*<br>
                    lrwxrwxrwx 1 root root       58 Feb  4 09:48
                    /lib/x86_64-linux-gnu/libpython3.12.a ->
                    ../python3.12/config-3.12-x86_64-linux-gnu/libpython3.12.a<br>
                    lrwxrwxrwx 1 root root       60 Feb  4 09:48
                    /lib/x86_64-linux-gnu/libpython3.12d.a ->
                    ../python3.12/config-3.12d-x86_64-linux-gnu/libpython3.12d.a<br>
                    lrwxrwxrwx 1 root root       19 Feb  4 09:48
                    /lib/x86_64-linux-gnu/<a href="https://urldefense.us/v3/__http://libpython3.12d.so__;!!G_uCfscf7eWS!Y9u6eJnvOw3IsoL2l2NE4TRAuerg63WS_QF4KnevrJSvCcetF4dyqWweHkPeGbZJ27D_p1cH1cvdr5RhjeMhZ82J5axUqPoNQHADXm5h$" target="_blank" moz-do-not-send="true">libpython3.12d.so</a> ->
                    libpython3.12d.so.1<br>
                    lrwxrwxrwx 1 root root       21 Feb  4 09:48
                    /lib/x86_64-linux-gnu/libpython3.12d.so.1 ->
                    libpython3.12d.so.1.0<br>
                    -rw-r--r-- 1 root root 34018416 Feb  4 09:48
                    /lib/x86_64-linux-gnu/libpython3.12d.so.1.0<br>
                    lrwxrwxrwx 1 root root       18 Feb  4 09:48
                    /lib/x86_64-linux-gnu/<a href="https://urldefense.us/v3/__http://libpython3.12.so__;!!G_uCfscf7eWS!Y9u6eJnvOw3IsoL2l2NE4TRAuerg63WS_QF4KnevrJSvCcetF4dyqWweHkPeGbZJ27D_p1cH1cvdr5RhjeMhZ82J5axUqPoNQI5lkBGY$" target="_blank" moz-do-not-send="true">libpython3.12.so</a> ->
                    libpython3.12.so.1<br>
                    lrwxrwxrwx 1 root root       20 Feb  4 09:48
                    /lib/x86_64-linux-gnu/libpython3.12.so.1 ->
                    libpython3.12.so.1.0<br>
                    -rw-r--r-- 1 root root  9055112 Feb  4 09:48
                    /lib/x86_64-linux-gnu/libpython3.12.so.1.0<br>
                  </span></span></p>
              <p>(I installed the debug ("d") versions to get debug
                symbols, but the segfault occurs even without them.)</p>
              <p>Interestingly, on the same Ubuntu setup, calling <code>PetscPythonInitialize</code>
                within our <em>pure C++</em> code works fine, and the <code>"pc_type
                  python"</code> example runs successfully.</p>
              <p>This issue only occurs when calling <code>PetscPythonInitialize</code>
                from our <em>Python module</em>.</p>
              <p>Any ideas?</p>
              <p>Could this be something that has already been fixed in
                PETSc 3.22.x?</p>
              <p>Thanks,</p>
              <p>Eric</p>
              <p><br>
              </p>
              <div>On 2025-03-12 16:48, Matthew Knepley wrote:<br>
              </div>
              <blockquote type="cite">
                <div dir="ltr">
                  <div dir="ltr">On Wed, Mar 12, 2025 at 4:34 PM Eric
                    Chamberland via petsc-users <<a
                      href="mailto:petsc-users@mcs.anl.gov"
                      target="_blank" moz-do-not-send="true"
                      class="moz-txt-link-freetext">petsc-users@mcs.anl.gov</a>>
                    wrote:</div>
                  <div class="gmail_quote">
                    <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
                      <br>
                      just a naive question: looking at KSPPYTHON and
                      PCPYTHON, we saw that <br>
                      there is only 1 example available.<br>
                      <br>
                      We are asking ourself: is it still supported and
                      can we start <br>
                      developping ou PCs and KSPs on top of it?<br>
                      <br>
                      Or is there a "new" replacement for these?<br>
                    </blockquote>
                    <div><br>
                    </div>
                    <div>I think the reason that there are so few
                      examples is that many examples exist in other
                      packages, such as Firedrake, and they are the main
                      consumers. KSPPYTHON is a way to write
                      KSPSHELL using Python rather than C, and we mostly
                      write C.</div>
                    <div><br>
                    </div>
                    <div>I will say that recently we fixed everything so
                      that PETSc errors and Python exceptions are passed
                      correctly up the stack, and debugging these things
                      should be easy. I have been debugging the
                      PyVista visualization, and I can change the Python
                      in one window and run in the other. It is easy.</div>
                    <div><br>
                    </div>
                    <div>  Thanks,</div>
                    <div><br>
                    </div>
                    <div>     Matt</div>
                    <div> </div>
                    <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                      Thanks,<br>
                      <br>
                      Eric<br>
                      <br>
                      -- <br>
                      Eric Chamberland, ing., M. Ing<br>
                      Professionnel de recherche<br>
                      GIREF/Université Laval<br>
                      (418) 656-2131 poste 41 22 42<br>
                      <br>
                    </blockquote>
                  </div>
                  <div><br clear="all">
                  </div>
                  <div><br>
                  </div>
                  <span class="gmail_signature_prefix">-- </span><br>
                  <div dir="ltr" class="gmail_signature">
                    <div dir="ltr">
                      <div>
                        <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="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!Y9u6eJnvOw3IsoL2l2NE4TRAuerg63WS_QF4KnevrJSvCcetF4dyqWweHkPeGbZJ27D_p1cH1cvdr5RhjeMhZ82J5axUqPoNQC9gNDOK$" target="_blank" moz-do-not-send="true">https://www.cse.buffalo.edu/~knepley/</a><br>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </blockquote>
              <pre cols="72">-- 
Eric Chamberland, ing., M. Ing
Professionnel de recherche
GIREF/Université Laval
(418) 656-2131 poste 41 22 42</pre>
            </div>
          </blockquote>
        </div>
        <div><br clear="all">
        </div>
        <div><br>
        </div>
        <span class="gmail_signature_prefix">-- </span><br>
        <div dir="ltr" class="gmail_signature">
          <div dir="ltr">
            <div>
              <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="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!Y9u6eJnvOw3IsoL2l2NE4TRAuerg63WS_QF4KnevrJSvCcetF4dyqWweHkPeGbZJ27D_p1cH1cvdr5RhjeMhZ82J5axUqPoNQC9gNDOK$" target="_blank" moz-do-not-send="true">https://www.cse.buffalo.edu/~knepley/</a><br>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Eric Chamberland, ing., M. Ing
Professionnel de recherche
GIREF/Université Laval
(418) 656-2131 poste 41 22 42</pre>
  </body>
</html>