File: BiocParallel_BatchtoolsParam.R

package info (click to toggle)
r-bioc-biocparallel 1.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,768 kB
  • sloc: cpp: 139; sh: 14; makefile: 8
file content (99 lines) | stat: -rw-r--r-- 2,624 bytes parent folder | download | duplicates (3)
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
92
93
94
95
96
97
98
99
## ----style, eval=TRUE, echo=FALSE, results="asis"--------------------------
BiocStyle::latex()

## ----setup, echo=FALSE-----------------------------------------------------
suppressPackageStartupMessages({
    library(BiocParallel)
})

## ----intro-----------------------------------------------------------------
library(BiocParallel)

## Pi approximation
piApprox <- function(n) {
    nums <- matrix(runif(2 * n), ncol = 2)
    d <- sqrt(nums[, 1]^2 + nums[, 2]^2)
    4 * mean(d <= 1)
}

piApprox(1000)

## Apply piApprox over
param <- BatchtoolsParam()
result <- bplapply(rep(10e5, 10), piApprox, BPPARAM=param)
mean(unlist(result))

## --------------------------------------------------------------------------
registryargs <- batchtoolsRegistryargs(
    file.dir = "mytempreg",
    work.dir = getwd(),
    packages = character(0L),
    namespaces = character(0L),
    source = character(0L),
    load = character(0L)
)
param <- BatchtoolsParam(registryargs = registryargs)
param

## --------------------------------------------------------------------------
fname <- batchtoolsTemplate("slurm")
cat(readLines(fname), sep="\n")

## ----simple_sge_example, eval=FALSE----------------------------------------
#  library(BiocParallel)
#  
#  ## Pi approximation
#  piApprox <- function(n) {
#      nums <- matrix(runif(2 * n), ncol = 2)
#      d <- sqrt(nums[, 1]^2 + nums[, 2]^2)
#      4 * mean(d <= 1)
#  }
#  
#  template <- system.file(
#      package = "BiocParallel",
#      "unitTests", "test_script", "test-sge-template.tmpl"
#  )
#  param <- BatchtoolsParam(workers=5, cluster="sge", template=template)
#  
#  ## Run parallel job
#  result <- bplapply(rep(10e5, 100), piApprox, BPPARAM=param)

## ----demo_sge, eval=FALSE--------------------------------------------------
#  library(BiocParallel)
#  
#  ## Pi approximation
#  piApprox <- function(n) {
#      nums <- matrix(runif(2 * n), ncol = 2)
#      d <- sqrt(nums[, 1]^2 + nums[, 2]^2)
#      4 * mean(d <= 1)
#  }
#  
#  template <- system.file(
#      package = "BiocParallel",
#      "unitTests", "test_script", "test-sge-template.tmpl"
#  )
#  param <- BatchtoolsParam(workers=5, cluster="sge", template=template)
#  
#  ## start param
#  bpstart(param)
#  
#  ## Display param
#  param
#  
#  ## To show the registered backend
#  bpbackend(param)
#  
#  ## Register the param
#  register(param)
#  
#  ## Check the registered param
#  registered()
#  
#  ## Run parallel job
#  result <- bplapply(rep(10e5, 100), piApprox)
#  
#  bpstop(param)

## ----sessionInfo, results="asis"-------------------------------------------
toLatex(sessionInfo())