[Mesa-users] Pointer error with free_star

Warrick Ball wball at bison.ph.bham.ac.uk
Fri Dec 15 08:52:25 EST 2017


Hi everyone,

I'm collaborating on an application that will use MESA as a library to evaluate 
a *lot* of stellar models.  I'm not sure exactly how many but the only relevant 
point here is that I need to release star pointers.

We found that we couldn't make more than ten models and traced that back to a 
hardcoded maximum number of pointers on line 110 of 
`$MESA_DIR/star/public/star_def.f90` (r10108).

       integer, parameter :: max_star_handles = 10 ! this can be increased as 
necessary

Granted, one option is to increase this number to something more suitable but 
we are calling `free_star` from `star_lib` after each evolutionary run, which 
should be releasing star handles.  I also noticed that with each new model, 
MESA would consume another ~0.6% of my 16 GB of RAM, which is about 100MB 
(though our code uses r9793 so newer versions might behave better).

So I started following function calls and noticed this in `star_lib` (lines 
65--75):

        subroutine free_star(id, ierr)
           use alloc, only: free_star_data
          !  frees the handle and all associated data
           integer, intent(in) :: id
           integer, intent(out) :: ierr

           ierr = 0
           return  ! skip this for now

           call free_star_data(id, ierr)
        end subroutine free_star

Note the line that says "skip this for now"!  The subroutine doesn't actually 
release the pointer.  Naturally, I tried commenting that line and running our 
code again but ran into an error that I haven't been able to debug.

I've written a small program (attached, with Makefile) that demonstrates the 
problem.  It allocates a new star pointer, creates a pre-MS model, then 
releases the pointer, twice.  If you comment out the early return above, the 
second iteration fails with the error


*** Error in `./test_free_star': double free or corruption (!prev): 
0x000000000684f760 ***

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x7f1d3786471f in ???
#1  0x7f1d3786469b in ???
#2  0x7f1d378663b0 in ???
#3  0x7f1d378aea86 in ???
#4  0x7f1d378b5e8d in ???
#5  0x7f1d378b7988 in ???
#6  0x7f1d378c02ed in ???
#7  0x7968b1 in __net_def_MOD_do_free_net
 	at ../public/net_def.f90:384
#8  0x49710b in __net_MOD_set_net
 	at ../private/net.f90:639
#9  0x560b9f in model_builder
 	at ../private/init.f90:1191
#10  0x561434 in __init_MOD_create_pre_ms_model
 	at ../private/init.f90:1014
#11  0x418448 in __star_lib_MOD_star_create_pre_ms_model
 	at ../public/star_lib.f90:378
#12  0x414971 in ???
#13  0x414a83 in ???
#14  0x7f1d3784e039 in ???
#15  0x414489 in ???
#16  0xffffffffffffffff in ???
Aborted (core dumped)


I've looked at the listed functions but can't see that there's a problem. The 
error crops up at the start of the pre-MS subroutine, where it sets the nuclear 
reaction network (`set_net`).  That checks if there's currently a net and, if 
not, releases the existing one (`do_free_net`). But that then crashes, 
apparently, as far as I can tell, because of g% net_iso.  From 
`$MESA_DIR/net/public/net_def.f90`, lines 383--386:

              if (associated(g% net_iso)) then
                 deallocate(g% net_iso)
                    nullify(g% net_iso)
              end if

I think these are the guilty lines because I sprinkled `write` statements 
everywhere and then tried moving this up and down the sequence of `deallocate` 
statements.

The only guidance I can find online is that something appears to be corrupting 
the array structure, possibly by going out of bounds but I have no idea how to 
track this down in the code.  One option appears to be to call `deallocate` 
with an error integer, in which case the code won't crash and I can maybe just 
ignore the error.  But I'm a bit far beyond the limits of my 
knowledge/debugging skills and would appreciate any advice anyone can offer.

Thanks,
Warrick

PS:  Hoping the embarassingly-subjectless version of this message is 
swallowed in the ether...


------------
Warrick Ball
Postdoc, School of Physics and Astronomy
University of Birmingham, Edgbaston, Birmingham B15 2TT
wball at bison.ph.bham.ac.uk
+44 (0)121 414 4552
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_free_star.f90
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20171215/b533600e/attachment.ksh>
-------------- next part --------------
FC=gfortran

#MODPATH = ${MESA_DIR}/include ${MESASDK_ROOT}/include # ${GYRE_DIR}/src/build
INCLUDE = -I${MESA_DIR}/include -I${MESASDK_ROOT}/include # ${GYRE_DIR}/src/build
MESA_LIB_DIR = $(MESA_DIR)/lib
LOAD_PGPLOT = `mesasdk_pgplot_link`
LOAD_LAPACK = `mesasdk_lapack_link`
LOAD_BLAS = `mesasdk_blas_link`
LOAD_HDF5 = `mesasdk_hdf5_link`
LOAD_CRLIBM = -lcrlibm
LOAD_MATRIX = -lf2crlibm $(LOAD_CRLIBM) -lmtx -lconst -lutils $(LOAD_LAPACK) $(LOAD_BLAS) # -lmesaklu
LOAD_MESA_NUMERICS = -linterp_2d -linterp_1d -lnum $(LOAD_MATRIX) $(LOAD_HDF5)
LOAD_MESA_MICRO = -lnet -leos -lkap -lrates -lneu -lchem $(LOAD_MESA_NUMERICS)
LOAD_MESA_MACRO = -lionization -latm -lcolors -lmlt $(LOAD_MESA_MICRO)
LOAD_MESA_STAR_SUPPORT = $(LOAD_MESA_MACRO)
LOAD_STAR_MODS = -lstar $(LOAD_MESA_STAR_SUPPORT)
STAR_LOAD_LIST = $(LOAD_STAR_MODS) $(LOAD_PGPLOT) $(LOAD_SE)
LOAD_MESA_STAR = -L$(MESA_LIB_DIR) $(STAR_LOAD_LIST)
LDFLAGS = ${LOAD_MESA_STAR} -lz

vpath %.mod ${MODPATH}

test_free_star: test_free_star.f90
	$(FC) -o test_free_star test_free_star.f90 $(LDFLAGS) $(INCLUDE) -fopenmp

.PHONY: clean

clean:
	rm -f test_free_star


More information about the Mesa-users mailing list