Segfault with R.cached model

91 views
Skip to first unread message

Kodi Arfer

unread,
Jul 14, 2013, 3:58:44 PM7/14/13
to stan-...@googlegroups.com
Here is an R source file:

http://nopaste.me/paste/185351724651e2fbb5993c8

and here is the output I get when I run it:

http://nopaste.me/paste/86613175751e2fbd8a8abd

Sorry the R code and the model are so complicated. I had a lot of trouble getting even this far towards isolating the bug, because the segfault isn't reliable at all: all sorts of seemingly inconsequential changes can make it more or less likely. Even with the same file, the error doesn't happen every run, although it happens in most runs. But in the original context ( http://arfer.net/projects/builder ), with all the attending support code, it happens every time I attempt a large analysis. So, I'd be happy with a workaround in lieu of a fix.

Tell me if there's a way to provide a more informative backtrace.

Ben Goodrich

unread,
Jul 14, 2013, 7:37:42 PM7/14/13
to stan-...@googlegroups.com

For a model this complicated, we are going to need more help. There is a FAQ entry on run-time problems here

https://groups.google.com/d/msg/stan-users/4gv3fNCqSNk/FXHj6fn0SC0J

And there is a section on debugging compiled code here

http://cran.r-project.org/doc/manuals/R-exts.html#Debugging-compiled-code

So, if you start R with

R -d gdb

and execute

run

then in the R session that starts

library(rstan)
set_cppo
("debug")
source
("test.R")

you eventually get

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff258f596 in CppObject__finalize__rcpp__wrapper__(Rcpp::XPtr<Rcpp::class_Base, &(void Rcpp::standard_delete_finalizer<Rcpp::class_Base>(Rcpp::class_Base*))>, SEXPREC*) () from /usr/lib/R/site-library/Rcpp/libs/Rcpp.so
(gdb) bt
#0  0x00007ffff258f596 in CppObject__finalize__rcpp__wrapper__(Rcpp::XPtr<Rcpp::class_Base, &(void Rcpp::standard_delete_finalizer<Rcpp::class_Base>(Rcpp::class_Base*))>, SEXPREC*) () from /usr/lib/R/site-library/Rcpp/libs/Rcpp.so
#1  0x00007ffff25913d7 in CppObject__finalize () from /usr/lib/R/site-library/Rcpp/libs/Rcpp.so
#2  0x00007ffff79688ba in do_dotcall (call=0x2f4b688, op=<optimized out>, args=<optimized out>, env=0x3668f28) at dotcode.c:582
#3  0x00007ffff79a496c in Rf_eval (e=0x2f4b688, rho=rho@entry=0x3668f28) at eval.c:635
#4  0x00007ffff79a7410 in do_begin (call=0x2f4c5b8, op=0x6124f0, args=0x2f4b768, rho=0x3668f28) at eval.c:1557
#5  0x00007ffff79a4791 in Rf_eval (e=0x2f4c5b8, rho=0x3668f28) at eval.c:607
#6  0x00007ffff79a8719 in Rf_applyClosure (call=0x173b2c8, op=0x36c1f98, arglist=<optimized out>, rho=rho@entry=0x59f4100, suppliedenv=0x636b80) at eval.c:1003
#7  0x00007ffff799f0be in bcEval (body=body@entry=0x173b300, rho=rho@entry=0x59f4100, useCache=useCache@entry=TRUE) at eval.c:4567
#8  0x00007ffff79a4478 in Rf_eval (e=0x173b300, rho=0x59f4100) at eval.c:538
#9  0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x59f3fe8, op=op@entry=0x36a8f40, arglist=<optimized out>, rho=rho@entry=0x636b48, suppliedenv=0x636b80)
    at
eval.c:1003
#10 0x00007ffff79a4511 in Rf_eval (e=e@entry=0x59f3fe8, rho=0x636b48) at eval.c:654
#11 0x00007ffff79cf810 in R_RunWeakRefFinalizer (w=<optimized out>) at memory.c:1313
#12 0x00007ffff79cf9e2 in RunFinalizers () at memory.c:1357
#13 0x00007ffff79ce41c in R_gc_internal (size_needed=size_needed@entry=1) at memory.c:2707
#14 0x00007ffff79cfc0c in Rf_allocVector (type=type@entry=13, length=length@entry=1) at memory.c:2269
#15 0x00007ffff791208d in do_lapply (call=<optimized out>, op=<optimized out>, args=<optimized out>, rho=0x35aa6d0) at apply.c:62
#16 0x00007ffff79d1630 in do_internal (call=<optimized out>, op=<optimized out>, args=0x999720, env=0x35aa6d0) at names.c:1170
#17 0x00007ffff7997d3a in bcEval (body=body@entry=0x9963b8, rho=rho@entry=0x35aa6d0, useCache=useCache@entry=TRUE) at eval.c:4608
#18 0x00007ffff79a4478 in Rf_eval (e=0x9963b8, rho=0x35aa6d0) at eval.c:538
#19 0x00007ffff79a8719 in Rf_applyClosure (call=0x1c160d8, op=0x995b50, arglist=<optimized out>, rho=rho@entry=0x35aab30, suppliedenv=0x636b80) at eval.c:1003
#20 0x00007ffff799f0be in bcEval (body=body@entry=0x1c14cc0, rho=rho@entry=0x35aab30, useCache=useCache@entry=TRUE) at eval.c:4567
#21 0x00007ffff79a4478 in Rf_eval (e=0x1c14cc0, rho=0x35aab30) at eval.c:538
#22 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x16c0178, op=op@entry=0x1c14e80, arglist=<optimized out>, rho=rho@entry=0x35aa060, suppliedenv=0x636b80)
    at
eval.c:1003
#23 0x00007ffff79a4511 in Rf_eval (e=0x16c0178, rho=rho@entry=0x35aa060) at eval.c:654
#24 0x00007ffff79a5d3e in Rf_evalList (el=0x16c0140, rho=rho@entry=0x35aa060, call=call@entry=0x16c0108, n=1, n@entry=0) at eval.c:1985
#25 0x00007ffff79a485f in Rf_eval (e=0x16c0108, rho=rho@entry=0x35aa060) at eval.c:626
#26 0x00007ffff79a5aee in Rf_evalListKeepMissing (el=0x16c0098, rho=rho@entry=0x35aa060) at eval.c:2049
#27 0x00007ffff79a5f5c in evalArgs (el=<optimized out>, rho=rho@entry=0x35aa060, dropmissing=dropmissing@entry=0, call=call@entry=0x16c1320, n=n@entry=1)
    at
eval.c:2343
#28 0x00007ffff79a61ec in Rf_DispatchOrEval (call=call@entry=0x16c1320, op=op@entry=0x6122c0, generic=generic@entry=0x7ffff7aa01a2 "[", args=0x16c1358,
    rho
=rho@entry=0x35aa060, ans=ans@entry=0x7ffffffeee28, dropmissing=dropmissing@entry=0, argsevald=argsevald@entry=0) at eval.c:2526
#29 0x00007ffff7a28fb2 in do_subset (call=0x16c1320, op=0x6122c0, args=<optimized out>, rho=0x35aa060) at subset.c:621
#30 0x00007ffff79a4791 in Rf_eval (e=0x16c1320, rho=rho@entry=0x35aa060) at eval.c:607
#31 0x00007ffff79a7230 in do_set (call=0x16c1240, op=0x6126e8, args=0x16c1278, rho=0x35aa060) at eval.c:1871
#32 0x00007ffff79a4791 in Rf_eval (e=0x16c1240, rho=0x35aa060) at eval.c:607
#33 0x00007ffff79a4791 in Rf_eval (e=0x16c1048, rho=rho@entry=0x35aa060) at eval.c:607
#34 0x00007ffff79a7410 in do_begin (call=0x16c0d00, op=0x6124f0, args=0x16c1010, rho=0x35aa060) at eval.c:1557
#35 0x00007ffff79a4791 in Rf_eval (e=0x16c0d00, rho=0x35aa060) at eval.c:607
#36 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x16c27c0, op=op@entry=0x16c1d98, arglist=<optimized out>, rho=rho@entry=0x35aa1b0, suppliedenv=0x636b80)
    at
