<div dir="ltr"><div style class="markdown-here-wrapper"><p style="margin:1.2em 0px!important">Pierre,</p>
<p style="margin:1.2em 0px!important">Have you used a tool like Valgrind? There is a bit of a learning curve, but it is exceedingly useful.</p>
<p style="margin:1.2em 0px!important">A few comments:</p>
<p style="margin:1.2em 0px!important">1) For cases likes this gctortute(TRUE) in your R script helps those “for enough iterations in a loop…” bugs to present quickly. With gctorture(TRUE) I’m producing the crash with fewer than 50 iters.</p><p style="margin:1.2em 0px!important"></p><div class="gmail_default" style="font-size:small;display:inline">​2) What you are implementing has everything to do with RNGs, so setting the seed is useful for reproducibility​</div><div class="gmail_default" style="font-size:small;display:inline">​.​</div><br><p></p>
<p style="margin:1.2em 0px!important">2) I got useful messages from Valgrind after changing your prefix increments to postfix increments, but I didn’t before making that switch</p><div class="gmail_default" style="font-size:small;display:inline">​ (if I remember correctly)​</div>.<p></p>
<p style="margin:1.2em 0px!important">3) These msgs points me to these lines</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">            for(int i = 1; i < kappa+2; i++){
                phi_omega[i-1] = phi_C(arma::trans(omegas.row(i)),
                                       piks,muks,Cks,Gamma);
            }
            accept = all_C((phi_omega < Upsilon));
</code></pre><p style="margin:1.2em 0px!important">in <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">main_function_C()</code>. Pretty sure you have an “off by 1” error here. kappa is an int, phi_omega has kappa elements (in elements 0 through kappa -1), but you refer to elements 1-1=0 through kappa+1-1=kappa which is the position of the kappa+1st elem.</p>
<p style="margin:1.2em 0px!important">I switched your loop to <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">for(int i = 1; i < kappa+1; i++)</code> and it is running under Valgrind now (i.e. slowly) and it’s gotten farther than any other run thus far.</p><div class="gmail_default" style="font-size:small;display:inline">​ Without having a conceptual understanding of what you are trying to do, I have no idea if this is the right fix for you (and I may be mistaken altogether of course...).<br><br></div><div class="gmail_default" style="font-size:small;display:inline">HTH,<br></div><div class="gmail_default" style="font-size:small;display:inline">Jonathan​</div><p></p>
<div title="MDH:PGRpdiBjbGFzcz0iZ21haWxfZGVmYXVsdCIgc3R5bGU9ImZvbnQtc2l6ZTogc21hbGw7Ij5QaWVy
cmUsPGJyPjxicj5IYXZlIHlvdSB1c2VkIGEgdG9vbCBsaWtlIFZhbGdyaW5kPyBUaGVyZSBpcyBh
IGJpdCBvZiBhIGxlYXJuaW5nIGN1cnZlLCBidXQgaXQgaXMgZXhjZWVkaW5nbHkgdXNlZnVsLjxi
cj48YnI+PC9kaXY+PGRpdiBjbGFzcz0iZ21haWxfZGVmYXVsdCIgc3R5bGU9ImZvbnQtc2l6ZTog
c21hbGw7Ij5BIGZldyBjb21tZW50czo8YnI+PGJyPjEpIEZvciBjYXNlcyBsaWtlcyB0aGlzIGdj
dG9ydHV0ZShUUlVFKSBpbiB5b3VyIFIgc2NyaXB0IGhlbHBzIHRob3NlICJmb3IgZW5vdWdoIGl0
ZXJhdGlvbnMgaW4gYSBsb29wLi4uIiBidWdzIHRvIHByZXNlbnQgcXVpY2tseS4gV2l0aCBnY3Rv
cnR1cmUoVFJVRSkgSSdtIHByb2R1Y2luZyB0aGUgY3Jhc2ggd2l0aCBmZXdlciB0aGFuIDUwIGl0
ZXJzLjxicj48YnI+MikgSSBnb3QgdXNlZnVs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div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 7, 2014 at 8:17 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi Pierre,<br>
<span class=""><br>
On 8 October 2014 at 01:59, <a href="mailto:Pierre.Gloaguen@ifremer.fr">Pierre.Gloaguen@ifremer.fr</a> wrote:<br>
| I will do what I can to reduce the code and have to same error occuring.<br>
| Of course i don't expect you to read all of it :) I was just wondering<br>
| if that kind of memory problem occured before, and if has some<br>
| "typical/generic" solutions.<br>
| I will try to have a shortest code to exhibit.<br>
<br>
</span>Really appreciate it.<br>
<br>
Many of us found over the years that just by "creating a better example" to<br>
often drill down close enough to the problem core.<br>
<br>
And the easier you make it for folks to help you, the likier it is that some<br>
kind soul from around here can give you a hand.<br>
<br>
Just lowering the barriers, be it cognitive or just plain effort ...<br>
<br>
Best, Dirk<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div><span style="color:rgb(102,102,102);font-family:tahoma,sans-serif;font-size:small"><br></span></div><div><span style="color:rgb(102,102,102);font-family:tahoma,sans-serif;font-size:small">J.P. Olmsted</span><br></div><div><font><font color="#666666" face="tahoma, sans-serif"><a href="mailto:j.p.olmsted@gmail.com" target="_blank">j.p.olmsted@gmail.com</a></font></font></div></div>
</div>