Fortran Just-in-time data mapping SIGSEGV on finalize

Hello,

I have recently completed the integration of preCICE with our in house solver and a simple forced oscillator code. It is a simple scheme CFD provides the mesh runs reports its time step and the forced oscillator provides displacements in accordance. This runs great. The CFD code calls finalize and exits appropriately but the oscillator code when finalizing reports a SIGSEGV error. I have added the config.xml, fortran code and traceback below.

<?xml version="1.0" encoding="UTF-8"?>
<precice-configuration experimental="true">
    <log enabled="true">
        <sink type="stream" output="stdout" format="(%Rank%)  [%Module%]:%Line% in %Function%: %ColorizedSeverity%%Message%" filter="(%Severity% = debug) and not ((%Severity% = info) and (%Rank% != 0))" enabled="true"/>
    </log>
    <!-- <profiling synchronize="true" /> -->
    <data:vector name="Displacements"/>

    <mesh name="uns3dMesh" dimensions="3">
        <use-data name="Displacements"/>
    </mesh>

    <participant name="uns3d">
        <provide-mesh name="uns3dMesh" />
        <read-data  name="Displacements" mesh="uns3dMesh"/>
    </participant>

    <participant name="fsihook">
        <receive-mesh name="uns3dMesh" from="uns3d" api-access="true"/>
        <write-data name="Displacements" mesh="uns3dMesh"/>
        <mapping:nearest-neighbor direction="write" to="uns3dMesh" constraint="conservative" />
    </participant>

    <m2n:sockets acceptor="uns3d" connector="fsihook"/>

    <coupling-scheme:serial-explicit>
        <participants first="uns3d" second="fsihook"/>
        <time-window-size value="-1" method="first-participant"/>
        <max-time-windows value="100000"/>
        <exchange data="Displacements" mesh="uns3dMesh" from="fsihook" to="uns3d"/>
    </coupling-scheme:serial-explicit>
</precice-configuration>

program fsiPrecicehook
    use mpi
    use precice
    implicit none
    character(64) :: configFileName
    character(9) :: meshname = "uns3dMesh"
    character(7) :: solvername = "fsihook"
    character(13) :: dataclass = 'Displacements'
    character(6) :: dataclass2 = 'Forces'
    integer :: myid
    integer :: ncpu
    integer :: ierr
    integer :: numVertices
    integer, allocatable :: vertexIDs(:)
    real(8), allocatable :: displacements(:), positions(:), forces(:)
    integer :: ongoing
    real(8) :: ctime = 0
    real(8) :: dt
    integer :: itercounter = 1
    integer :: niter

    call MPI_INIT(ierr)
    call MPI_Comm_rank(MPI_COMM_WORLD, myid, ierr)
    call MPI_Comm_size(MPI_COMM_WORLD, ncpu, ierr)
    call get_command_argument(2, configFileName)
    read(configFileName, *) niter
    call get_command_argument(1, configFileName)

    call precicef_create(solvername, configFileName, &
      &                        myid, ncpu, &
      &                        LEN_TRIM(solvername), LEN_TRIM(configFileName))
    call precicef_set_mesh_access_region(meshname, [.3d0, .7d0, -1.d0, 1.d0, .3d0, .7d0], LEN_TRIM(meshname))

    call precicef_initialize()
    call precicef_get_mesh_vertex_size(meshname, numVertices, LEN_TRIM(meshname))

    allocate(vertexIDs(numVertices))
    allocate(displacements(3*numVertices), positions(3*numVertices), forces(3*numVertices))
    vertexIDs = 0
    positions = 0d0
    call precicef_get_mesh_vertex_ids_and_coordinates(meshname, numVertices, vertexIDs, &
        positions, LEN_TRIM(meshname))
    
    call precicef_is_coupling_ongoing(ongoing)
    do while (ongoing /= 0 .and. itercounter < niter - 1)
        itercounter = itercounter + 1

        call precicef_get_max_time_step_size(dt)
        ctime = ctime + dt
        call square_gaussian(displacements, positions, ctime)
        
        call precicef_write_and_map_data(meshname, dataclass, numVertices, positions, &
                displacements, LEN_TRIM(meshname), LEN_TRIM(dataclass))
        call precicef_advance(dt)
        call precicef_is_coupling_ongoing(ongoing)
    enddo

    call precicef_finalize()

    call MPI_FINALIZE(ierr)

contains

    subroutine square_gaussian(disp, pos, rtime)
        implicit none
        real(8), intent(in) :: rtime
        real(8), intent(out) :: disp(:)
        real(8), intent(in) :: pos(:)
        real(8), parameter :: pi = 3.141592653589793238462643383279502d0
        integer :: m
        integer :: i
        
        do i=1, size(disp)
            disp(i*3-2) = 0
            disp(i*3-1) = (3.4843*exp(-3.43421*(pos(i*3-2)-.5)**2)-3.03708679002)* &
                (3.4843*exp(-3.43421*(pos(i*3  )-.5)**2)-3.03708679002)*sin(1d4*pi*rtime)
            disp(i*3  ) = 0
        enddo


    end subroutine