eval.c:1003
---Type <return> to continue, or q <return> to quit---
#37 0x00007ffff79a4511 in Rf_eval (e=0x16c27c0, rho=0x35aa1b0) at eval.c:654
#38 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x16c6a00, op=op@entry=0x16c3858, arglist=<optimized out>, rho=rho@entry=0x35a9cc8, suppliedenv=0x636b80)
    at
eval.c:1003
#39 0x00007ffff79a4511 in Rf_eval (e=0x16c6a00, rho=rho@entry=0x35a9cc8) at eval.c:654
#40 0x00007ffff79a7230 in do_set (call=0x16c68e8, op=0x6126e8, args=0x16c6920, rho=0x35a9cc8) at eval.c:1871
#41 0x00007ffff79a4791 in Rf_eval (e=0x16c68e8, rho=rho@entry=0x35a9cc8) at eval.c:607
#42 0x00007ffff79a7410 in do_begin (call=0x16c7268, op=0x6124f0, args=0x16c7818, rho=0x35a9cc8) at eval.c:1557
#43 0x00007ffff79a4791 in Rf_eval (e=0x16c7268, rho=0x35a9cc8) at eval.c:607
#44 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x16da2d8, op=op@entry=0x16c7be8, arglist=<optimized out>, rho=rho@entry=0x59f2e70, suppliedenv=0x636b80)
    at
