<div dir="ltr"><div class="gmail_default" style="font-size:small">James,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">My attempt at marginal usefulness (compared to DE and JJE's comments) would be to offer some code examples that I've got using OpenMP--based parallelism. There are examples in the gallery, of course. But I've got a number of others for euclidean distance and one for an EM algorithm. If you are interested, just shoot me an email.</div>

<div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Somewhere in all that I have a some benchmarks showing the time costs depending on where you use the pragmas. But, if you are tied to RcppParallel or you are using a compiler that doesn't support OpenMP, then I've got nothing for you :-(</div>

<div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">And, then there is the issue of whether you find it easier to think about the code in terms of the RcppParallel abstractions or something else.</div>

<div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">-Jonathan<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 11, 2014 at 10:01 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"><div class=""><br>
On 11 July 2014 at 21:19, JJ Allaire wrote:<br>
| (2) The premise of RcppParallel is that you are reading and writing directly<br>
| into C arrays in background threads (it's not safe to call into R and therefore<br>
| not really safe to call into Rcpp). So to interact with a Matrix/Vector you<br>
| need to calculate the appropriate offsets from matrix.begin() to get the slices<br>
| (rows/columns) of the matrix you want.<br>
|<br>
| #2 is based on my conservative assumption about what's thread-safe in Rcpp.<br>
| Romain may tell us that it's perfectly safe to call vector iterators and<br>
| matrix::operator(,) from a background thread but I don't want to assume that's<br>
| okay without confirmation. If those things _aren't_ okay (or might not be okay<br>
| in the future) then we either need to provide good examples for offsetting into<br>
| vectors and matrixes or perhaps provide some lightweight helper classes or<br>
| functions for doing the same.<br>
<br>
</div>When I was working for a while with OpenMP, I found it easier (in terms of my<br>
own mental task switches) to simply not assume anything R-related in the<br>
parallel code.  It is too easy to briefly forget the multithreaded context<br>
and use an idiom which may involve R data structures -- and the possibility<br>
of subsequent data corruption, or worse, is simply not worth it.<br>
<br>
So yes, as you suggest, "in theory" we can use lightweight wrappers. "In<br>
practice", this may be fraught with nasty surprises.<br>
<br>
Parallel programming is hard. Which to me is yet another reason to start<br>
defensively.  But we'll all learn more as we move along, so thanks again to<br>
you for RcppParallel / TBB and all that for getting us going!<br>
<span class="HOEnZb"><font color="#888888"><br>
Dirk<br>
<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>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<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"><div><br></div>-- <br><div dir="ltr"><div><br></div><div><font color="#666666"><font face="courier new, monospace">J.P. Olmsted</font></font></div><div><font color="#666666"><font face="courier new, monospace"><br>

</font></font></div><div><font color="#666666"><font face="courier new, monospace">029 Corwin</font></font></div><div><font face="courier new, monospace"><span style="font-size:small;color:rgb(102,102,102)">Politics Department</span><br>

</font></div><div><font color="#666666"><font face="courier new, monospace">Princeton University</font></font></div><div><font color="#666666"><font face="courier new, monospace">Princeton, NJ 08544</font></font></div><div>

<br></div><div><font color="#666666"><font face="courier new, monospace">t: 609.258.6202</font></font></div><div><font color="#666666" face="courier new, monospace"><font>f: 609.258.1110<br></font><font><a href="mailto:jolmsted@princeton.edu" target="_blank">jolmsted@princeton.edu</a></font></font></div>

<div><a href="http://olmjo.com/" target="_blank"><font face="courier new, monospace">olmjo.com</font></a><div><font face="arial, helvetica, sans-serif"><br></font></div></div></div>
</div>