I think multicore is one of answer if you can write your function in to lapply.
On Mon, Jun 18, 2012 at 12:14 PM, R. Michael Weylandt <michael.weyla...@gmail.com> wrote: > I would argue (somewhat emphatically) that the parallel facilities you > are looking at are absolutely not for `for` loops. `for` loops are a > control structure native to imperative programming and, as such, are > inherently stateful. This provides many advantages, but easy > parallelization is absolutely not one of them. Rather consider R as a > functional language and the appropriate "control structure" is the > Map(), most famously of MapReduce, but also inherent in R's *apply() > family of functions. The careful reader will note that here is where > parallelization is exposed. By being state-free, there's no inherent > sequentiality and, consequently, no barriers to parallel computing. > > For a somewhat concrete example consider what it would take to do a > state-dependent simulation (like a gibbs sampler) in parallel: it is, > to my mind, quite non-trivial. Compare this to the question of doing > column sums of a matrix in parallel -- effectively trivial. The > parallelization afforded by R is of that second sort. > > A red herring in this discussion is the foreach() formalism, but a > moment's thought suggests to me that foreach() is much closer to Map() > than to for(). > > Best, > Michael > > On Sun, Jun 17, 2012 at 1:23 PM, Gary Dong <pdxgary...@gmail.com> wrote: >> Thanks for all replied. >> >> I read the introduction of R parallel. Is it for loops only? >> >> Gary >> >> >> On Sun, Jun 17, 2012 at 10:04 AM, R. Michael Weylandt >> <michael.weyla...@gmail.com> <michael.weyla...@gmail.com> wrote: >>> >>> Take a look at the parallel package which ships with all current versions >>> of R. >>> >>> Michael >>> >>> On Jun 17, 2012, at 11:39 AM, Gary Dong <pdxgary...@gmail.com> wrote: >>> >>> > Dear R users, >>> > >>> > I'm wonder if there is a easy way to make R use multi-CPUs on my >>> > computer. >>> > My computer has four CPUs but R uses only one. Thanks. >>> > >>> > Gary >>> > >>> > [[alternative HTML version deleted]] >>> > >>> > ______________________________________________ >>> > R-help@r-project.org mailing list >>> > https://stat.ethz.ch/mailman/listinfo/r-help >>> > PLEASE do read the posting guide >>> > http://www.R-project.org/posting-guide.html >>> > and provide commented, minimal, self-contained, reproducible code. >> >> > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.