eval.c:1003
#45 0x00007ffff79a4511 in Rf_eval (e=0x16da2d8, rho=rho@entry=0x59f2e70) at eval.c:654
#46 0x00007ffff79a7410 in do_begin (call=0x16da070, op=0x6124f0, args=0x16da2a0, rho=0x59f2e70) at eval.c:1557
#47 0x00007ffff79a4791 in Rf_eval (e=0x16da070, rho=0x59f2e70) at eval.c:607
#48 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x16dcbc8, op=op@entry=0x16da9f0, arglist=<optimized out>, rho=rho@entry=0x3752aa8, suppliedenv=0x636b80)
    at
eval.c:1003
#49 0x00007ffff79a4511 in Rf_eval (e=0x16dcbc8, rho=rho@entry=0x3752aa8) at eval.c:654
#50 0x00007ffff79a7410 in do_begin (call=0x16dd1c8, op=0x6124f0, args=0x16dcb90, rho=0x3752aa8) at eval.c:1557
#51 0x00007ffff79a4791 in Rf_eval (e=0x16dd1c8, rho=0x3752aa8) at eval.c:607
#52 0x00007ffff79a8719 in Rf_applyClosure (call=0x1d68bb8, op=0x16dd9c0, arglist=<optimized out>, rho=rho@entry=0x2f27308, suppliedenv=0x636b80) at eval.c:1003
#53 0x00007ffff799f0be in bcEval (body=body@entry=0x1d68950, rho=rho@entry=0x2f27308, useCache=useCache@entry=TRUE) at eval.c:4567
#54 0x00007ffff79a4478 in Rf_eval (e=0x1d68950, rho=0x2f27308) at eval.c:538
#55 0x00007ffff79a8719 in Rf_applyClosure (call=0x1d8a198, op=0x1d6c6e0, arglist=<optimized out>, rho=rho@entry=0x2f273e8, suppliedenv=0x636b80) at eval.c:1003
#56 0x00007ffff799f0be in bcEval (body=body@entry=0x1d8a048, rho=rho@entry=0x2f273e8, useCache=useCache@entry=TRUE) at eval.c:4567
#57 0x00007ffff79a4478 in Rf_eval (e=0x1d8a048, rho=0x2f273e8) at eval.c:538
#58 0x00007ffff79a8719 in Rf_applyClosure (call=0x1dab370, op=0x1da5df8, arglist=<optimized out>, rho=rho@entry=0x155e9c0, suppliedenv=0x636b80) at eval.c:1003
#59 0x00007ffff799f0be in bcEval (body=body@entry=0x1dad480, rho=rho@entry=0x155e9c0, useCache=useCache@entry=TRUE) at eval.c:4567
#60 0x00007ffff79a4478 in Rf_eval (e=0x1dad480, rho=0x155e9c0) at eval.c:538
#61 0x00007ffff79a8719 in Rf_applyClosure (call=0x2098d18, op=0x1dadd90, arglist=<optimized out>, rho=rho@entry=0x16de9b0, suppliedenv=0x636b80) at eval.c:1003
#62 0x00007ffff799f0be in bcEval (body=body@entry=0x20c9498, rho=rho@entry=0x16de9b0, useCache=useCache@entry=TRUE) at eval.c:4567
#63 0x00007ffff79a4478 in Rf_eval (e=0x20c9498, rho=0x16de9b0) at eval.c:538
#64 0x00007ffff79a8719 in Rf_applyClosure (call=0x20d3228, op=0x20ca5d8, arglist=<optimized out>, rho=rho@entry=0x16df218, suppliedenv=0x636b80) at eval.c:1003
#65 0x00007ffff799f0be in bcEval (body=body@entry=0x20d3d30, rho=rho@entry=0x16df218, useCache=useCache@entry=TRUE) at eval.c:4567
#66 0x00007ffff79a4478 in Rf_eval (e=0x20d3d30, rho=0x16df218) at eval.c:538
#67 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x2764268, op=op@entry=0x20d4560, arglist=<optimized out>, rho=rho@entry=0x3008d00, suppliedenv=0x636b80)
    at
