[Rd] Multicore mapply

2010-04-13 Thread David Rossell
Quick question regarding multicore versions of mapply. Package 'multicore'
provides a parallelized version of 'lapply', called 'mclapply'. I haven't
found any parallelized versions of 'mapply', however (although one can use
the lower level function 'parallel', it becomes harder to control the number
of spawned processes etc).

Is anyone aware of a parallelized version of mapply?

In case anyone finds it interesting, I have coded my pedestrian attempt to a
parallelized 'mapply', which basically sets up a series of calls and then
uses mclapply. It's clearly sub-optimal, as setting up the series of calls
is done with a 'for' which can have a non-negligible cost. Could this be
useful for the multicore package? Any suggestions?

mcmapply <- function(FUN, ..., mc.preschedule = TRUE, mc.set.seed = TRUE,
mc.silent = FALSE, mc.cores=1) {
  FUN <- match.fun(FUN)
  dots <- list(...)
  if (length(dots)==1) {
ans <- mclapply(dots[[1]], FUN, mc.preschedule=mc.preschedule,
mc.set.seed=mc.set.seed, mc.silent=mc.silent, mc.cores=mc.cores)
  } else {
l <- length(dots[[1]])
if (any(sapply(dots,length)!=l)) stop("Arguments must be lists of the
same length")
elem <- mycall <- vector("list", l)
for (i in 1:length(elem)) {
  elem[[i]] <- lapply(dots, "[[", i)
  mycall[[i]] <- paste("do.call(FUN, elem[[",i,"]])",sep="")
}
ans <- mclapply(mycall, function(z) eval(parse(text=z)),
mc.preschedule=mc.preschedule, mc.set.seed=mc.set.seed, mc.silent=mc.silent,
mc.cores=mc.cores)
 }
  return(ans)
}

Here's a couple test examples to compute (1:5)^2.

> mcmapply(function(x) x^2, as.list(1:5), mc.cores=2)  #basically the same
as mclapply
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

[[5]]
[1] 25

> mcmapply(function(x,y) x*y, as.list(1:5), as.list(1:5), mc.cores=2)
[[1]]
[1] 1

[[2]]
[1] 4

[[3]]
[1] 9

[[4]]
[1] 16

[[5]]
[1] 25

Best,

David

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] bug in R CMD INSTALL do_install under OS X

2008-12-15 Thread David Rossell
Hi, I believe I've encountered a bug in the do_install function in the
script used by R CMD INSTALL. I'm using R 2.8.0 under OS X 10.5.5. I was
trying to install a package from source (the package gaga which I maintain,
which I checked and builds correctly for R 2.8.0) when I get the error
message

* Installing to library '/Users/drossell/Desktop/R-2.8.0/library'
/Users/drossell/Desktop/R-2.8.0/bin/INSTALL: line 950: cd:
/Volumes/biostats/projects/routines/R/gaga
/Volumes/biostats/projects/routines/R/gaga: No such file or directory
sed: DESCRIPTION: No such file or directory
ERROR: no 'Package' field in 'DESCRIPTION'

I get this same error for any other package that I try to install.

Upon debugging the script, I've found that the script is trying to cd to
"/Volumes/biostats/projects/routines/R/gaga\n/Volumes/biostats/projects/routines/R/gaga".
That is, the directory is repeated twice, which causes the installation to
fail. To temporarily fix the bug I commented out the 1st two lines in the
do_install function and manually specified the directory. After doing this
the package installs just fine.

#  cd "${1}"
#  pkg_dir="${1}"
  cd "/Volumes/biostats/projects/routines/R/gaga"   #line added
  pkg_dir="/Volumes/biostats/projects/routines/R/gaga" #line added

Thanks,

David

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] bug in R CMD INSTALL do_install under OS X

2008-12-16 Thread David Rossell
You're right William, unsetting the CDPATH variable does the trick. The R
INSTALL script should unset it to avoid the problem.

Thanks a lot,

David

On Mon, Dec 15, 2008 at 9:29 PM, William Dunlap  wrote:

> This problem could be caused by having CDPATH set.  E.g.,
>
>   % env CDPATH=. ~/R-svn/r-devel/R/bin/R CMD INSTALL -l Rlib
> testCMacros
>   /homes/bill/packages/Rlib
>   /homes/bill/R-svn/r-devel/R/bin/INSTALL: line 948: cd:
> /homes/bill/packages/testCMacros
>   /a/seafiler01.na.tibco.com/vol/vol2/users/bill/packages/testCMacros:
> No such file or directory
>/bin/sed: can't read DESCRIPTION: No such file or directory
>ERROR: no 'Package' field in 'DESCRIPTION'
>/bin/sed: read error on /homes/bill/packages/testCMacros: Is a
> directory
> (It works fine if I set 'CDPATH='.)
>
> The happens because, from 'man cd' in
> http://www.linuxhowtos.org/manpages/1p/cd.htm:
>
>   If a non-empty directory name from CDPATH is used, or if
>   cd - is used, an absolute pathname of the new working
>   directory shall be written to the standard output as follows:
>"%s\n", 
>   Otherwise, there shall be no output.
>
> and INSTALL uses the idiom
>`cd ${dir} && /bin/pwd`
> to convert the directory name dir to a full path.
>
> libtools explicitly unsets CDPATH, presumably to avoid this
> sort of problem.  All the R scripts should do so.
>
> Bill Dunlap
> TIBCO Software Inc - Spotfire Division
> wdunlap tibco.com
>
> > -Original Message-
> > From: r-devel-boun...@r-project.org
> > [mailto:r-devel-boun...@r-project.org] On Behalf Of David Rossell
> > Sent: Monday, December 15, 2008 2:05 AM
> > To: r-devel@r-project.org
> > Subject: [Rd] bug in R CMD INSTALL do_install under OS X
> >
> > Hi, I believe I've encountered a bug in the do_install function in the
> > script used by R CMD INSTALL. I'm using R 2.8.0 under OS X
> > 10.5.5. I was
> > trying to install a package from source (the package gaga
> > which I maintain,
> > which I checked and builds correctly for R 2.8.0) when I get the error
> > message
> >
> > * Installing to library '/Users/drossell/Desktop/R-2.8.0/library'
> > /Users/drossell/Desktop/R-2.8.0/bin/INSTALL: line 950: cd:
> > /Volumes/biostats/projects/routines/R/gaga
> > /Volumes/biostats/projects/routines/R/gaga: No such file or directory
> > sed: DESCRIPTION: No such file or directory
> > ERROR: no 'Package' field in 'DESCRIPTION'
> >
> > I get this same error for any other package that I try to install.
> >
> > Upon debugging the script, I've found that the script is
> > trying to cd to
> > "/Volumes/biostats/projects/routines/R/gaga\n/Volumes/biostats
> /projects/routines/R/gaga".
> > That is, the directory is repeated twice, which causes the
> > installation to
> > fail. To temporarily fix the bug I commented out the 1st two
> > lines in the
> > do_install function and manually specified the directory.
> > After doing this
> > the package installs just fine.
> >
> > #  cd "${1}"
> > #  pkg_dir="${1}"
> >   cd "/Volumes/biostats/projects/routines/R/gaga"   #line added
> >   pkg_dir="/Volumes/biostats/projects/routines/R/gaga" #line added
> >
> > Thanks,
> >
> > David
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>



-- 
David Rossell
Manager, Bioinformatics and Biostatistics unit
IRB Barcelona
Tel (+34) 93 402 0217
Fax (+34) 93 402 0257

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel