Re: [Rd] R thread safe

From: Duncan Temple Lang <duncan_at_wald.ucdavis.edu>
Date: Mon 07 Nov 2005 - 21:35:22 GMT

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

R is not yet thread safe.
We are working on it, and I hope to make some progress before the end of the year. (This one even!)

 D.

Olaf.Schenk@unibas.ch wrote:
> Dear R-dev,
>
> I would like to accelerate my R computation by using parallel OpenMP compilers
> (e.g from Pathscale) on a 2-processor AMD server and I would like to know
> whether R is a tread safe library. The main kernel of the OpenMP
> parallelization is a C SEXP function that performs the computational routine in
> parallel with:
>
> *******************
> SEXP example(SEXP list, SEXP expr, SEXP rho)
> {
> R_len_t i, n = length(list);
> SEXP ans, alocal;
>
> omp_lock_t lck;
> PROTECT(ans = allocVector(VECSXP, n));
> ans = allocVector(VECSXP, n);
> omp_init_lock(&lck);
> #pragma omp parallel for default(none) private(i, alocal) shared(list,
> lck,rho, ans, n, expr)
> for(i = 0; i < n; i++) {
>
> omp_set_lock(&lck);
> PROTECT(alocal = allocVector(VECSXP, 1));
> alocal = allocVector(VECSXP, 1);
> defineVar(install("x"), VECTOR_ELT(list, i), rho);
> omp_unset_lock(&lck);
>
> /* do computational kernel in parallel */
> alocal = eval(expr, rho);
>
> omp_set_lock(&lck);
> SET_VECTOR_ELT(ans, i, alocal);
> UNPROTECT(1);
> omp_unset_lock(&lck);
>
> }
> setAttrib(ans, R_NamesSymbol, getAttrib(list, R_NamesSymbol));
> UNPROTECT(1);
> return(ans);
> }
>
> ***********
>
> The code works fine using one thread and breaks currently down with 2 threads.
> I am using a recent R distribution and the complete R code is compile with
> "-openmp" and the Pathscale compiler suite.
>
> Thanks in advance,
> Olaf
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

iD8DBQFDb8ia9p/Jzwa2QP4RAjHoAJ9/VVL5DIRwE4tYjwM+0oQPKjmQ4QCeNzFa lX6CVF5yVQZPNSE3bZPr7q4=
=hsjc
-----END PGP SIGNATURE-----



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Nov 08 08:43:09 2005

This archive was generated by hypermail 2.1.8 : Tue 08 Nov 2005 - 02:20:58 GMT