eval.c:1003
#68 0x00007ffff79a4511 in Rf_eval (e=0x2764268, rho=rho@entry=0x3008d00) at eval.c:654
#69 0x00007ffff79a7230 in do_set (call=0x27641c0, op=0x6126e8, args=0x27641f8, rho=0x3008d00) at eval.c:1871
#70 0x00007ffff79a4791 in Rf_eval (e=0x27641c0, rho=rho@entry=0x3008d00) at eval.c:607
#71 0x00007ffff79a7410 in do_begin (call=0x2764a60, op=0x6124f0, args=0x2764188, rho=0x3008d00) at eval.c:1557
#72 0x00007ffff79a4791 in Rf_eval (e=e@entry=0x2764a60, rho=rho@entry=0x3008d00) at eval.c:607
#73 0x00007ffff79a948e in do_for (call=0x2764910, op=0x6105f0, args=0x2764948, rho=0x3008d00) at eval.c:1453
#74 0x00007ffff79a4791 in Rf_eval (e=0x2764910, rho=rho@entry=0x3008d00) at eval.c:607
#75 0x00007ffff79a7410 in do_begin (call=0x27676e8, op=0x6124f0, args=0x27648d8, rho=0x3008d00) at eval.c:1557
---Type <return> to continue, or q <return> to quit---
#76 0x00007ffff79a4791 in Rf_eval (e=0x27676e8, rho=0x3008d00) at eval.c:607
#77 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x22eb888, op=op@entry=0x2767ea8, arglist=<optimized out>, rho=rho@entry=0x3427728, suppliedenv=0x636b80)
    at
eval.c:1003
#78 0x00007ffff79a4511 in Rf_eval (e=0x22eb888, rho=rho@entry=0x3427728) at eval.c:654
#79 0x00007ffff79a7410 in do_begin (call=0x22eb818, op=0x6124f0, args=0x22eb850, rho=0x3427728) at eval.c:1557
#80 0x00007ffff79a4791 in Rf_eval (e=0x22eb818, rho=0x3427728) at eval.c:607
#81 0x00007ffff79a4791 in Rf_eval (e=0x22eb658, rho=rho@entry=0x3427728) at eval.c:607
#82 0x00007ffff79a7410 in do_begin (call=0x22eb3f0, op=0x6124f0, args=0x22eb620, rho=0x3427728) at eval.c:1557
#83 0x00007ffff79a4791 in Rf_eval (e=0x22eb3f0, rho=0x3427728) at eval.c:607
#84 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x1b2c370, op=op@entry=0x22ebe50, arglist=<optimized out>, rho=rho@entry=0x34275d8, suppliedenv=0x636b80)
    at
eval.c:1003
#85 0x00007ffff79a4511 in Rf_eval (e=0x1b2c370, rho=rho@entry=0x34275d8) at eval.c:654
#86 0x00007ffff79a7230 in do_set (call=0x1b2c290, op=0x6126e8, args=0x1b2c2c8, rho=0x34275d8) at eval.c:1871
#87 0x00007ffff79a4791 in Rf_eval (e=0x1b2c290, rho=rho@entry=0x34275d8) at eval.c:607
#88 0x00007ffff79a7410 in do_begin (call=0x1b2c220, op=0x6124f0, args=0x1b2c258, rho=0x34275d8) at eval.c:1557
#89 0x00007ffff79a4791 in Rf_eval (e=0x1b2c220, rho=0x34275d8) at eval.c:607
#90 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x3427140, op=0x1b2ccf0, arglist=<optimized out>, rho=0x21f7090, rho@entry=0x7ffff4d46520,
    suppliedenv
