You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Responded to review comments for reduce_sum changes (mostly use slice instead of subset, rearranging a couple sentences, etc.) (design-doc pull request #17)
Stan has two mechanisms for parallelizing calculations used in a model: `reduce_sum` and and `map_rect`.
4
4
@@ -8,30 +8,30 @@ The main advantages to `reduce_sum` are:
8
8
2.`reduce_sum` partitions the data for parallelization automatically (this is done manually in `map_rect`).
9
9
3.`reduce_sum` is easier to use.
10
10
11
-
while the advantages of `map_rect` are:
11
+
The advantages of `map_rect` are:
12
12
13
13
1.`map_rect` returns a list of vectors, while `reduce_sum` returns only a real.
14
14
2.`map_rect` can be parallelized across multiple computers, while `reduce_sum` can only parallelized across multiple cores.
15
15
16
16
## Reduce-Sum { #reduce-sum }
17
17
18
-
```reduce_sum```is a tool for parallelizing operations that can be represented as a sum of functions, `g: U -> real`.
18
+
```reduce_sum```parallelizes operations that can be represented as a sum of functions, `g: U -> real`.
19
19
20
20
For instance, for a sequence of ```x``` values of type ```U```, ```{ x1, x2, ... }```, we might compute the sum:
21
21
22
22
```g(x1) + g(x2) + ...```
23
23
24
24
In probabilistic modeling this comes up when there are N conditionally independent terms in a likelihood. Because of the conditional independence, these terms can be computed in parallel. If dependencies exist between the terms, then this isn't possible. For instance, in evaluating the log density of a Gaussian process ```reduce_sum``` would not be very useful.
25
25
26
-
```reduce_sum```doesn't actually take ```g: U -> real``` as an input argument. Instead it takes```f: U[] -> real```, where ```f``` computes the partial sum corresponding to the slice of the sequence ```x``` passed in. For instance:
26
+
```reduce_sum```takes a function```f: U[] -> real```, where ```f``` computes the partial sum corresponding to the slice of the sequence ```x``` passed in. For instance:
27
27
28
28
```
29
29
f({ x1, x2, x3 }) = g(x1) + g(x2) + g(x3)
30
30
f({ x1 }) = g(x1)
31
31
f({ x1, x2, x3 }) = f({ x1, x2 }) + f({ x3 })
32
32
```
33
33
34
-
If the user can write a function ```f: U[] -> real``` to compute the necessary partial sums in the calculation, then we can provide a function to automatically parallelize the calculations (and this is what ```reduce_sum``` is).
34
+
If the user can write a function ```f: U[] -> real``` to compute the necessary partial sums in the calculation, then ```reduce_sum``` can automatically parallelize the calculations.
35
35
36
36
If the set of work is represented as an array ```{ x1, x2, x3, ... }```, then mathematically it is possible to rewrite this sum with any combination of partial sums.
37
37
@@ -73,16 +73,16 @@ real reduce_sum(F func, T[] x, int grainsize, T1 s1, T2 s2, ...)
73
73
The user-defined partial sum functions have the signature:
74
74
75
75
```
76
-
real func(int start, int end, T[] x_subset, T1 arg1, T2 arg2, ...)
76
+
real func(int start, int end, T[] x_slice, T1 arg1, T2 arg2, ...)
77
77
```
78
78
79
79
and take the arguments:
80
80
1.```start``` - An integer specifying the first term in the partial sum
81
81
2.```end``` - An integer specifying the last term in the partial sum (inclusive)
82
-
3.```x_subset``` - The subset of ```x``` (from ```reduce_sum```) for which this partial sum is responsible (```x[start:end]```)
82
+
3.```x_slice``` - The subset of ```x``` (from ```reduce_sum```) for which this partial sum is responsible (```x[start:end]```)
83
83
4-. ```arg1, arg2, ...``` Arguments shared in every term (passed on without modification from the reduce_sum call)
84
84
85
-
The user-provided function ```func``` is expect to compute the ```start``` through ```end``` terms of the overall sum, accumulate them, and return that value. The user function is passed the subset ```x[start:end]``` as ```x_subset```. ```start``` and ```end``` are passed so that ```func``` can index any of the tailing ```sM``` arguments as necessary. The trailing ```sM``` arguments are passed without modification to every call of ```func```.
85
+
The user-provided function ```func``` is expect to compute the ```start``` through ```end``` terms of the overall sum, accumulate them, and return that value. The user function is passed the subset ```x[start:end]``` as ```x_slice```. ```start``` and ```end``` are passed so that ```func``` can index any of the tailing ```sM``` arguments as necessary. The trailing ```sM``` arguments are passed without modification to every call of ```func```.
0 commit comments