forked from mlr-org/parallelMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternal_test.R
68 lines (61 loc) · 1.42 KB
/
external_test.R
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
library(BBmisc)
library(parallelMap)
library(testthat)
doJobs = function(type, mode) {
job = switch(type,
short = function(x) {
x^2
},
long = function(x) {
Sys.sleep(5)
x^2
},
export = function(x) {
#i = parallelGetExported("i")
i * x^2
},
lib = function(x) {
m = randomForest(Species~., data=iris, ntree=1)
x^2
}
)
xs = 1:2
if (type == "export") {
i = 1
#parallelExport("i")
}else if (type == "lib") {
parallelLibrary("randomForest")
}
st = system.time({
ys = parallelMap(job, xs, simplify = TRUE)
})
#print(ys)
expect_equal(ys, c(1, 4))
messagef("type=%s; mode=%s; time: %2f", type, mode, st[3])
}
doTest = function(type, mode, cpus) {
parallelStart(mode = mode, cpus = cpus)
doJobs(type, mode)
parallelStop()
catf("")
}
#doTest("short", "local")
#doTest("short", "multicore", 2)
#doTest("short", "socket", 2)
#doTest("short", "snowfall", 2)
doTest("short", "BatchJobs", 2)
#doTest("long", "local")
#doTest("long", "multicore", 2)
#doTest("long", "socket", 2)
#doTest("long", "snowfall", 2)
doTest("long", "BatchJobs", 2)
#doTest("export", "local")
#doTest("export", "multicore", 2)
#doTest("export", "socket", 2)
#doTest("export", "snowfall", 2)
doTest("export", "BatchJobs", 2)
#doTest("lib", "local")
#doTest("lib", "multicore", 2)
#doTest("lib", "socket", 2)
#doTest("lib", "snowfall", 2)
doTest("lib", "BatchJobs", 2)