[Rcpp-devel] RcppParallel wrong after correct

f.krah at mailbox.org f.krah at mailbox.org
Fri Jun 2 15:40:00 CEST 2017


Hi all,

I wrote a function foo using RcppParallel and I am observing a bug, which I can’t figure out.
I first wrote the function in R, then in Rcpp, then RcppParallel.

foo is doing exactly what it is supposed to do in R and Rcpp.
However, I am observing some wired things in RcppParallel.

foo_par is running, giving almost what I want.

foo compares two matrices columnwise all pairwise combinations.
thus we have 3 loops. 
In the smallest step it takes two values e.g. m[c(row1, row2), 1] from the first matrix and checks if they are
appear in 1 column in the second matrix. If they are 1 is returned, if not 0.

However, before that there is a check if one of the c(1,2) is even, then only a NA is returned. 
Check below for this step.

The wired thing is, that this works perfectly fine the very 1st instance this case happens 
and not any more in the thereafter examples. 

E.g: 

> foo(m1, m2)
     [,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    1   NA    1    0*
[3,]    1    0*    1    0*

the 0s with * should be NA. 



if ( (row1 % 2 == 0) || (row2 % 2 == 0) ){
       
           result_matrix(count, col) = NA_REAL;

          } else { 

do the 0, 1 stuff
}

** count: i am using a counter for the filling of the resulting matrix (indicates the row where it should be put)
** col: this is from the outest loop. it loops over columns and then writes the result into the according col in the result matrix. 



Is this enough information?
If someone needs to see the full function, I would prefer to send this via mail directly, since 
this is for a publication…

I appreciate any hints!
And I am wondering if this is coming from the parallelization itself?
The modulo is somehow not working correctly?

Cheers, 
Franz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170602/f1e7447f/attachment.html>


More information about the Rcpp-devel mailing list