<div dir="ltr">Hi All,<div><br></div><div>I'm attempting to paralellize some Rcpp code I have now, but I'm having a hard time understanding the best route for this. I'm looking for some guidance about how things need to be restructured to take advantage of the parallelFor (if that would be the speediest option).</div>
<div><br></div><div>I have the following two functions:</div><div><br></div><div>double kl_divergence(NumericVector vec1, NumericVector vec2)<br></div><div>NumericMatrix js_distance(NumericMatrix mat)<br></div><div><br></div>
<div>Right now, the code for js_distance is:</div><div><br></div><div><div>NumericMatrix rmat(mat.nrow(), mat.nrow());</div><div>  for (int i = 0; i < rmat.nrow(); i++) {<br></div><div>    for (int j = 0; j < i; j++) {</div>
<div>      NumericVector avg = (mat(i,_) + mat(j,_))/2;</div><div>      double d1 = kl_divergence(mat(i,_), avg);</div><div>      double d2 = kl_divergence(mat(j,_), avg);</div><div>      rmat(i,j) = sqrt(.5 * (d1 + d2));</div>
<div>    }</div><div>  }</div></div><div><br></div><div>Which, by the way, is amazingly short and nice. I wanted to parallelize the outer loop, but I'm not finding a mechanism to use iterators to go over the rows of mat. I've looked at the examples on RcppParallel, but</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>