From 6b22b25466525051a11010dfa69637b904abb40f Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Wed, 1 Nov 2023 10:54:48 +0000 Subject: [PATCH] moves parallel to enhances --- DESCRIPTION | 6 +-- NEWS.md | 4 +- vignettes/mirai.Rmd | 96 ++++++++++++++++++++++----------------------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae3f8a9a8..f13f3d348 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mirai Type: Package Title: Minimalist Async Evaluation Framework for R -Version: 0.11.0.9021 +Version: 0.11.0.9022 Description: Lightweight parallel code execution and distributed computing. Designed for simplicity, a 'mirai' evaluates an R expression asynchronously, on local or network resources, resolving automatically upon completion. @@ -23,9 +23,9 @@ Encoding: UTF-8 Depends: R (>= 3.5) Imports: - nanonext (>= 0.10.2.9021), - parallel + nanonext (>= 0.10.2.9024) Enhances: + parallel, promises Suggests: later, diff --git a/NEWS.md b/NEWS.md index 572fd81b4..3ee380135 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# mirai 0.11.0.9021 (development) +# mirai 0.11.0.9022 (development) * Adds 'mirai' method for 'as.promise()' from the {promises} package (if available). This functionality is merged from the package {mirai.promises}, allowing use of the promise pipe `%...>%` with a 'mirai'. * Parallel clusters (the alternative communications backend for R) now work with existing R versions, no longer requiring R >= 4.4. @@ -12,7 +12,7 @@ * Fixes supplying an `ssh_config()` specifying tunnelling to the 'remote' argument of `daemons()`. * Fixes the print method for a subset 'miraiCluster' (thanks @HenrikBengtsson #83). * Removes the deprecated deferred evaluation pipe `%>>%`. -* Requires nanonext >= [0.10.2.9019]. +* Requires nanonext >= [0.10.2.9024]. # mirai 0.11.0 diff --git a/vignettes/mirai.Rmd b/vignettes/mirai.Rmd index d238c92ca..2313e5141 100644 --- a/vignettes/mirai.Rmd +++ b/vignettes/mirai.Rmd @@ -69,7 +69,7 @@ Upon completion, the 'mirai' resolves automatically to the evaluated result. ```r m$data |> str() -#> num [1:100000000] 57.804 -1.941 -7.661 0.387 0.777 ... +#> num [1:100000000] 0.196 2.357 -6.271 0.685 2.239 ... ``` Alternatively, explicitly call and wait for the result using `call_mirai()`. @@ -77,7 +77,7 @@ Alternatively, explicitly call and wait for the result using `call_mirai()`. ```r call_mirai(m)$data |> str() -#> num [1:100000000] 57.804 -1.941 -7.661 0.387 0.777 ... +#> num [1:100000000] 0.196 2.357 -6.271 0.685 2.239 ... ``` 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: @@ -94,7 +94,7 @@ args <- list(m = runif(1), n = 1e8) m <- mirai(.expr = expr, .args = args) call_mirai(m)$data |> str() -#> num [1:100000000] 0.123 0.733 0.649 1.472 5.71 ... +#> num [1:100000000] 0.953 0.357 -1.377 -0.939 1.481 ... ``` [« Back to ToC](#table-of-contents) @@ -221,12 +221,12 @@ status() #> #> $daemons #> i online instance assigned complete -#> abstract://2c91f63f732bdd18c473ec80 1 1 1 0 0 -#> abstract://3b690e927a6d8d9be7b8eb64 2 1 1 0 0 -#> abstract://2c4aa81c2d6e20d10998049f 3 1 1 0 0 -#> abstract://4521e936800ac3da2a5cce9e 4 1 1 0 0 -#> abstract://96c4b425a2eda1175e24a33d 5 1 1 0 0 -#> abstract://12f6dc8cdb6aa4fabed7300e 6 1 1 0 0 +#> abstract://d0acbf797fca7d8ad57ce6db 1 1 1 0 0 +#> abstract://9193e16129b32a48f5af1953 2 1 1 0 0 +#> abstract://4c9c493f1b310490627d4809 3 1 1 0 0 +#> abstract://52f8135cb023b13b443da89a 4 1 1 0 0 +#> abstract://31cbcb2b9ff93c123c110b51 5 1 1 0 0 +#> abstract://4423774e68363970ddb3578c 6 1 1 0 0 ``` The default `dispatcher = TRUE` 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. @@ -261,7 +261,7 @@ status() #> [1] 6 #> #> $daemons -#> [1] "abstract://d5a7ab71b50c27f6e81196d0" +#> [1] "abstract://f452a388caafaa22825cb163" ``` 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. @@ -352,7 +352,7 @@ By specifying `dispatcher = FALSE`, remote daemons connect directly to the host ```r daemons(url = host_url(), dispatcher = FALSE) -#> [1] "tcp://hostname:35033" +#> [1] "tcp://hostname:42189" ``` Note that above, calling `host_url()` without a port value uses the default of '0'. This is a wildcard value that will automatically cause a free ephemeral port to be assigned. The actual assigned port is provided in the return value of the call, or it may be queried at any time via `status()`. @@ -368,7 +368,7 @@ status() #> [1] 0 #> #> $daemons -#> [1] "tcp://hostname:35033" +#> [1] "tcp://hostname:42189" ``` To reset all connections and revert to default behaviour: @@ -445,10 +445,10 @@ daemons(n = 2, url = host_url()) launch_remote(1:2) #> [1] -#> Rscript -e "mirai::daemon('tcp://hostname:40815',rs=c(10407,-1298605964,-1613285147,639709282,1751824507,-1051788928,-932623487))" +#> Rscript -e "mirai::daemon('tcp://hostname:36925',rs=c(10407,12447993,776969318,-1122538577,132652580,1015805653,-1905100398))" #> #> [2] -#> Rscript -e "mirai::daemon('tcp://hostname:39985',rs=c(10407,1124331931,1808224896,-1742832536,-639982197,-1545947632,1369966981))" +#> Rscript -e "mirai::daemon('tcp://hostname:34367',rs=c(10407,-1677977516,618003857,-1886215845,-1504767133,2041967051,556928152))" daemons(0) #> [1] 0 @@ -480,37 +480,37 @@ The generated self-signed certificate is available via `launch_remote()`. This f ```r launch_remote(1) #> [1] -#> Rscript -e "mirai::daemon('wss://hostname:44085/1',tls=c('-----BEGIN CERTIFICATE----- +#> Rscript -e "mirai::daemon('wss://hostname:32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t4pE1rEw +#> aC5/aDKYkfHNVAeeIzPUklS7SNrJHw2Ou66juVVWmQBAeTkPf6ZggN9W4tEV5oqv +#> bEdYGvJ6HiFnferXjkk+xwkeVDJ+c50R9z+qfBmVXU2raS9zUo8B4XAxgSkkt2/P +#> Xrokv8iO9c7qrPsRqh0tGnetYgR4ProHSORwbbaX++2b89R8LAfBExu6oCh1ENNh +#> hFbJR2VjNcZyeDXa6BZ+o/mITobStzAzSWzqEshEWZF4Xc/wD+45lKNSj2uFCXtL +#> gb+xtSJx4wiSbiihSwgS4v/OfIIGx8gwhdR87kaVnYc66yCj+xcj6mwyiw== #> -----END CERTIFICATE----- -#> ',''),rs=c(10407,1009925696,-5957311,851346958,-714207433,-1893795316,680318877))" +#> ',''),rs=c(10407,1573322550,847649855,1628623220,-2111267355,-395308702,-469637765))" ``` The printed value may be deployed directly on a remote machine. @@ -634,36 +634,36 @@ cl parallel::parLapply(cl, 1:5, rnorm) #> [[1]] -#> [1] -0.9836203 +#> [1] -2.100108 #> #> [[2]] -#> [1] 1.0656311 0.5503744 +#> [1] -1.204032 -1.042151 #> #> [[3]] -#> [1] 0.2525613 -0.8804021 0.5376508 +#> [1] 0.1248739 1.1350673 -0.1112634 #> #> [[4]] -#> [1] -1.968415e-05 1.351948e+00 1.176134e+00 1.551765e+00 +#> [1] 0.6114177 -0.8331200 -0.1468930 -0.4842804 #> #> [[5]] -#> [1] -0.5270231 0.4128853 -0.1984081 0.8376930 -1.1472594 +#> [1] -0.7784605 -0.7929214 -1.2540343 -1.0441703 0.3732057 status(cl) #> $connections #> [1] 4 #> #> $daemons -#> [1] "abstract://757f162f5903b2ccf58e3782" +#> [1] "abstract://193e22ffb1ef8c82ced3ff97" stop_cluster(cl) cl <- make_cluster(n = 2, url = host_url()) #> Shell commands for deployment on nodes: #> [1] -#> Rscript -e "mirai::daemon('tcp://hostname:39797',rs=c(10407,-1845852469,625033104,1695168081,-1539269666,1803884231,-226338724))" +#> Rscript -e "mirai::daemon('tcp://hostname:33829',rs=c(10407,1306966007,-787489844,329801309,-1459926662,1567557811,2114850392))" #> #> [2] -#> Rscript -e "mirai::daemon('tcp://hostname:39797',rs=c(10407,-951338746,-573234744,-1153439598,1348855247,1553839924,-21456304))" +#> Rscript -e "mirai::daemon('tcp://hostname:33829',rs=c(10407,1230136452,360255358,885527131,991567976,-445341772,345044727))" stop_cluster(cl) ```