Skip to content

Commit 3d48dc8

Browse files
committed
update vignettes
1 parent b870e11 commit 3d48dc8

File tree

2 files changed

+58
-59
lines changed

2 files changed

+58
-59
lines changed

vignettes/mirai.Rmd

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ To wait for and collect the return value, use the mirai's `[]` method:
6262

6363
``` r
6464
m[]
65-
#> [1] 4.021118 4.931766 5.243967 3.375100 5.667178
65+
#> [1] 3.495676 3.816495 4.628665 3.491260 5.778629
6666
```
6767
As a mirai represents an async operation, it is never necessary to wait for it. Other code can continue to be run. Once it completes, the return value automatically becomes available at `$data`.
6868

6969
``` r
7070
m
7171
#> < mirai [$data] >
7272
m$data
73-
#> [1] 4.021118 4.931766 5.243967 3.375100 5.667178
73+
#> [1] 3.495676 3.816495 4.628665 3.491260 5.778629
7474
```
7575
For easy programmatic use of `mirai()`, '.expr' accepts a pre-constructed language object, and also a list of named arguments passed via '.args'. So, the following would be equivalent to the above:
7676

@@ -82,7 +82,7 @@ args <- list(time = x$time, mean = x$mean)
8282

8383
m <- mirai(.expr = expr, .args = args)
8484
m[]
85-
#> [1] 2.344214 5.151972 2.745938 5.707968 3.244619
85+
#> [1] 3.425921 4.885346 4.717019 2.501762 5.443241
8686
```
8787

8888
[&laquo; Back to ToC](#table-of-contents)
@@ -158,15 +158,14 @@ for (i in 1:10) {
158158
}
159159
#> iteration 1 successful
160160
#> iteration 2 successful
161-
#> Error: random error
162161
#> iteration 3 successful
163162
#> iteration 4 successful
164163
#> iteration 5 successful
165164
#> iteration 6 successful
166165
#> iteration 7 successful
166+
#> Error: random error
167167
#> iteration 8 successful
168168
#> iteration 9 successful
169-
#> Error: random error
170169
#> iteration 10 successful
171170
```
172171
Further, by testing the return value of each 'mirai' for errors, error-handling code is then able to automate recovery and re-attempts, as in the above example. Further details on [error handling](#errors-interrupts-and-timeouts) can be found in the section below.
@@ -201,12 +200,12 @@ status()
201200
#>
202201
#> $daemons
203202
#> i online instance assigned complete
204-
#> abstract://f52b35b9a832a2152cb68451 1 1 1 0 0
205-
#> abstract://033141983db5a787d41c6b62 2 1 1 0 0
206-
#> abstract://f5b1e54c4524b0ad70f97cb1 3 1 1 0 0
207-
#> abstract://0c2dde598cb4db7faea10fa5 4 1 1 0 0
208-
#> abstract://4c233fb0f8673194b1f4e043 5 1 1 0 0
209-
#> abstract://32c59496251de9055106a772 6 1 1 0 0
203+
#> abstract://bb7da8970444e783a3f63281 1 1 1 0 0
204+
#> abstract://faf804d9f786b1ccc4f76628 2 1 1 0 0
205+
#> abstract://e8e180caa09bc41f4067298a 3 1 1 0 0
206+
#> abstract://3faa8cb0dadbe3c24fc35133 4 1 1 0 0
207+
#> abstract://bdca3dd925f7416391b86f12 5 1 1 0 0
208+
#> abstract://2e4db69b3b9c198610e51062 6 1 1 0 0
210209
```
211210
The default `dispatcher = "process"` creates a `dispatcher()` background process that connects to individual daemon processes on the local machine. This ensures that tasks are dispatched efficiently on a first-in first-out (FIFO) basis to daemons for processing. Tasks are queued at the dispatcher and sent to a daemon as soon as it can accept the task for immediate execution.
212211

@@ -238,7 +237,7 @@ status()
238237
#> [1] 6
239238
#>
240239
#> $daemons
241-
#> [1] "abstract://d47e6c20df78276654d7893e"
240+
#> [1] "abstract://1ebf9fad5f9a05dfb8def571"
242241
```
243242
This implementation sends tasks immediately, and ensures that tasks are evenly-distributed amongst daemons. This means that optimal scheduling is not guaranteed as the duration of tasks cannot be known *a priori*. As an example, tasks could be queued at a daemon behind a long-running task, whilst other daemons are idle having already completed their tasks.
244243

@@ -266,11 +265,11 @@ m <- mirai(capture.output(str(con)))
266265
m[]
267266
#> [1] "Formal class 'SQLiteConnection' [package \"RSQLite\"] with 8 slots"
268267
#> [2] " ..@ ptr :<externalptr> "
269-
#> [3] " ..@ dbname : chr \"/tmp/Rtmp8RYD0H/file38fb134e0316\""
268+
#> [3] " ..@ dbname : chr \"/tmp/RtmpgPsUPA/file4e907e57a6b6\""
270269
#> [4] " ..@ loadable.extensions: logi TRUE"
271270
#> [5] " ..@ flags : int 70"
272271
#> [6] " ..@ vfs : chr \"\""
273-
#> [7] " ..@ ref :<environment: 0x56e93a2ecdf8> "
272+
#> [7] " ..@ ref :<environment: 0x5fb884ba8ae0> "
274273
#> [8] " ..@ bigint : chr \"integer64\""
275274
#> [9] " ..@ extended_types : logi FALSE"
276275
```
@@ -371,7 +370,7 @@ status()
371370
#> [1] 0
372371
#>
373372
#> $daemons
374-
#> [1] "tcp://hostname:42771"
373+
#> [1] "tcp://hostname:42761"
375374
```
376375
The number of daemons connecting to the host URL is not limited and network resources may be added or removed at any time, with tasks automatically distributed to all connected daemons.
377376

@@ -461,10 +460,10 @@ daemons(n = 2, url = host_url())
461460
#> [1] 2
462461
launch_remote(1:2)
463462
#> [1]
464-
#> Rscript -e 'mirai::daemon("tcp://hostname:45023",rs=c(10407,-1977357818,1537914063,-944747324,685206773,301969714,384986891))'
463+
#> Rscript -e 'mirai::daemon("tcp://hostname:34471",rs=c(10407,-1464045629,542467624,-1598368247,142924342,1806531391,-2073238412))'
465464
#>
466465
#> [2]
467-
#> Rscript -e 'mirai::daemon("tcp://hostname:35177",rs=c(10407,-2118558994,-1471211395,-214113251,1708896166,-1342731093,-35397167))'
466+
#> Rscript -e 'mirai::daemon("tcp://hostname:45693",rs=c(10407,-1513314584,1587671761,1092626800,-185579079,11250700,-1550799561))'
468467
daemons(0)
469468
#> [1] 0
470469
```
@@ -491,37 +490,37 @@ The generated self-signed certificate is available via `launch_remote()`. This f
491490
``` r
492491
launch_remote(1)
493492
#> [1]
494-
#> Rscript -e 'mirai::daemon("wss://hostname:33667/1",tls=c("-----BEGIN CERTIFICATE-----
493+
#> Rscript -e 'mirai::daemon("wss://hostname:35957/1",tls=c("-----BEGIN CERTIFICATE-----
495494
#> MIIFNzCCAx+gAwIBAgIBATANBgkqhkiG9w0BAQsFADAzMREwDwYDVQQDDAhrdW1h
496495
#> bW90bzERMA8GA1UECgwITmFub25leHQxCzAJBgNVBAYTAk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SIb3
512-
#> DQEBCwUAA4ICAQA9ONCt0Ms6T9pz8jOiS++aEfYd9rOxAPHjqV0WtEIt5XqgbLmy
513-
#> UBqEho3gW6gPXT99AOzAAF93QHIoSHeaLLskbRsO5AtvhaFUx0D9tkcZCk46uT4i
514-
#> E4vk+H64r/EAaedkowA7c54vwHP+0XnDp8FKWDQaj9UWFC7WPnoYiAqu274YHpP2
515-
#> HDneTf2qb0+ALI52/8EL7YKbsAOpi42x35die9qS2zYbA8CNThDvWsMFCviC8bgM
516-
#> YAnH/5bqrzh9VyFn6EasDk7NXt8Gyadn7avZRWDjbKvEwrBbvmoWUJh0YBShMZSy
517-
#> I+88xHid9WJWJYGNL7fBvVxzfnew8cVU0D20YWK2WN/JMrNKg570fhIGSXW2rNRw
518-
#> x/hZ7a3JdADmUSMV8YRZmLIx48P/X7CgEyhZZVWWxPez0vz6srOOxLvxTod84CDB
519-
#> ApyWcm5GylpkRtMZdX4fkvZtc22Hi21cjZTjL1OU8olRgjycRuxqJI+zBMlepUk+
520-
#> jYGcMp4mczoK+KCqZI9BR5M4hs4nurE2QDaeEW8gC6tM4KlP5O+dI+CjXb8QV6IZ
521-
#> VgfxXVSch+9LpCynaQf+JdomygH35d+XYsps7KjkASJeig9poT7QdDqpWSAyID21
522-
#> RAWLnGaioVrEqp5SDiVEGyh0bX4fmSFWXv1TorfLDNbB1GAm6pGXn8yLjQ==
498+
#> ADCCAgoCggIBAKgWqagLiM5FC5EuvEWA3drnGLa9E5oPUq9ITajT7AYtSE8gW9WZ
499+
#> tIWK631uyeJyxZ8k+D/REkV7dJJONDKZ4csyNgoVSoLlswW7OuqoOxT7wA6laa5b
500+
#> ld8fRKDQkRnhV/qE4YQvPvH1TXUBOqGfg8EdcusN3p17vB2j17RtlnlNSiTGavkn
501+
#> fz8xsNsowJjWLYz05ZMzkiL37cjccDgP0/gG97w4aRSZtaLJSWNs/EKjzKhIe2iI
502+
#> kMFafiG9FABJF5qhh5L0vWdvfncwcWo2wQhvDTX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lM
518+
#> ZhIy04rDO8ghT7TImEoi8Z36prDvulETbN0t2RNNXqE4nc/fNEl/WNAx61PeZdZ7
519+
#> 0uktJVR7ekSr6rQILCLYagEuCOhlc7Mvrxf0LIXQCuGmzDxIpaKuC3UbXNBwAGDl
520+
#> THfQzCmb9+tO9EO5nbs9C7CHNhnWtw2sgh+uRlqgg2ps10/QHvL9rQAgcThwmkAT
521+
#> gBVWwO072B2m5H+2BIyi/05hBfW0r0z3b49ay3QspwSLktY6X472jV0GPg==
523522
#> -----END CERTIFICATE-----
524-
#> ",""),rs=c(10407,-190365515,-1460862478,1356191947,1879828880,1039554641,2031211998))'
523+
#> ",""),rs=c(10407,-455422690,750700295,1273478044,1219766253,-2043149878,1421521091))'
525524
```
526525
The printed value may be deployed directly on a remote machine.
527526

@@ -754,10 +753,10 @@ daemons(4)
754753
vec <- c(1, 1, 4, 4, 1, 1, 1, 1)
755754
system.time(mirai_map(vec, Sys.sleep)[])
756755
#> user system elapsed
757-
#> 0.003 0.003 4.007
756+
#> 0.004 0.002 4.006
758757
system.time(parLapply(cl, vec, Sys.sleep))
759758
#> user system elapsed
760-
#> 0.010 0.004 8.013
759+
#> 0.005 0.007 8.010
761760
```
762761
`.args` is used to specify further constant arguments to `.f` - the 'mean' and 'sd' in the example below:
763762

@@ -767,13 +766,13 @@ with(
767766
mirai_map(1:3, rnorm, .args = list(mean = 20, sd = 2))[]
768767
)
769768
#> [[1]]
770-
#> [1] 20.27145
769+
#> [1] 21.88944
771770
#>
772771
#> [[2]]
773-
#> [1] 20.55287 22.25358
772+
#> [1] 17.87407 20.08740
774773
#>
775774
#> [[3]]
776-
#> [1] 20.18246 20.24844 19.74873
775+
#> [1] 21.64744 18.48347 16.43075
777776
```
778777
Use `...` to further specify objects referenced but not defined in `.f` - the 'do' in the anonymous function below:
779778

@@ -785,16 +784,16 @@ ml <- mirai_map(
785784
)
786785
#> Warning: mirai is launching one local daemon for a map operation as none previously set
787786
ml
788-
#> < mirai map [3/3] >
787+
#> < mirai map [1/3] >
789788
ml[]
790789
#> $a
791-
#> [1] "c8"
790+
#> [1] "88"
792791
#>
793792
#> $b
794-
#> [1] 96 66
793+
#> [1] 39 3b
795794
#>
796795
#> $c
797-
#> [1] "6b20bb"
796+
#> [1] "1b5f6c"
798797
```
799798
Use of `mirai_map()` assumes that `daemons()` have previously been set. If not then one (non-dispatcher) daemon is set to allow the function to proceed. This ensures safe behaviour, but is unlikely to be optimal, so please ensure daemons are set beforehand.
800799

vignettes/parallel.Rmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ status(cl)
5050
#> [1] 4
5151
#>
5252
#> $daemons
53-
#> [1] "abstract://e755083adb3ac002d81d87c7"
53+
#> [1] "abstract://4fc130b92777dbce706aaaa8"
5454
stop_cluster(cl)
5555
```
5656
Making a cluster specifying 'url' without 'remote' causes the shell commands for manual deployment of nodes to be printed to the console.
@@ -60,10 +60,10 @@ cl <- make_cluster(n = 2, url = host_url())
6060
#> Shell commands for deployment on nodes:
6161
#>
6262
#> [1]
63-
#> Rscript -e 'mirai::daemon("tcp://hostname:41567",rs=c(10407,-1229812554,-355079233,-704283916,613800293,-1049741598,-1259508485))'
63+
#> Rscript -e 'mirai::daemon("tcp://hostname:38547",rs=c(10407,987529368,-709709383,-455625178,-350041489,-644694556,1812636565))'
6464
#>
6565
#> [2]
66-
#> Rscript -e 'mirai::daemon("tcp://hostname:41567",rs=c(10407,-936602309,482053993,1829342693,1529156475,2009204106,1430761999))'
66+
#> Rscript -e 'mirai::daemon("tcp://hostname:38547",rs=c(10407,2025237564,31519412,1895592412,1818446374,-452272375,1687922752))'
6767
stop_cluster(cl)
6868
```
6969

@@ -85,10 +85,10 @@ doParallel::registerDoParallel(cl)
8585
m <- matrix(rnorm(9), 3, 3)
8686
foreach(i = 1:nrow(m), .combine = rbind) %dopar%
8787
(m[i, ] / mean(m[i, ]))
88-
#> [,1] [,2] [,3]
89-
#> result.1 0.6168828 1.1209518 1.2621654
90-
#> result.2 1.9631338 0.3970546 0.6398116
91-
#> result.3 1.8112756 8.5974163 -7.4086918
88+
#> [,1] [,2] [,3]
89+
#> result.1 0.5860066 1.0688031 1.3451903
90+
#> result.2 0.6856291 -0.1415699 2.4559407
91+
#> result.3 0.8224936 1.6700118 0.5074946
9292
# simple parallel matrix multiply
9393
a <- matrix(1:16, 4, 4)
9494
b <- t(a)

0 commit comments

Comments
 (0)