forked from AdamWilsonLabEDU/SpatialDataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParallelProcessingIntro.Rmd
More file actions
92 lines (68 loc) · 3.97 KB
/
Copy pathParallelProcessingIntro.Rmd
File metadata and controls
92 lines (68 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
title: "Parallel Processing"
output:
ioslides_presentation:
css: ../present.css
---
## Serial Computing
Most (legacy) software is written for serial computation:
* Problem broken into discrete set of instructions
* Instructions executed sequentially on a single processor

<br><span style="color:grey; font-size:0.5em;">Figure from [here](https://computing.llnl.gov/tutorials/parallel_comp/) </span>
## Parallel computation
* Problem divided into discrete parts that can be solved concurrently
* Instructions executed simultaneously on different processors
* Overall control/coordination mechanism
<img src="assets/parallelProblem.gif" alt="alt text" width="75%">
<br><span style="color:grey; font-size:0.5em;">Figure from [here](https://computing.llnl.gov/tutorials/parallel_comp/) </span>
## Flynn's taxonomy
A classification of computer architectures ([Flynn, 1972](http://dx.doi.org/10.1109/TC.1972.5009071))
### Four Categories
1. *Single Instruction, Single Data (SISD)*
* No parallelization
2. *Single Instruction, Multiple Data (SIMD)*
* Run the same code/analysis on different datasets
* Examples:
* different species in species distribution model
* same species under different climates
---
3. *Multiple Instruction, Single Data (MISD)*
* Run different code/analyses on the same data
* Examples:
* One species, multiple models
4. *Multiple Instruction, Multiple Data streams (MIMD)*
* Run different code/analyses on different data
* Examples:
* Different species & different models
## Flynn's Taxonomy
<img src="assets/SISD.png" alt="alt text" width="60%">
<br><span style="color:grey; font-size:0.5em;">Figure from [here](http://en.wikipedia.org/wiki/Flynn%27s_taxonomy)</span>
## Our focus: *Single Instruction, Multiple Data (SIMD)*
1. Parallel functions within an R script
* starts on single processor
* runs looped elements on multiple 'slave' processors
* returns results of all iterations to the original instance
* foreach, multicore, plyr, raster
2. Alternative: run many separate instances of R in parallel with `Rscript`
* need another operation to combine the results
* preferable for long, complex jobs
* NOT planning to discuss in this session
## R Packages
There are many R packages for parallelization, check out the CRAN Task View on [High-Performance and Parallel Computing](http://cran.r-project.org/web/views/HighPerformanceComputing.html) for an overview. For example:
* [Rmpi](http://cran.r-project.org/web/packages/Rmpi/index.html): Built on MPI (Message Passing Interface), a de facto standard in parallel computing.
* [snow](http://cran.r-project.org/web/packages/snow/index.html): Simple Network of Workstations can use several standards (PVM, MPI, NWS)
* [parallel](https://stat.ethz.ch/R-manual/R-devel/library/parallel/doc/parallel.pdf) Built in R package (since v2.14.0).
## Foreach Package
In this session we'll focus on the foreach package, which has numerous advantages including:
* intuitive `for()` loop-like syntax
* flexibility of parallel 'backends' from laptops to supercomputers (`multicore`, `parallel`, `snow`, `Rmpi`, etc.)
* nice options for combining output from parallelized jobs
## Documentation for foreach:
- [foreach manual](http://cran.r-project.org/web/packages/foreach/foreach.pdf)
- [foreach vignette](http://cran.r-project.org/web/packages/foreach/vignettes/foreach.pdf)
- [Nested Loops](http://cran.r-project.org/web/packages/foreach/vignettes/nested.pdf)
### Foreach _backends_
- [doParallel](http://cran.r-project.org/web/packages/doParallel/index.html) best for use on multicore machines (uses `fork` on linux/mac and `snow` on windows).
- [doMPI](http://cran.r-project.org/web/packages/doMPI/vignettes/doMPI.pdf): Interface to MPI (Message-Passing Interface)
- [doSNOW](http://cran.r-project.org/web/packages/doSNOW/doSNOW.pdf): Simple Network of Workstations