Discussion:
[Rcpp-devel] RcppParallel wrong after correct
f***@mailbox.org
2017-06-02 13:40:00 UTC
Permalink
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.
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
Romain Francois
2017-06-02 13:56:55 UTC
Permalink
Can you prepare a reprex ?
Post by f***@mailbox.org
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.
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
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Dirk Eddelbuettel
2017-06-02 14:27:31 UTC
Permalink
On 2 June 2017 at 15:56, Romain Francois wrote:
| Can you prepare a reprex ?

Seconded. Minimally reproducible example or your post does not exist.

https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Tim Keitt
2017-06-04 01:25:39 UTC
Permalink
Post by f***@mailbox.org
The modulo is somehow not working correctly?
Possible. Modulo in C++ behaves differently than in R.

More likely is you are working outside the index bound that RcppParallel
uses to chunk the work.

THK

http://www.keittlab.org/

Loading...