endprogram
(0)  [impl::ParticipantImpl]:604 in finalize: ESC[0mFinalize coupling scheme
(0)  [impl::ParticipantImpl]:1857 in closeCommunicationChannels: ESC[0mClosing communication with uns3d

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7f2162fd5d11 in ???
#1  0x7f2162fd4ee5 in ???
#2  0x7f2162cb708f in ???
        at /build/glibc-B3wQXB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#3  0x7f2162d0c589 in _int_malloc
        at /build/glibc-B3wQXB/glibc-2.31/malloc/malloc.c:3867
#4  0x7f2162d0e298 in __GI___libc_malloc
        at /build/glibc-B3wQXB/glibc-2.31/malloc/malloc.c:3066
#5  0x7f2162b34679 in ???
#6  0x7f2162b3adfa in ???
#7  0x7f21639d20b0 in _ZN5boost3log11v2_mt_posix7sources12basic_loggerIcN7precice7logging6Logger10LoggerImplENS2_19single_thread_modelEE20open_record_u
nlockedINS_9parameter3aux18flat_like_arg_listIJNSC_19flat_like_arg_tupleINS5_8keywords7func_ns4funcENSC_15tagged_argumentISH_PKcEESt17integral_constant
IbLb1EEEENSE_INSF_7file_ns4fileENSI_ISQ_SK_EESN_EENSE_INS1_8keywords3tag8severityENSI_ISV_KNS1_7trivial14severity_levelEEESN_EENSE_INSF_7line_ns4lineEN
SI_IS12_iEESN_EEEEEEENS1_6recordERKT_
        at /home/grads/j/justin.schoppe/uns3d/7.0.0/boost_1_74_0/include/boost/log/sources/basic_logger.hpp:263
#8  0x7f21639ce981 in ???
#9  0x7f21639c9a49 in _ZN5boost3log11v2_mt_posix7sources21basic_severity_loggerIN7precice7logging15precice_featureINS2_12basic_loggerIcNS5_6Logger10Log
gerImplENS2_19single_thread_modelEEEEENS1_7trivial14severity_levelEE20open_record_unlockedINS_9parameter3aux18flat_like_arg_listIJNSI_19flat_like_arg_t
upleINS5_8keywords7func_ns4funcENSI_15tagged_argumentISN_PKcEESt17integral_constantIbLb1EEEENSK_INSL_7file_ns4fileENSO_ISW_SQ_EEST_EENSK_INS1_8keywords
3tag8severityENSO_IS11_KSE_EEST_EENSK_INSL_7line_ns4lineEN^@^X^@^@^@^@^@^@^@^@<<9F>[<F2><FE>o<F9>^@^@^@^@^@^@^@^@  ^@^@^@^@^@^@^@I<9A><9C>c!       at /
home/grads/j/justin.schoppe/uns3d/7.0.0/boost_1_74_0/include/boost/log/sources/severity_feature.hpp:257
#10  0x7f21639c43e3 in _ZN5boost3log11v2_mt_posix7sources22basic_composite_loggerIcN7precice7logging6Logger10LoggerImplENS2_19single_thread_modelENS2_8
featuresIJNS2_8severityINS1_7trivial14severity_levelEEENS5_11precice_logEEEEE11open_recordINS_9parameter3aux18flat_like_arg_listIJNSJ_19flat_like_arg_t
upleINS5_8keywords7func_ns4funcENSJ_15tagged_argumentISO_PKcEESt17integral_constantIbLb1EEEENSL_INSM_7file_ns4fileENSP_ISX_SR_EESU_EENSL_INS1_8keywords
3tag8severityENSP_IS12_KSC_EESU_EENSL_INSM_7line_ns4lineEN^@^X^@^@^@^@^@^@^@^@<<9F>[<F2><FE>o<F9>^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@<E3>C<9C>c!       at /home/grads/j/justin.schoppe/uns3d/7.0.0/boost_1_74_0/include/boost/log/sources/basic_logger.hpp:579
#11  0x7f21639b47df in _ZN7precice7logging6Logger5debugENS0_11LogLocationESt17basic_string_viewIcSt11char_traitsIcEE
        at /home/grads/j/justin.schoppe/uns3d/7.0.0/precice/src/logging/Logger.cpp:184
#12  0x7f2163a1186c in _ZN7precice4impl15ParticipantImpl8finalizeEv
        at /home/grads/j/justin.schoppe/uns3d/7.0.0/precice/src/precice/impl/ParticipantImpl.cpp:616
#13  0x7f21639f7ecd in _ZN7precice11Participant8finalizeEv
        at /home/grads/j/justin.schoppe/uns3d/7.0.0/precice/src/precice/Participant.cpp:59
#14  0x7f2163c7517f in precicef_finalize_
        at /home/grads/j/justin.schoppe/uns3d/7.0.0/precice/extras/bindings/fortran/src/preciceFortran.cpp:78
#15  0x55dd5c81a003 in ???
#16  0x55dd5c81a04f in ???
#17  0x7f2162c98082 in __libc_start_main
        at ../csu/libc-start.c:308
#18  0x55dd5c81921d in ???
#19  0xffffffffffffffff in ???

Please delete or mark as closed I found where the memory leak was coming from

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.