[Rcpp-devel] R session crashes when largely using a Rcpp sourced function

Pierre.Gloaguen at ifremer.fr Pierre.Gloaguen at ifremer.fr
Wed Oct 8 08:18:31 CEST 2014


Hello Jonathan,

Thanks a lot for your help.

I didn't know valgrind, but i'll definitely go into it. Thanks very  
much for your help.

So, you think I should go to postfix increments instead of prefix?
I'm a beginner in C++, so I'm not comfortable on which of them to chose.

You seem to be right on my mistake on the loop, I'll check it more  
carefuly tomorow.

If it still don't work after these fixings, I'll try to have a shorter  
version as Dirk suggested, so it will be easier to point out mistakes  
from this whole code.

Again, thank you for your help, and if you're interested I could  
describe you in details the goals of this code (i guess it's not the  
purpose of tis list)
I'll let you know!

Pierre


Jonathan Olmsted <jpolmsted at gmail.com> a écrit :

> Pierre,
>
> Have you used a tool like Valgrind? There is a bit of a learning curve, but
> it is exceedingly useful.
>
> A few comments:
>
> 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.
>
> ​2) What you are implementing has everything to do with RNGs, so setting
> the seed is useful for reproducibility​
> ​.​
>
> 2) I got useful messages from Valgrind after changing your prefix
> increments to postfix increments, but I didn’t before making that switch
> ​ (if I remember correctly)​
> .
>
> 3) These msgs points me to these lines
>
>             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));
>
> in main_function_C(). 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.
>
> I switched your loop to for(int i = 1; i < kappa+1; i++) and it is running
> under Valgrind now (i.e. slowly) and it’s gotten farther than any other run
> thus far.
> ​ 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...).
>
> HTH,
> Jonathan​
>
>>
> On Tue, Oct 7, 2014 at 8:17 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
>>
>> Hi Pierre,
>>
>> On 8 October 2014 at 01:59, Pierre.Gloaguen at ifremer.fr wrote:
>> | I will do what I can to reduce the code and have to same error occuring.
>> | Of course i don't expect you to read all of it :) I was just wondering
>> | if that kind of memory problem occured before, and if has some
>> | "typical/generic" solutions.
>> | I will try to have a shortest code to exhibit.
>>
>> Really appreciate it.
>>
>> Many of us found over the years that just by "creating a better example" to
>> often drill down close enough to the problem core.
>>
>> And the easier you make it for folks to help you, the likier it is that
>> some
>> kind soul from around here can give you a hand.
>>
>> Just lowering the barriers, be it cognitive or just plain effort ...
>>
>> Best, Dirk
>>
>> --
>> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>> _______________________________________________
>> Rcpp-devel mailing list
>> Rcpp-devel at lists.r-forge.r-project.org
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>
>
>
>
> --
>
> J.P. Olmsted
> j.p.olmsted at gmail.com
>





More information about the Rcpp-devel mailing list