Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

Reading new input file causes crash somewhere else?

samrabin

Sam Rabin
Member
My code is crashing without a useful error message or debugging output (see here). I added a bunch of print statements to try and figure out where it's crashing, and then when that didn't help, I started commenting out bits of my new code. I've determined that the call of dshr_fldbun_getFldPtr here is causing the crash, but NOT when it's actually called. I know this because the crashing process always enters and exits the function in question successfully. The crash happens… somewhere else.

Annoyingly, I have also determined that it's not actually the use of the read-in values that's causing the problem, as the crash occurs even when I ignore crop_inst%rx_cultivar_gdds_thisyr and use the previous CLM code that I had been trying to replace.

Does anyone see any obvious problems with what I'm doing here? This is with ESMF, in case it matters.

Code:
lsize = bounds%endg - bounds%begg + 1
allocate(dataptr1d_cultivar_gdds(lsize))
allocate(dataptr2d_cultivar_gdds(lsize, ncft))
if (.not. generate_crop_gdds) then
    ! Read prescribed cultivar GDDs from input files
    ! Starting with npcropmin will skip generic crops
    do n = 1, ncft
       call dshr_fldbun_getFldPtr(sdat_cropcal_cultivar_gdds%pstrm(1)%fldbun_model, trim(stream_varnames_cultivar_gdds(n)), &
            fldptr1=dataptr1d_cultivar_gdds,  rc=rc)
       if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) then
          call ESMF_Finalize(endflag=ESMF_END_ABORT)
       end if
      
       ! Note that the size of dataptr1d includes ocean points so it will be around 3x larger than lsize
       ! So an explicit loop is required here
       do g = 1,lsize
          dataptr2d_cultivar_gdds(g,n) = dataptr1d_cultivar_gdds(g)
       end do
    end do

    ! Set rx_cultivar_gdd for each gridcell/patch combination
    do fp = 1, num_pcropp
       p = filter_pcropp(fp)
       ivt = patch%itype(p)
       ! Will skip generic crops
       if (ivt >= npcropmin) then
          n = ivt - npcropmin + 1
          ig = g_to_ig(patch%gridcell(p))
          crop_inst%rx_cultivar_gdds_thisyr(p,1) = dataptr2d_cultivar_gdds(ig,n)
       endif
    end do
end if ! not generate_crop_gdds

deallocate(dataptr1d_cultivar_gdds)
deallocate(dataptr2d_cultivar_gdds)
 

samrabin

Sam Rabin
Member
Oh, and the crash is a segmentation fault:

Code:
71:MPT ERROR: Rank 71(g:71) received signal SIGSEGV(11).
71:     Process ID: 1962, Host: r6i5n13, Program: /glade/scratch/samrabin/f10_f10_mg37_debug/bld/cesm.exe
71:     MPT Version: HPE MPT 2.22  03/31/20 15:59:10
71:
71:MPT: --------stack traceback-------
71:
71:MPT: -----stack traceback ends-----
71:MPT: On host r6i5n13, Program /glade/scratch/samrabin/f10_f10_mg37_debug/bld/cesm.exe, Rank 71, Process 1962: Dumping core on signal SIGSEGV(11) into directory /glade/scratch/samrabin/f10_f10_mg37_debug/run
 

samrabin

Sam Rabin
Member
Hmm, okay, a bit of additional testing suggests my input file might have a problem—I tried with a different file and it worked fine past the previously problematic timestep… until the end of the run, when it crashed with a segfault again.
 

samrabin

Sam Rabin
Member
Alright, it looks like the problem was allocating/deallocating the 1d array. I removed that and now it works!
 
Top