\HeaderA{xcmsPapply}{xcmsPapply}{xcmsPapply}
\begin{Description}\relax
An apply-like function which uses Rmpi to distribute
the processing evenly across a cluster.  Will use a non-MPI
version if distributed processing is not available.
\end{Description}
\begin{Usage}
\begin{verbatim}
    xcmsPapply(arg_sets, papply_action, papply_commondata = list(), 
           show_errors = TRUE, do_trace = FALSE, also_trace = c())
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{arg\_sets}] a list, where each item will be given as an argument 
to papply\_action 
\item[\code{papply\_action}] A function which takes one argument.  It will be
called on each element of arg\_sets 
\item[\code{papply\_commondata}] A list containing the names and values of
variables to be accessible to the papply\_action.
'attach' is used locally to import this list. 
\item[\code{show\_errors}] If set to TRUE, overrides Rmpi's default, and 
messages for errors which occur in R slaves are 
produced. 
\item[\code{do\_trace}] If set to TRUE, causes the papply\_action function to
be traced. i.e. Each statement is output before it is
executed by the slaves. 
\item[\code{also\_trace}] If supplied an array of function names, as strings, 
tracing will also occur for the specified functions. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Similar to apply and lapply, applies a function to all items
of a list, and returns a list with the corresponding results.  

Uses Rmpi to implement a pull idiom in order to distribute
the processing evenly across a cluster.  
If Rmpi is not available, or there are no slaves, 
implements this as a non-parallel algorithm. 

\code{xcmsPapply} is a modified version of the papply function from package papply 0.2 (Duane Currie). 
Parts of the slave function were wrapped in try() to make it failsafe and progress output was added.

Make sure \code{Rmpi} was installed properly by executing the example below.
\code{Rmpi} was tested with 
\Itemize{
\item OpenMPI : Unix, \url{http://www.open-mpi.org/}, don't forget to export \code{MPI\_ROOT} before installing Rmpi e.g. \code{export MPI\_ROOT=/usr/lib/openmpi}  
\item DeinoMPI : Windows, \url{http://mpi.deino.net/}, also see \url{http://www.stats.uwo.ca/faculty/yu/Rmpi/} 
}
\end{Details}
\begin{Value}
A list of return values from papply\_action.  Each value corresponds to
the element of arg\_sets used as a parameter to papply\_action
\end{Value}
\begin{Note}\relax
Does not support distributing recursive calls in parallel.  If 
papply is used inside papply\_action, it will call a non-parallel
version
\end{Note}
\begin{Author}\relax
Duane Currie \textless{}duane.currie@acadiau.ca\textgreater{}, modified by Ralf Tautenhahn \textless{}rtautenh@ipb-halle.de\textgreater{}.
\end{Author}
\begin{References}\relax
\url{http://ace.acadiau.ca/math/ACMMaC/software/papply/}
\end{References}
\begin{Examples}
\begin{ExampleCode}
## Not run: 
library(Rmpi)
library(xcms)

number_lists <- list(1:10,4:40,2:27)

mpi.spawn.Rslaves(nslaves=2)

results <- xcmsPapply(number_lists,sum)
results

mpi.close.Rslaves()

## End(Not run)
\end{ExampleCode}
\end{Examples}

