<div dir="ltr"><br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><a href="http://www.keittlab.org/" target="_blank">http://www.keittlab.org/</a></div></div></div>
<br><div class="gmail_quote">On Sat, Jul 29, 2017 at 8:00 AM, Iñaki Úcar <span dir="ltr"><<a href="mailto:i.ucar86@gmail.com" target="_blank">i.ucar86@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">2017-07-29 13:58 GMT+02:00 JJ Allaire <<a href="mailto:jj.allaire@gmail.com">jj.allaire@gmail.com</a>>:<br>
> The best you can do is to get the pointer to the function (not sure if that<br>
> does what you are hoping for):<br>
><br>
> func <- Rcpp::cppFunction("int foo() { return 1; }")<br>
><br>
>> body(func)<br>
> .Primitive(".Call")(<pointer: 0x103bf0f40>)<br>
<br>
I don't think so. Let me explain the motivation behind my question;<br>
this way you can judge whether it's worth it.<br>
<br>
With our simulator, simmer, we are able to generate arrivals, entities<br>
that execute a given set of activities. One of these activities could<br>
be, let's say, a delay. A user can provide this delay as a fixed<br>
parameter to the C++ core, but also as a function that returns a<br>
value, giving them a lot of flexibility to implement the simulation<br>
model. As a trade-off, calling an R function from C++ is slow.<br>
<br>
Now, what if the user needs flexibility *and* speed and so decides to<br>
pass a cppFunction instead? This is perfectly valid and works like a<br>
charm. In fact, this speeds up things a lot, especially if the<br>
function was performing some heavy processing. *However*, it means<br>
that we still have C++ calling R calling C++.<br>
<br>
This is why I say, what if I can detect that situation and completely<br>
get rid of that thin R layer? What if I can extract the pointer and<br>
call C++ directly from my C++ core? I would expect an impressive<br>
performance improvement.<br></blockquote><div><br></div><div>Many C++ libs require function inlining to get top performance. You might consider assembling the model in C++ and compiling on-the-fly. I have a demo at <a href="https://github.com/thk686/odeintr">https://github.com/thk686/odeintr</a>. The user just supplies bits of C++ code that are merged with the boilerplate and compiled.</div><div><br></div><div>THK</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Iñaki<br>
______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a></blockquote></div><br></div></div>