Hello Jonhatan and Dirk,

It seems that the whole issue that I encountered was contained in this "off by 1" in the loop. I feel a bit stupid for that :). I can now compute the operation 10^8 times (embedded in another function) without any problem so far, and without using R function gc(). Just one last question though. In that case, no compiling error like "subscript out of bounds" is returned at the compilation (which would have avoided this problem)?

Anyway, thanks a lot for the help, and I'll keep in mind to use Valgrind (or Dr Memory, for windows), even if, so far, I'm learning how to use it.

Just one last thing, congratulations for your package, the improvement in computation time is amazing (not far than 1000 times faster in my case)!

Thanks again,

Pierre Gloaguen


Jonathan Olmsted <jpolms...@gmail.com> a écrit :


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.


​I was just giving some tips in case you needed to look at the output from
Valgrind. When using the prefix, Valgrinds messages didn't lead me right to
the problem. When using postfix, they did. A more seasoned user may have
been able to identify the problem using prefix, but I did not.​



If it still don't work after these fixings,


​... fingers crossed.

-Jonathan​




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 <jpolms...@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 <e...@debian.org> wrote:


Hi Pierre,

On 8 October 2014 at 01:59, pierre.gloag...@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 | e...@debian.org
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel




--

J.P. Olmsted
j.p.olms...@gmail.com







--

J.P. Olmsted
j.p.olms...@gmail.com




_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to