[Rcpp-devel] Rcpp-devel Digest, Vol 57, Issue 18

JJ Allaire jj.allaire at gmail.com
Thu Jul 17 22:50:59 CEST 2014


It very well may be thread-safe, but my thinking is that it could be
dangerous to use a class where some methods are thread-safe and some are
not (and there isn't necessarily documentation or a formal contract on
what's safe and what's not). Your current use is likely fine, I'm just
being cautious.

J.J.


On Thu, Jul 17, 2014 at 4:40 PM, Alessandro Mammana <mammana at molgen.mpg.de>
wrote:

> Sorry,  I read this post just by chance,
> did I understand correctly, the class Rcpp::Matrix are not thread safe?
> Is there any problem in writing code such as:
>
> mat(i,j) = something
>
> in a multithreaded environment (such as inside a "#pragma omp parallel
> for" loop)?
> My scripts are full of such loops. I have assumed that it was the same as
> doing:
>
> double* M = mat.begin();
> M[i + ncol*j] = something;
>
> This at least should be thread safe, right?
>
> Thx a lot!
> Ale
>
>
>
> On Tue, Jul 15, 2014 at 12:00 PM,
> <rcpp-devel-request at lists.r-forge.r-project.org> wrote:
> > Send Rcpp-devel mailing list submissions to
> >         rcpp-devel at lists.r-forge.r-project.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> >
> > or, via email, send a message with subject or body 'help' to
> >         rcpp-devel-request at lists.r-forge.r-project.org
> >
> > You can reach the person managing the list at
> >         rcpp-devel-owner at lists.r-forge.r-project.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Rcpp-devel digest..."
> >
> >
> > Today's Topics:
> >
> >    1. Re: parallel distance matrix calculation (JJ Allaire)
> >    2. Re: parallel distance matrix calculation (JJ Allaire)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Mon, 14 Jul 2014 10:45:06 -0400
> > From: JJ Allaire <jj.allaire at gmail.com>
> > To: Dirk Eddelbuettel <edd at debian.org>
> > Cc: "rcpp-devel at lists.r-forge.r-project.org"
> >         <rcpp-devel at lists.r-forge.r-project.org>
> > Subject: Re: [Rcpp-devel] parallel distance matrix calculation
> > Message-ID:
> >         <CAKw=oCxkxeHkM4Q=aFMk+9SrQaM1e-Hao1Mh=
> qgKzn22HCOB5g at mail.gmail.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> > Here's a parallel version:
> >
> >
> https://github.com/jjallaire/RcppParallel/blob/master/inst/examples/parallel-distance-matrix.cpp
> >
> > To make the code reasonable I introduced a new RMatrix<T> class in
> > RcppParallel that makes offsetting into rows and columns safe and
> > straightforward. This class has no connection on the R or Rcpp APIs so is
> > guaranteed to be thread-safe.
> >
> > On a 4 core machine (8 with hyperthreading) I'm observing a 10x speedup.
> > The parallel related speedup is 4x. There is an additional 2.5x speedup
> > which appears to be related to the lower level access to the Matrix
> memory
> > done by RMatrix<T> (and perhaps some elimination of copying).
> >
> >
> >
> >
> > On Sun, Jul 13, 2014 at 7:27 AM, Dirk Eddelbuettel <edd at debian.org>
> wrote:
> >
> >>
> >> On 12 July 2014 at 12:37, JJ Allaire wrote:
> >> | If you could send the full source code to your example (including
> >> js_distance
> >> | and whatever R code you are using to test/exercise the functions) I'll
> >> see if I
> >> | can come up with the code you'd use to parallelize the outer loop.
> >> Depending on
> >> | how it turns out perhaps we can even convert this into another gallery
> >> article!
> >>
> >> That's the spirit!  [ I had another quick look at the inner-product
> example
> >> which is short and nice, but there is just too little of a pickup
> there...
> >> ]
> >>
> >> Dirk
> >>
> >> --
> >> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
> >>
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: <
> http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140714/a4fcf62a/attachment-0001.html
> >
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Mon, 14 Jul 2014 12:48:25 -0400
> > From: JJ Allaire <jj.allaire at gmail.com>
> > To: Dirk Eddelbuettel <edd at debian.org>
> > Cc: "rcpp-devel at lists.r-forge.r-project.org"
> >         <rcpp-devel at lists.r-forge.r-project.org>
> > Subject: Re: [Rcpp-devel] parallel distance matrix calculation
> > Message-ID:
> >         <CAKw=
> oCyCdv98hTUHRUf+XLbKKFUMp3L64hJX4Ku6uoDjjarvSw at mail.gmail.com>
> > Content-Type: text/plain; charset="utf-8"
> >
> >> On a 4 core machine (8 with hyperthreading) I'm observing a 10x speedup.
> >> The parallel related speedup is 4x. There is an additional 2.5x speedup
> >> which appears to be related to the lower level access to the Matrix
> memory
> >> done by RMatrix<T> (and perhaps some elimination of copying).
> >>
> >
> > It turns out that the additional slowdown in the serial version was due
> to
> > repeatedly calling Vector::length as a loop termination condition. I
> > re-wrote the serial version using iterators and now the speedup from
> > parallel is about 5x (more in line with expectations).
> > -------------- next part --------------
> > An HTML attachment was scrubbed...
> > URL: <
> http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140714/39077e47/attachment-0001.html
> >
> >
> > ------------------------------
> >
> > _______________________________________________
> > Rcpp-devel mailing list
> > Rcpp-devel at lists.r-forge.r-project.org
> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> >
> > End of Rcpp-devel Digest, Vol 57, Issue 18
> > ******************************************
>
>
>
> --
> Alessandro Mammana, PhD Student
> Max Planck Institute for Molecular Genetics
> Ihnestraße 63-73
> D-14195 Berlin, Germany
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140717/0b1a7c9f/attachment.html>


More information about the Rcpp-devel mailing list