=0x636b80) at eval.c:1003
#91 0x00007ffff79d65c5 in R_possible_dispatch (call=call@entry=0x3427140, op=op@entry=0x612250, args=args@entry=0x34274c0, rho=0x7ffff4d46520, rho@entry=0x21f7090,
    promisedArgs
=promisedArgs@entry=TRUE) at objects.c:1447
#92 0x00007ffff79a6275 in Rf_DispatchOrEval (call=call@entry=0x3427140, op=op@entry=0x612250, generic=generic@entry=0x7ffff7a959c5 "$", args=args@entry=0x34273e0,
    rho
=rho@entry=0x21f7090, ans=ans@entry=0x7fffffff61e8, dropmissing=dropmissing@entry=0, argsevald=argsevald@entry=0) at eval.c:2456
#93 0x00007ffff7a2a138 in do_subset3 (call=0x3427140, op=0x612250, args=0x34273e0, env=0x21f7090) at subset.c:1094
#94 0x00007ffff79a4791 in Rf_eval (e=0x3427140, rho=0x21f7090) at eval.c:607
#95 0x00007ffff79a5787 in do_eval (call=0x91fd40, op=0x62a4a0, args=0x3427178, rho=0x2ed7988) at eval.c:2236
#96 0x00007ffff7999874 in bcEval (body=body@entry=0x91fec8, rho=rho@entry=0x2ed7988, useCache=useCache@entry=TRUE) at eval.c:4587
#97 0x00007ffff79a4478 in Rf_eval (e=0x91fec8, rho=0x2ed7988) at eval.c:538
#98 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x28ac9c8, op=op@entry=0x91f900, arglist=<optimized out>, rho=rho@entry=0x21f7090, suppliedenv=0x636b80)
    at
eval.c:1003
#99 0x00007ffff79a4511 in Rf_eval (e=0x28ac9c8, rho=rho@entry=0x21f7090) at eval.c:654
#100 0x00007ffff79a7230 in do_set (call=0x28aca70, op=0x6126e8, args=0x28aca38, rho=0x21f7090) at eval.c:1871
#101 0x00007ffff79a4791 in Rf_eval (e=0x28aca70, rho=rho@entry=0x21f7090) at eval.c:607
#102 0x00007ffff79a7410 in do_begin (call=0x28ac160, op=0x6124f0, args=0x28acaa8, rho=0x21f7090) at eval.c:1557
#103 0x00007ffff79a4791 in Rf_eval (e=0x28ac160, rho=0x21f7090) at eval.c:607
#104 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x28b5cd0, op=op@entry=0x28ab7a8, arglist=<optimized out>, rho=rho@entry=0x21f82e8, suppliedenv=0x636b80)
    at
eval.c:1003
#105 0x00007ffff79a4511 in Rf_eval (e=0x28b5cd0, rho=rho@entry=0x21f82e8) at eval.c:654
#106 0x00007ffff79a7410 in do_begin (call=0x28ab8c0, op=0x6124f0, args=0x28b5d08, rho=0x21f82e8) at eval.c:1557
#107 0x00007ffff79a4791 in Rf_eval (e=0x28ab8c0, rho=rho@entry=0x21f82e8) at eval.c:607
#108 0x00007ffff79a8044 in R_execClosure (call=0x134c728, op=op@entry=0x28a5ab0, arglist=<optimized out>, rho=0x226b4e0, newrho=newrho@entry=0x21f82e8) at eval.c:1099
#109 0x00007ffff79a8397 in R_execMethod (op=op@entry=0x28a5ab0, rho=rho@entry=0x21fbae8) at eval.c:1188
#110 0x00007ffff402be4e in R_dispatchGeneric (fname=0x289cf08, ev=0x21fbae8, fdef=0x21fbb58) at methods_list_dispatch.c:1029
#111 0x00007ffff79d5883 in do_standardGeneric (call=<optimized out>, op=<optimized out>, args=<optimized out>, env=0x21fbae8) at objects.c:1142
---Type <return> to continue, or q <return> to quit---
#112 0x00007ffff79a48bb in Rf_eval (e=0x289c610, rho=rho@entry=0x21fbae8) at eval.c:639
#113 0x00007ffff79a7410 in do_begin (call=0x289c680, op=0x6124f0, args=0x289c648, rho=0x21fbae8) at eval.c:1557
#114 0x00007ffff79a4791 in Rf_eval (e=0x289c680, rho=0x21fbae8) at eval.c:607
#115 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x134c728, op=op@entry=0x2871328, arglist=<optimized out>, rho=rho@entry=0x226b4e0, suppliedenv=0x636b80)
    at
