Learn parallel programming in R with these exercises for "foreach"

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The foreach package provides a simple looping construct for R: the foreach function, which you may be familiar with from other languages like Javascript or C#. It's basically a function-based version of a "for" loop. But what makes foreach useful isn't iteration: it's the way it makes it easy to run those iterations in parallel, and save time on multi-CPU and distributed systems.

If you want to get familiar with the foreach function, Parallelizing Loops at Microsoft Docs will introduce you to foreach oops (and the companion concept, iterators), and the various “backends” you can use to make the loops run in parallel without changing your loop code. Then, to make sure you've captured the concepts, you can try these 10 parallel computing exercises using foreach, from R-exercises.com. If you get stuck, the solutions are available here.

To get started with foreach, can install the foreach package from CRAN, or simply use any edition of Microsoft R including Microsoft R Open (all come with foreach preinstalled). The foreach package is maintained by Microsoft under the open-source Apache license. 

R-exercises: Parallel Computing Exercises: Foreach and DoParallel (Part-2)

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)