[MITgcm-support] Segmentation fault trying to capture location in ptracers array.

Michael Schaferkotter schaferk at bellsouth.net
Tue Jun 9 21:36:03 EDT 2015


1) Print the counter 


>>>>        DO nTrac=1,PTRACERS_num,1
                    Print*,nTrac
>>>>          fldName=PTRACERS_names(nTrac)
>>>>          IF ( fldName(1:4) .EQ. 'apre' ) THEN
>>>>             itrc_apre=nTrac         
>>>>          ELSEIF ( fldName(1:4) .EQ. 'ppre' ) THEN
>>>>             itrc_ppre=nTrac
>>>>          ELSEIF ( fldName(1:7) .EQ. 'atmpco2' ) THEN
>>>>             itrc_pco2=nTrac
>>>>          ENDIF         
>>>>        ENDDO

2) Use a debugger, ie gdb to trap the segfault with backtrace
And find exactly where the segfault occurs.

Sent from Here3.

> On Jun 9, 2015, at 18:33, Jonathan Lauderdale <jml1 at mit.edu> wrote:
> 
> Hi Michael,
> 
> Thanks for your reply, I am using gfortran (gcc49 on an iMac 10.10) with -g and -C and that is all the output I get, but I will check for specific version flags, etc….
> 
> If I comment out the loop in my previous message and just leave in "[….reset preformed surface tracer concentration…]” which has the same set of logical calls to PTRACERS_names then there is no segfault. Also if I comment out just the itrc_xxxx=nTrac or itrc_xxxx=tmp lines then there is no problem, so it must be something to do with initializing or assigning these values.
> 
> Here are some of the other things you asked about:
> 
> In EEPARMS.h
>               PARAMETER ( MAX_LEN_FNAM = 512 )
> In PTRACERS_SIZE.h
> 	      INTEGER PTRACERS_num
> 	      PARAMETER(PTRACERS_num = 12 ) 
> In PTRACERS_PARAMS.h
>  CHARACTER*(MAX_LEN_FNAM) PTRACERS_names(PTRACERS_num)
> 
> Thanks again,
> 
> Jon
> 
>> On 9 Jun 2015, at 18:59, Michael Schaferkotter <schaferk at bellsouth.net> wrote:
>> 
>> Recompile with -g -C ( or with whatever the bounds check switch is with the compiler).
>> 
>> Also set the switches to trap segfault at run time.
>> 
>> You could add print statements for all counters, and extents values.
>> What is the value of MAX_LEN_FNAM, PTRACERS_num?
>> How is PTRACERS_names instantiated?
>> 
>> 
>> Sent from Here3.
>> 
>>> On Jun 9, 2015, at 16:49, Jonathan Lauderdale <jml1 at mit.edu> wrote:
>>> 
>>> Hello,
>>> 
>>> I am trying to add a few passive/preformed tracers to the end of the pTracers array. In my code (gchem_forcing_sep.F to be precise), I cycle through the extra tracers in a “do” loop and use PTRACERS_names to decide how to reset the surface values (e.g. preformed phosphate, ppre, is reset to surface po4 values; cpre to surface dic values). This works great. 
>>> 
>>> For a few calculations later, I want to capture the order of these extra tracers (if they exist) and pass them as arguments to a subroutine, similar to how dic_biotic_forcing is done. Sounds simple...My minimal working example loop is as follows:
>>> 
>>>>        INTEGER nTrac
>>>>        INTEGER itrc_apre,itrc_ppre,itrc_pco2 
>>>>        CHARACTER*(MAX_LEN_FNAM) fldName
>>>> 
>>>> [….reset preformed surface tracer concentration…]
>>>> 
>>>>        DO nTrac=1,PTRACERS_num,1
>>>>          fldName=PTRACERS_names(nTrac)
>>>>          IF ( fldName(1:4) .EQ. 'apre' ) THEN
>>>>             itrc_apre=nTrac         
>>>>          ELSEIF ( fldName(1:4) .EQ. 'ppre' ) THEN
>>>>             itrc_ppre=nTrac
>>>>          ELSEIF ( fldName(1:7) .EQ. 'atmpco2' ) THEN
>>>>             itrc_pco2=nTrac
>>>>          ENDIF         
>>>>        ENDDO
>>> 
>>> I keep getting the following error and I am having a nightmare trying to figure out what is wrong:
>>> 
>>>> Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
>>>> 
>>>> Backtrace for this error:
>>>> #0  0x160a7fa52
>>>> #1  0x160a8021e
>>>> #2  0x7fff92dc9f19
>>>> #3  0x10f784c68
>>>> #4  0x10f739973
>>>> #5  0x10f74ae31
>>>> #6  0x10f972c95
>>>> #7  0x10f9b2818
>>>> #8  0x10f9b2910
>>>> #9  0x10f92a61d
>>>> #10  0x10f9bbdb8
>>>> Segmentation fault: 11
>>> 
>>> 
>>> I did think it might have something to do with interfering with the do-loop index, nTrac, but I tried it with a dumb counter with no success:
>>> 
>>>>        INTEGER nTrac,tmp1,tmp2,tmp3
>>>>        INTEGER itrc_apre,itrc_ppre,itrc_pco2 
>>>>        CHARACTER*(MAX_LEN_FNAM) fldName
>>>> 
>>>> [….reset preformed surface tracer concentration…]
>>> 
>>>>        tmp1=0
>>>>        DO nTrac=1,PTRACERS_numInUse
>>>>          fldName=PTRACERS_names(nTrac)
>>>>          tmp1=tmp1+1
>>>>          IF ( fldName(1:4) .EQ. 'apre' ) THEN
>>>>             itrc_apre=tmp1 
>>>>          ENDIF         
>>>>        ENDDO
>>>>  
>>>>        tmp2=0
>>>>        DO nTrac=1,PTRACERS_numInUse
>>>>          fldName=PTRACERS_names(nTrac)
>>>>          tmp2=tmp2+1
>>>>          IF ( fldName(1:4) .EQ. 'ppre' ) THEN
>>>>             itrc_ppre=tmp2
>>>>          ENDIF         
>>>>        ENDDO
>>>> 
>>>>        tmp3=0
>>>>        DO nTrac=1,PTRACERS_numInUse
>>>>          fldName=PTRACERS_names(nTrac)
>>>>          tmp3=tmp3+1
>>>>          IF ( fldName(1:7) .EQ. 'atmpco2' ) THEN
>>>>             itrc_pco2=tmp3
>>>>          ENDIF         
>>>>        ENDDO
>>> 
>>> I guess I will just have to hard code these locations in if not, but it would be nice to get this working! Thanks in advance!
>>> 
>>> Jon
>>> 
>>> ___________________________________________________________________________
>>> Dr. Jonathan M. Lauderdale
>>> Postdoctoral Research Associate
>>> Department of Earth, Atmosphere and Planetary Sciences 
>>> Massachusetts Institute of Technology 
>>> 77 Massachusetts Avenue 
>>> Cambridge, MA 02139, USA 
>>> Office: +1 617 324 3401 
>>> Cell   : +1 617 304 5661
>>> Email: <mailto:jml1 at mit.edu>
>>> Web: <http://eaps-www.mit.edu/paoc/people/jonathan-lauderdale>
>>> Association of Polar Early Career Scientists <http://www.apecs.is/>
>>> ___________________________________________________________________________
>>> 
>>> _______________________________________________
>>> MITgcm-support mailing list
>>> MITgcm-support at mitgcm.org
>>> http://mitgcm.org/mailman/listinfo/mitgcm-support
>> _______________________________________________
>> MITgcm-support mailing list
>> MITgcm-support at mitgcm.org
>> http://mitgcm.org/mailman/listinfo/mitgcm-support
> 
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mitgcm.org/pipermail/mitgcm-support/attachments/20150609/65f5d4b7/attachment-0001.htm>


More information about the MITgcm-support mailing list