eval.c:1003
#116 0x00007ffff79a4511 in Rf_eval (e=0x134c728, rho=rho@entry=0x226b4e0) at eval.c:654
#117 0x00007ffff79a7230 in do_set (call=0x134d5e8, op=0x6126e8, args=0x134c6b8, rho=0x226b4e0) at eval.c:1871
#118 0x00007ffff79a4791 in Rf_eval (e=0x134d5e8, rho=rho@entry=0x226b4e0) at eval.c:607
#119 0x00007ffff79a7410 in do_begin (call=0x134b768, op=0x6124f0, args=0x134d508, rho=0x226b4e0) at eval.c:1557
#120 0x00007ffff79a4791 in Rf_eval (e=0x134b768, rho=0x226b4e0) at eval.c:607
#121 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x1376948, op=op@entry=0x24e7158, arglist=<optimized out>, rho=rho@entry=0x636b48, suppliedenv=0x636b80)
    at
eval.c:1003
#122 0x00007ffff79a4511 in Rf_eval (e=0x1376948, rho=0x636b48) at eval.c:654
#123 0x00007ffff79a4b2b in forcePromise (e=0x226bfe8) at eval.c:458
#124 0x00007ffff79a49f2 in Rf_eval (e=<optimized out>, rho=rho@entry=0x226c1e0) at eval.c:561
#125 0x00007ffff79a5d3e in Rf_evalList (el=0x136c890, rho=rho@entry=0x226c1e0, call=call@entry=0x136c858, n=1, n@entry=0) at eval.c:1985
#126 0x00007ffff79a485f in Rf_eval (e=0x136c858, rho=rho@entry=0x226c1e0) at eval.c:626
#127 0x00007ffff79a61c0 in Rf_DispatchOrEval (call=call@entry=0x136c708, op=op@entry=0x612288, generic=generic@entry=0x7ffff7a96629 "[[", args=0x136c740,
    rho
=rho@entry=0x226c1e0, ans=ans@entry=0x7fffffff9568, dropmissing=dropmissing@entry=0, argsevald=argsevald@entry=0) at eval.c:2437
#128 0x00007ffff7a29a72 in do_subset2 (call=0x136c708, op=0x612288, args=<optimized out>, rho=0x226c1e0) at subset.c:850
#129 0x00007ffff79a4791 in Rf_eval (e=0x136c708, rho=rho@entry=0x226c1e0) at eval.c:607
#130 0x00007ffff79a7230 in do_set (call=0x136c660, op=0x612640, args=0x136c698, rho=0x226c1e0) at eval.c:1871
#131 0x00007ffff79a4791 in Rf_eval (e=0x136c660, rho=rho@entry=0x226c1e0) at eval.c:607
#132 0x00007ffff79a7410 in do_begin (call=0x136c628, op=0x6124f0, args=0x136c4d8, rho=0x226c1e0) at eval.c:1557
#133 0x00007ffff79a4791 in Rf_eval (e=0x136c628, rho=0x226c1e0) at eval.c:607
#134 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x1376638, op=op@entry=0x241cbe8, arglist=<optimized out>, rho=rho@entry=0x636b48, suppliedenv=0x636b80)
    at
