[petsc-users] Fortran alternative for DMDAGetElements?
Matthew Knepley
knepley at gmail.com
Fri Jun 30 09:50:18 CDT 2023
On Fri, Jun 30, 2023 at 10:48 AM Ngoc Mai Monica Huynh <
ngocmaimonica.huynh at unipv.it> wrote:
> Hi,
> yes, it runs and now also my code.
> I moved it from the extension .F to .F90.
> (With my older codes the extension .F still works fine, but not with this
> one)
>
Yes, you need .F90 to properly handle the interface definitions.
Thanks,
Matt
> Thank you for the patience and support!
> Monica
>
> On 30 Jun 2023, at 15:54, Barry Smith <bsmith at petsc.dev> wrote:
>
>
> I glued your code fragment into a stand-alone program and it runs fine
> for me on 16 ranks. Does this simple program run for you?
>
> program main
> #include <petsc/finclude/petscdm.h>
> use petsc
> implicit none
> integer ierr
>
> MPI_Comm comm
> DM da3d
> ISLocalToGlobalMapping map
> PetscInt nel,nen
> PetscInt, pointer :: e_loc(:)
>
> PetscCallA(PetscInitialize(ierr))
> comm = PETSC_COMM_WORLD
> call DMDACreate3d(comm,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE, &
> & DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,433,41,29, &
> & 8,2,1,3,1,PETSC_NULL_INTEGER, &
> & PETSC_NULL_INTEGER,PETSC_NULL_INTEGER, &
> & da3d,ierr)
> call DMSetMatType(da3d,MATIS,ierr)
> call DMSetFromOptions(da3d,ierr)
> call DMDASetElementType(da3d,DMDA_ELEMENT_Q1,ierr)
> call DMSetUp(da3d,ierr)
> call DMGetLocalToGlobalMapping(da3d,map,ierr)
>
> call DMDAGetElements(da3d,nel,nen,e_loc,ierr)
> call DMDARestoreElements(da3d,nel,nen,e_loc,ierr)
> PetscCallA(DMDestroy(da3d,ierr))
>
> PetscCallA(PetscFinalize(ierr)
>
>
>
> On Jun 30, 2023, at 9:21 AM, Ngoc Mai Monica Huynh <
> ngocmaimonica.huynh at unipv.it> wrote:
>
> Yes, I have the #include at the top of the code.
>
> Thank you very much for your help.
> I’ll let you know if I have any improvements from my side.
> Looking forward to hearing from you.
>
> Thanks,
> Monica
>
> On 30 Jun 2023, at 15:08, Matthew Knepley <knepley at gmail.com> wrote:
>
> On Fri, Jun 30, 2023 at 8:38 AM Ngoc Mai Monica Huynh <
> ngocmaimonica.huynh at unipv.it> wrote:
>
>> Yes, it compiles and run correctly
>>
>
> Okay, then we try to alter that example until it looks like your test.
>
> One thing is the #include at the top. Do you have that in your code? If
> Fortran does not find the interface,
> then it will just SEGV.
>
> Thanks,
>
> Matt
>
>
>> Monica
>>
>> On 30 Jun 2023, at 12:50, Matthew Knepley <knepley at gmail.com> wrote:
>>
>> On Fri, Jun 30, 2023 at 6:47 AM Ngoc Mai Monica Huynh <
>> ngocmaimonica.huynh at unipv.it> wrote:
>>
>>> Hi,
>>>
>>> I have no problem now in compiling, thank you for providing the Fortran
>>> interface.
>>> I have a follow up question.
>>> When running the code, I get this error, which I’m pretty sure it is
>>> related to DMDAGetElements(), since up to that line everything works fine.
>>>
>>> [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 https://petsc.org/release/faq/#valgrind and
>>> https://petsc.org/release/faq/
>>> [0]PETSC ERROR: --------------------- Stack Frames
>>> ------------------------------------
>>> [0]PETSC ERROR: No error traceback is available, the problem could be in
>>> the main program.
>>>
>>> --------------------------------------------------------------------------
>>> MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
>>> with errorcode 59.
>>>
>>> NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
>>> You may or may not see output from other processes, depending on
>>> exactly when Open MPI kills them.
>>> —————————————————————————————————————
>>>
>>> The lines of code I’m working on are the following:
>>>
>>> integer ierr
>>>
>>> MPI_Comm comm
>>> DM da3d
>>> ISLocalToGlobalMapping map
>>> PetscInt nel,nen
>>> PetscInt, pointer :: e_loc(:)
>>>
>>> call DMDACreate3d(comm,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,
>>> & DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,433,41,29,
>>> & 8,2,1,3,1,PETSC_NULL_INTEGER,
>>> & PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,
>>> & da3d,ierr)
>>> call DMSetMatType(da3d,MATIS,ierr)
>>> call DMSetFromOptions(da3d,ierr)
>>> call DMDASetElementType(da3d,DMDA_ELEMENT_Q1,ierr)
>>> call DMSetUp(da3d,ierr)
>>> call DMGetLocalToGlobalMapping(da3d,map,ierr)
>>>
>>> call DMDAGetElements(da3d,nel,nen,e_loc,ierr)
>>>
>>> By printing in a dummy way any kind of message before and after
>>> DMDAGetElements(), I cannot pass over it.
>>> Unfortunately, I cannot run with the debug option on this machine.
>>> Am I calling the routine in a wrong way?
>>>
>>
>> Does
>>
>> src/dm/tutorials/ex11f90.F90
>>
>> run for you?
>>
>> Thanks,
>>
>> Matt
>>
>>
>>> Thanks,
>>> Monica
>>>
>>>
>>> On 29 Jun 2023, at 21:09, Matthew Knepley <knepley at gmail.com> wrote:
>>>
>>> On Thu, Jun 29, 2023 at 3:05 PM Ngoc Mai Monica Huynh <
>>> ngocmaimonica.huynh at unipv.it> wrote:
>>>
>>>> Thank you.
>>>> Does this mean that DMDARestoreElements() is supported as well now?
>>>>
>>>
>>> Yes.
>>>
>>> Thanks,
>>>
>>> Matt
>>>
>>>
>>>> Monica
>>>>
>>>>
>>>> Il giorno 29 giu 2023, alle ore 20:17, Barry Smith <bsmith at petsc.dev>
>>>> ha scritto:
>>>>
>>>>
>>>>
>>>> The code is ready in the branch
>>>> *barry/2023-06-29/add-dmdagetelements-fortran *
>>>> https://gitlab.com/petsc/petsc/-/merge_requests/6647
>>>>
>>>> Barry
>>>>
>>>>
>>>> On Jun 29, 2023, at 12:41 PM, Ngoc Mai Monica Huynh <
>>>> ngocmaimonica.huynh at unipv.it> wrote:
>>>>
>>>> That would be amazing, thank you very much!
>>>> Monica
>>>>
>>>> On 29 Jun 2023, at 18:38, Barry Smith <bsmith at petsc.dev> wrote:
>>>>
>>>>
>>>> I can provide the Fortran interface this afternoon.
>>>>
>>>> Barry
>>>>
>>>>
>>>> On Jun 29, 2023, at 10:48 AM, Ngoc Mai Monica Huynh <
>>>> ngocmaimonica.huynh at unipv.it> wrote:
>>>>
>>>> Hi everyone,
>>>>
>>>> I would need to use the routine DMDAGetElements() in our Fortran code.
>>>> However, as I read from the manual, there is no Fortran support for
>>>> this routine.
>>>> Is there any similar alternative there?
>>>>
>>>> Many thanks!
>>>> Best regards,
>>>> Monica Huynh
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>> --
>>> What most experimenters take for granted before they begin their
>>> experiments is infinitely more interesting than any results to which their
>>> experiments lead.
>>> -- Norbert Wiener
>>>
>>> https://www.cse.buffalo.edu/~knepley/
>>> <http://www.cse.buffalo.edu/~knepley/>
>>>
>>>
>>>
>>
>> --
>> What most experimenters take for granted before they begin their
>> experiments is infinitely more interesting than any results to which their
>> experiments lead.
>> -- Norbert Wiener
>>
>> https://www.cse.buffalo.edu/~knepley/
>> <http://www.cse.buffalo.edu/~knepley/>
>>
>>
>>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://www.cse.buffalo.edu/~knepley/
> <http://www.cse.buffalo.edu/~knepley/>
>
>
>
>
>
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230630/f94b0721/attachment-0001.html>
More information about the petsc-users
mailing list