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
Copy file name to clipboardExpand all lines: README.md
+42-41Lines changed: 42 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,7 +154,7 @@ The **future** package comes with built-in future backends that leverage the **p
154
154
| **[future.callr]**<br> `callr` | 📶<br>♻️<br> | parallelly via transient **[callr]** background R sessions on current machine; all memory is returned when as each future is resolved
155
155
| **[future.mirai]**<br> `mirai_multisession` | 📶<br>♻️<br> | parallelly via **[mirai]** background R sessions on current machine; low latency
156
156
| **[future.mirai]**<br> `mirai_cluster` |♻️<br> | parallelly via **[mirai]** daemons running locally or remotely
157
-
|**[future.batchtools]**<br> `batchtools_lsf`<br>`batchtools_openlava`<br>`batchtools_sge`<br>`batchtools_slurm`<br>`batchtools_torque`| 📶(soon)<br> ♻️(next)| parallelly on HPC job schedulers (Load Sharing Facility [LSF], OpenLava, TORQUE/PBS, Son/Sun/Oracle/Univa Grid Engine [SGE], Slurm) via **[batchtools]**; for long-running tasks; high latency |
157
+
|**[future.batchtools]**<br> `batchtools_lsf`<br>`batchtools_openlava`<br>`batchtools_sge`<br>`batchtools_slurm`<br>`batchtools_torque`| 📶(soon)<br> ♻️<br>| parallelly on HPC job schedulers (Load Sharing Facility [LSF], OpenLava, TORQUE/PBS, Son/Sun/Oracle/Univa Grid Engine [SGE], Slurm) via **[batchtools]**; for long-running tasks; high latency |
158
158
159
159
📶: futures relay progress updates in real-time, e.g. **[progressr]**<br>
160
160
♻️: futures are interruptible and restartable; * disabled by default<br>
@@ -209,7 +209,7 @@ Sequential futures are the default unless otherwise specified. They were design
209
209
> plan(sequential)
210
210
>pid<- Sys.getpid()
211
211
>pid
212
-
[1] 1399790
212
+
[1] 1287562
213
213
>a %<-% {
214
214
+pid<- Sys.getpid()
215
215
+ cat("Future 'a' ...\n")
@@ -227,14 +227,14 @@ Sequential futures are the default unless otherwise specified. They were design
227
227
Future'a'...
228
228
>b
229
229
Future'b'...
230
-
[1] 1399790
230
+
[1] 1287562
231
231
>c
232
232
Future'c'...
233
233
[1] 6.28
234
234
>a
235
235
[1] 3.14
236
236
>pid
237
-
[1] 1399790
237
+
[1] 1287562
238
238
```
239
239
240
240
Since eager sequential evaluation is taking place, each of the three futures is resolved instantaneously in the moment it is created. Note also how `pid` in the calling environment, which was assigned the process ID of the current process, is neither overwritten nor removed. This is because futures are evaluated in a local environment. Since synchronous (uni-)processing is used, future `b` is resolved by the main R process (still in a local environment), which is why the value of `b` and `pid` are the same.
@@ -253,7 +253,7 @@ We start with multisession futures because they are supported by all operating s
253
253
> plan(multisession, workers=2)
254
254
>pid<- Sys.getpid()
255
255
>pid
256
-
[1] 1399790
256
+
[1] 1287562
257
257
>a %<-% {
258
258
+pid<- Sys.getpid()
259
259
+ cat("Future 'a' ...\n")
@@ -271,14 +271,14 @@ We start with multisession futures because they are supported by all operating s
271
271
Future'a'...
272
272
>b
273
273
Future'b'...
274
-
[1] 1399841
274
+
[1] 1287626
275
275
>c
276
276
Future'c'...
277
277
[1] 6.28
278
278
>a
279
279
[1] 3.14
280
280
>pid
281
-
[1] 1399790
281
+
[1] 1287562
282
282
```
283
283
284
284
The first thing we observe is that the values of `a`, `c` and `pid` are the same as previously. However, we notice that `b` is different from before. This is because future `b` is evaluated in a different R process and therefore it returns a different process ID.
@@ -318,7 +318,7 @@ Cluster futures evaluate expressions on an ad-hoc cluster (as implemented by the
318
318
> plan(cluster, workers= c("n1", "n2", "n3"))
319
319
>pid<- Sys.getpid()
320
320
>pid
321
-
[1] 1399790
321
+
[1] 1287562
322
322
>a %<-% {
323
323
+pid<- Sys.getpid()
324
324
+ cat("Future 'a' ...\n")
@@ -336,14 +336,14 @@ Cluster futures evaluate expressions on an ad-hoc cluster (as implemented by the
336
336
Future'a'...
337
337
>b
338
338
Future'b'...
339
-
[1] 1399937
339
+
[1] 1287729
340
340
>c
341
341
Future'c'...
342
342
[1] 6.28
343
343
>a
344
344
[1] 3.14
345
345
>pid
346
-
[1] 1399790
346
+
[1] 1287562
347
347
```
348
348
349
349
Any types of clusters that `parallel::makeCluster()` creates can be used for cluster futures. For instance, the above cluster can be explicitly set up as:
@@ -394,24 +394,24 @@ For instance, here is an example of two "top" futures (`a` and `b`) that uses mu
394
394
+ c(b.pid= Sys.getpid(), b1.pid=b1, b2.pid=b2)
395
395
+ }
396
396
>pid
397
-
[1] 1399790
397
+
[1] 1287562
398
398
>a
399
399
Future'a'...
400
-
[1] 1400059
400
+
[1] 1287860
401
401
>b
402
402
Future'b'...
403
403
Future'b1'...
404
404
Future'b2'...
405
405
b.pidb1.pidb2.pid
406
-
140005814000581400058
406
+
128785912878591287859
407
407
```
408
408
409
409
By inspection the process IDs, we see that there are in total three different processes involved for resolving the futures. There is the main R process
410
-
(pid 1399790),
410
+
(pid 1287562),
411
411
and there are the two processes used by `a`
412
-
(pid 1400059)
412
+
(pid 1287860)
413
413
and `b`
414
-
(pid 1400058).
414
+
(pid 1287859).
415
415
However, the two futures (`b1` and `b2`) that is nested by `b` are evaluated by the same R process as `b`. This is because nested futures use sequential evaluation unless otherwise specified. There are a few reasons for this, but the main reason is that it protects us from spawning off a large number of background processes by mistake, e.g. via recursive calls.
416
416
417
417
@@ -428,16 +428,16 @@ We would actually get the same behavior if we try with multiple levels of multis
428
428
> plan(list(multisession, multisession))
429
429
[...]
430
430
>pid
431
-
[1] 1399790
431
+
[1] 1287562
432
432
>a
433
433
Future'a'...
434
-
[1] 1400155
434
+
[1] 1287962
435
435
>b
436
436
Future'b'...
437
437
Future'b1'...
438
438
Future'b2'...
439
439
b.pidb1.pidb2.pid
440
-
140015414001541400154
440
+
128796312879631287963
441
441
```
442
442
443
443
The second multisession backend will default to single, sequential
@@ -452,22 +452,22 @@ Continuing, if we start off with the sequential backend and then use the multise
452
452
> plan(list(sequential, multisession))
453
453
[...]
454
454
>pid
455
-
[1] 1399790
455
+
[1] 1287562
456
456
>a
457
457
Future'a'...
458
-
[1] 1399790
458
+
[1] 1287562
459
459
>b
460
460
Future'b'...
461
461
Future'b1'...
462
462
Future'b2'...
463
463
b.pidb1.pidb2.pid
464
-
139979014002501400251
464
+
128756212880801288081
465
465
```
466
466
467
467
which clearly show that `a` and `b` are resolved in the calling
468
-
process (pid 1399790) whereas the two nested futures (`b1` and
469
-
`b2`) are resolved in two separate R processes (pids 1400250 and
470
-
1400251).
468
+
process (pid 1287562) whereas the two nested futures (`b1` and
469
+
`b2`) are resolved in two separate R processes (pids 1288080 and
470
+
1288081).
471
471
472
472
473
473
@@ -478,24 +478,24 @@ Having said this, it is indeed possible to use nested multisession backend that
478
478
+workers=2)))
479
479
[...]
480
480
>pid
481
-
[1] 1399790
481
+
[1] 1287562
482
482
>a
483
483
Future'a'...
484
-
[1] 1400346
484
+
[1] 1288184
485
485
>b
486
486
Future'b'...
487
487
Future'b1'...
488
488
Future'b2'...
489
489
b.pidb1.pidb2.pid
490
-
140034514005611400560
490
+
128818512883141288315
491
491
```
492
492
493
493
First, we see that both `a` and `b` are resolved in different processes
494
-
(pids 1400346 and 1400345)
494
+
(pids 1288184 and 1288185)
495
495
than the calling process
496
-
(pid 1399790).
496
+
(pid 1287562).
497
497
Second, the two nested futures (`b1` and `b2`) are resolved in yet two other R processes
498
-
(pids 1400561 and 1400560).
498
+
(pids 1288314 and 1288315).
499
499
500
500
501
501
For more details on working with nested futures and different future backends at each level, see Vignette '[A Future for R: Future Topologies]'.
@@ -532,11 +532,12 @@ Waiting for 'a' to be resolved ...
532
532
8
533
533
9
534
534
10
535
+
11
535
536
> cat("Waiting for 'a' to be resolved ... DONE\n")
536
537
Waitingfor'a'toberesolved...DONE
537
538
>a
538
539
Future'a'...done
539
-
[1] 1400685
540
+
[1] 1288421
540
541
```
541
542
542
543
@@ -604,9 +605,9 @@ There is one limitation with implicit futures that does not exist for explicit o
604
605
>v<- lapply(f, FUN=value)
605
606
> str(v)
606
607
Listof3
607
-
$:int1400783
608
-
$:int1400784
609
-
$:int1400783
608
+
$:int1288542
609
+
$:int1288543
610
+
$:int1288543
610
611
```
611
612
612
613
This is _not_ possible to do when using implicit futures. This is because the `%<-%` assignment operator _cannot_ be used in all cases where the regular `<-` assignment operator can be used. It can only be used to assign future values to _environments_ (including the calling environment) much like how `assign(name, value, envir)` works. However, we can assign implicit futures to environments using _named indices_, e.g.
@@ -622,9 +623,9 @@ This is _not_ possible to do when using implicit futures. This is because the `
622
623
>v<- as.list(v)
623
624
> str(v)
624
625
Listof3
625
-
$a:int1400783
626
-
$b:int1400784
627
-
$c:int1400783
626
+
$a:int1288542
627
+
$b:int1288543
628
+
$c:int1288542
628
629
```
629
630
630
631
Here `as.list(v)` blocks until all futures in the environment `v` have been resolved. Then their values are collected and returned as a regular list.
@@ -643,9 +644,9 @@ If _numeric indices_ are required, then _list environments_ can be used. List e
643
644
>v<- as.list(v)
644
645
> str(v)
645
646
Listof3
646
-
$:int1400783
647
-
$:int1400784
648
-
$:int1400783
647
+
$:int1288542
648
+
$:int1288543
649
+
$:int1288542
649
650
```
650
651
651
652
As previously, `as.list(v)` blocks until all futures are resolved.
Copy file name to clipboardExpand all lines: inst/vignettes-static/future-1-overview.md.rsp.rsp
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -155,7 +155,7 @@ The **future** package comes with built-in future backends that leverage the **p
155
155
| **[future.callr]**<br> `callr` | 📶<br>♻️<br> | parallelly via transient **[callr]** background R sessions on current machine; all memory is returned when as each future is resolved
156
156
| **[future.mirai]**<br> `mirai_multisession` | 📶<br>♻️<br> | parallelly via **[mirai]** background R sessions on current machine; low latency
157
157
| **[future.mirai]**<br> `mirai_cluster` |♻️<br> | parallelly via **[mirai]** daemons running locally or remotely
158
-
| **[future.batchtools]**<br> `batchtools_lsf`<br>`batchtools_openlava`<br>`batchtools_sge`<br>`batchtools_slurm`<br>`batchtools_torque` | 📶(soon)<br> ♻️(next) | parallelly on HPC job schedulers (Load Sharing Facility [LSF], OpenLava, TORQUE/PBS, Son/Sun/Oracle/Univa Grid Engine [SGE], Slurm) via **[batchtools]**; for long-running tasks; high latency |
158
+
| **[future.batchtools]**<br> `batchtools_lsf`<br>`batchtools_openlava`<br>`batchtools_sge`<br>`batchtools_slurm`<br>`batchtools_torque` | 📶(soon)<br> ♻️<br> | parallelly on HPC job schedulers (Load Sharing Facility [LSF], OpenLava, TORQUE/PBS, Son/Sun/Oracle/Univa Grid Engine [SGE], Slurm) via **[batchtools]**; for long-running tasks; high latency |
159
159
160
160
📶: futures relay progress updates in real-time, e.g. **[progressr]**<br>
161
161
♻️: futures are interruptible and restartable; * disabled by default<br>
0 commit comments