eval.c:1003
#135 0x00007ffff79a4511 in Rf_eval (e=0x1376638, rho=rho@entry=0x636b48) at eval.c:654
#136 0x00007ffff79a7410 in do_begin (call=0x1375cf0, op=0x6124f0, args=0x1376558, rho=0x636b48) at eval.c:1557
#137 0x00007ffff79a4791 in Rf_eval (e=e@entry=0x1375cf0, rho=rho@entry=0x636b48) at eval.c:607
#138 0x00007ffff79a948e in do_for (call=0x13762b8, op=0x6105f0, args=0x13762f0, rho=0x636b48) at eval.c:1453
#139 0x00007ffff79a4791 in Rf_eval (e=0x13762b8, rho=0x636b48) at eval.c:607
#140 0x00007ffff79a58e8 in do_eval (call=0x91fd40, op=0x62a4a0, args=0x1, rho=0x2403ee8) at eval.c:2257
#141 0x00007ffff7999874 in bcEval (body=body@entry=0x91fec8, rho=rho@entry=0x2403ee8, useCache=useCache@entry=TRUE) at eval.c:4587
#142 0x00007ffff79a4478 in Rf_eval (e=0x91fec8, rho=0x2403ee8) at eval.c:538
#143 0x00007ffff79a8719 in Rf_applyClosure (call=0x12f7238, op=0x91f900, arglist=<optimized out>, rho=rho@entry=0x12fc848, suppliedenv=0x636b80) at eval.c:1003
#144 0x00007ffff799f0be in bcEval (body=body@entry=0x12fbf70, rho=rho@entry=0x12fc848, useCache=useCache@entry=TRUE) at eval.c:4567
#145 0x00007ffff79a4478 in Rf_eval (e=0x12fbf70, rho=0x12fc848) at eval.c:538
#146 0x00007ffff79a4b2b in forcePromise (e=0x2404b78) at eval.c:458
#147 0x00007ffff79a49f2 in Rf_eval (e=<optimized out>, rho=rho@entry=0x2403cb8) at eval.c:561
#148 0x00007ffff79a5067 in do_withVisible (call=<optimized out>, op=<optimized out>, args=0x13777b8, rho=0x2403cb8) at eval.c:2284
#149 0x00007ffff79d1630 in do_internal (call=<optimized out>, op=<optimized out>, args=0x13777b8, env=0x2403cb8) at names.c:1170
#150 0x00007ffff7997d3a in bcEval (body=body@entry=0x1377898, rho=rho@entry=0x2403cb8, useCache=useCache@entry=TRUE) at eval.c:4608
---Type <return> to continue, or q <return> to quit---
#151 0x00007ffff79a4478 in Rf_eval (e=0x1377898, rho=0x2403cb8) at eval.c:538
#152 0x00007ffff79a8719 in Rf_applyClosure (call=0x12f72a8, op=0x1377908, arglist=<optimized out>, rho=rho@entry=0x12fc848, suppliedenv=0x636b80) at eval.c:1003
#153 0x00007ffff799f0be in bcEval (body=body@entry=0x12e6b30, rho=rho@entry=0x12fc848, useCache=useCache@entry=TRUE) at eval.c:4567
#154 0x00007ffff79a4478 in Rf_eval (e=0x12e6b30, rho=0x12fc848) at eval.c:538
#155 0x00007ffff79a8719 in Rf_applyClosure (call=call@entry=0x12e6530, op=op@entry=0x12e6300, arglist=<optimized out>, rho=rho@entry=0x636b48, suppliedenv=0x636b80)
    at
eval.c:1003
#156 0x00007ffff79a4511 in Rf_eval (e=e@entry=0x12e6530, rho=rho@entry=0x636b48) at eval.c:654
#157 0x00007ffff79c7a35 in Rf_ReplIteration (rho=rho@entry=0x636b48, savestack=savestack@entry=0, browselevel=browselevel@entry=0, state=state@entry=0x7fffffffd010)
    at main
.c:258
#158 0x00007ffff79c7c68 in R_ReplConsole (rho=0x636b48, savestack=savestack@entry=0, browselevel=browselevel@entry=0) at main.c:307
#159 0x00007ffff79c8170 in run_Rmainloop () at main.c:986
#160 0x00007ffff79c81c2 in Rf_mainloop () at main.c:993
#161 0x00000000004007fb in main (ac=ac@entry=1, av=av@entry=0x7fffffffe148) at Rmain.c:32
#162 0x00007ffff7127995 in __libc_start_main (main=0x4007e0 <main>, argc=1, ubp_av=0x7fffffffe148, init=<optimized out>, fini=<optimized out>,
    rtld_fini
=<optimized out>, stack_end=0x7fffffffe138) at libc-start.c:260
#163 0x000000000040082d in _start ()

I certainly can't rule out the possibility that this is a (R)Stan problem, but at first glance it looks like an Rcpp problem during compilation. If you go to to the top of the backtrace, those are all references to Rcpp functions or R functions, rather than what we usually see with a Stan problem which is a reference to a line in the C++ file generated by Stan.

