<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This looks like a copy and paste mistake. I can definitely see this line on the slide 57: <div class="">
                
        
        
                <div class="page" title="Page 58">
                        <div class="section" style="background-color: rgb(98.000000%, 98.000000%, 98.000000%)">
                                <div class="layoutArea">
                                        <div class="column"><p class=""><span style="font-size: 8.000000pt; font-family: 'LMMono8-Regular-Identity-H'; color: rgb(3.000000%, 3.000000%, 3.000000%)" class="">RMatrix<</span><span style="font-size: 8.000000pt; font-family: 'LMMono8-Regular-Identity-H'; color: rgb(13.000000%, 29.000000%, 53.000000%)" class="">double</span><span style="font-size: 8.000000pt; font-family: 'LMMono8-Regular-Identity-H'; color: rgb(3.000000%, 3.000000%, 3.000000%)" class="">> output; </span></p>
                                        </div>
                                </div>
                        </div>
                </div><div class="">Anyway, the example is there: </div><div class=""><a href="http://gallery.rcpp.org/articles/parallel-matrix-transform/" class="">http://gallery.rcpp.org/articles/parallel-matrix-transform/</a></div><div class=""><br class=""></div><div class="">Romain</div><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 31 mai 2017 à 12:42, <a href="mailto:f.krah@mailbox.org" class="">f.krah@mailbox.org</a> a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks Romain,<div class=""><br class=""></div><div class="">this error is fine now, however, now I run into new…</div><div class="">I took the example code from <a href="http://dirk.eddelbuettel.com/papers/rcpp_rfinance_may2015.pdf" class="">this</a> presentation of Dirk</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">> Rcpp::sourceCpp("src/par_example.cpp")</div><div class="">par_example.cpp:26:21: error: member initializer 'output' does not name a non-static data member or base class</div><div class="">    : input(input), output(output) {}</div><div class="">                    ^~~~~~~~~~~~~~</div><div class="">par_example.cpp:31:5: error: use of undeclared identifier 'output'</div><div class="">    output.begin() + begin,</div><div class="">    ^</div><div class="">2 errors generated.</div><div class="">make: *** [par_example.o] Error 1</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Hope this is as easily solved as the before error.</div><div class=""><br class=""></div><div class="">Cheers, Franz</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On 31 May 2017, at 12:26, Romain Francois <<a href="mailto:romain@r-enthusiasts.com" class="">romain@r-enthusiasts.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You can add this somewhere on top of your cpp file <div class=""><br class=""></div><div class="">// [[Rcpp::depends(RcppParallel)]]</div><div class=""><br class=""></div><div class="">Romain</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">Le 31 mai 2017 à 12:22, <a href="mailto:f.krah@mailbox.org" class="">f.krah@mailbox.org</a> a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi all,<div class=""><br class=""></div><div class="">I am very new to Rcpp and I wrote a function which I now want to parallelize.</div><div class="">The function is working fine, and is much faster than in R, however, it really is slow for bigger datasets.</div><div class=""><br class=""></div><div class="">Since the function is running I don’t need to explain what it does, however, it is has </div><div class="">3 nested for loops. It loops through columns and within each column if loops through the rows and in a third loop produces pair comparisons… </div><div class=""><br class=""></div><div class="">So the parallelisation should parallelize the column loop.</div><div class=""><br class=""></div><div class="">I found the RcppParallel package and for the beginning wanted to run on of the example to understand the</div><div class="">workflow first. However, I already have issues running the code below:</div><div class=""><br class=""></div><div class="">following is sourced with: Rcpp::sourceCpp("src/par_example.cpp")</div><div class="">However, I get the error: </div><div class=""><br class=""></div><div class=""><div class=""><b class="">par_example.cpp:6:10: fatal error: 'RcppParallel.h' file not found</b></div><div class=""><b class="">#include <RcppParallel.h></b></div><div class=""><b class="">         ^</b></div><div class=""><b class="">1 error generated.</b></div><div class=""><b class="">make: *** [par_example.o] Error 1</b></div></div><div class=""><br class=""></div><div class=""><div class="">I would much appreciate if someone could give me a start with this!</div><div class=""><br class=""></div><div class="">Cheers, </div><div class="">Franz</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">#include <Rcpp.h></div><div class=""><br class=""></div><div class="">using namespace Rcpp;</div><div class="">#include <cmath></div><div class="">#include <algorithm></div><div class="">#include <RcppParallel.h></div><div class=""><br class=""></div><div class="">// [[Rcpp::export]]</div><div class="">NumericMatrix matrixSqrt(NumericMatrix orig) {</div><div class="">  // allocate the matrix we will return</div><div class="">  NumericMatrix mat(orig.nrow(), orig.ncol());</div><div class="">  // transform it</div><div class="">  std::transform(orig.begin(), orig.end(), mat.begin(), ::sqrt);</div><div class="">  // return the new matrix</div><div class="">  return mat;</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">using namespace RcppParallel;</div><div class="">struct SquareRoot : public Worker {</div><div class="">  const RMatrix<double> input;</div><div class="">  // source matrix RMatrix<double> output; // destination matrix</div><div class="">  // initialize with source and destination</div><div class="">  SquareRoot(const NumericMatrix input, NumericMatrix output)</div><div class="">    : input(input), output(output) {}</div><div class="">  // take the square root of the range of elements requested</div><div class="">  void operator()(std::size_t begin, std::size_t end) { std::transform(input.begin() + begin,</div><div class="">    input.begin() + end,</div><div class="">    output.begin() + begin,</div><div class="">    ::sqrt);</div><div class="">  }</div><div class="">};</div><div class=""><br class=""></div><div class="">// [[Rcpp::export]]</div><div class="">NumericMatrix parallelMatrixSqrt(NumericMatrix x) {</div><div class="">  // allocate the output matrix</div><div class="">  NumericMatrix output(x.nrow(), x.ncol());</div><div class="">  // SquareRoot functor (pass input and output matrixes)</div><div class="">  SquareRoot squareRoot(x, output);</div><div class="">  // call parallelFor to do the work</div><div class="">  parallelFor(0, x.length(), squareRoot);</div><div class="">  // return the output matrix</div><div class="">  return output; }</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div>_______________________________________________<br class="">Rcpp-devel mailing list<br class=""><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" class="">Rcpp-devel@lists.r-forge.r-project.org</a><br class=""><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" class="">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></div></body></html>