It might also be some sort of interaction with the R.cache package (which I had never used before). There are a bunch of error messages that come up before the segfault that also do not appear to have anything to do with RStan but might suggest the root of problem.

Anyway, you can poke around under GDB some more, maybe Google some of these error messages, ask on the Rcpp list, etc. If you can simplify it down a lot more and / or produce something that more convincingly points to a problem in RStan, then we can look at it more closely.

Ben

Jiqiang Guo

unread,
Jul 14, 2013, 8:29:35 PM7/14/13
to stan-...@googlegroups.com
As Ben pointed out, you can first try not to use R.cache package, which is not necessary at all when using RStan.  Sampling can always be done for a compiled model with different data and other inputs so compiling is needed just once for the same model.  

And I am afraid that the problem is that R.cache does not handle objects created in RStan, which has a dynamic shared object created from compiling the C++ code.  From the description, I guess that after the dynamic shared object was unloaded by R (this happens automatically by R at a time that is not determined by the user), R.cache cannot load the dynamic shared object and thus a segfault follows.  

--
Jiqiang 

Jiqiang Guo

unread,
Jul 14, 2013, 11:42:58 PM7/14/13
to stan-...@googlegroups.com
My guess is not quite right about why the segfault happens.  But the problem does has to do with package R.cache and R's garbage collector. 

The problem with using R.cache is that every time it loads the cache, the same DSO (though with different file names) would be loaded again, which seems to cause some problem (I still do not know why it is problematic and that is why now in RStan if you compile the same model from its Stan code the generated DSO will be different).  The following R code would always create this type of segfault.  So my advice for this problem is not to use package R.cache.   

library(rstan)
library(R.cache)
testcode <- '
 parameters {
   real y;
 }
 model {
   y ~ normal(0, 1);
 }
'

sm <- stan_model(model_code = testcode)
k <- list(code = testcode)
saveCache(sm, key = k)
rm(sm)
base::gc()

sm <- loadCache(key = k)
f <- sampling(sm, chains = 1, iter = 10)

sm2 <- loadCache(key = k)
f2 <- sampling(sm2)
rm(sm2)
rm(f2)
gc()
rm(f)
gc()

--
Jiqiang 

Kodi Arfer

unread,
Jul 15, 2013, 12:23:16 PM7/15/13
to stan-...@googlegroups.com
Thanks for your thoughtful replies, folks.

My use for R.cache is to avoid having to recompile a model each time I start up R. I *can* simply avoid reloading the cached copy of the model once the current R process has done it once, and I found that if I do this, I can avoid segfaults in my original analysis (hooray!). But, if I understand correct, this still isn't entirely safe. I assume that using the stock save() and load() would be no better. Is there then no officially supported way to avoid recompiling the model for each R process? I opine that there should be. Compilation isn't fast.

Jiqiang Guo

unread,
Jul 15, 2013, 1:44:37 PM7/15/13
to stan-...@googlegroups.com
As the problem lies in loading a dynamic shared object multiple times, it is fine to use R.cache and R's save/load functions. 
But in each R session, just use it once.  So in your code, you can have the stanmodel object loaded by using loadCache once, not 200 times.

--
Jiqiang 

On Mon, Jul 15, 2013 at 12:23 PM, Kodi Arfer <kodi...@gmail.com> wrote:
Thanks for your thoughtful replies, folks.

My use for R.cache is to avoid having to recompile a model each time I start up R. I *can* simply avoid reloading the cached copy of the model once the current R process has done it once, and I found that if I do this, I can avoid segfaults in my original analysis (hooray!). But, if I understand correct, this still isn't entirely safe. I assume that using the stock save() and load() would be no better. Is there then no officially supported way to avoid recompiling the model for each R process? I opine that there should be. Compilation isn't fast.

--
You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kodi Arfer

unread,
Jul 16, 2013, 7:47:30 AM7/16/13
to stan-...@googlegroups.com
On Monday, July 15, 2013 1:44:37 PM UTC-4, Jiqiang Guo wrote:
As the problem lies in loading a dynamic shared object multiple times, it is fine to use R.cache and R's save/load functions. 
But in each R session, just use it once.  So in your code, you can have the stanmodel object loaded by using loadCache once, not 200 times.

Well, that works fine for me. Thanks again.
Reply all
Reply to author
Forward
0 new messages