-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_test
108 lines (78 loc) · 3 KB
/
parallel_test
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
100
101
102
103
104
105
106
107
#Test performance of parallel processes.
#Note that mode="multicore" is appropriate for Unix -- this does not work on Windows and I am not sure if it works on Mac
#Needs to be modified if there are not 16 cores available.
#Don't know how many cores are available? parallel::detectCores()
#Output: delta.time.RData
library(mlr)
library(parallelMap)
numeric_ps = makeParamSet(
makeNumericParam("C", lower = 0.5, upper = 2.0),
makeNumericParam("sigma", lower = 0.5, upper = 2.0)
)
ctrl = makeTuneControlRandom(maxit=20000L)
rdesc = makeResampleDesc("CV", iters = 3L)
delta.time.serial <- rep(NA, 10)
delta.time.p2 <- rep(NA, 10)
delta.time.p4 <- rep(NA, 10)
delta.time.p8 <- rep(NA, 10)
delta.time.p16 <- rep(NA, 10)
for (i in 1:10){
#In serial
start.time.serial <- Sys.time()
res.serial = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc,
par.set = numeric_ps, control = ctrl)
stop.time.serial <- Sys.time()
delta.time.serial[i] <- stop.time.serial - start.time.serial
#In parallel with 2 CPUs
start.time.parallel.2 <- Sys.time()
parallelStart(mode="multicore", cpu=2, level="mlr.tuneParams")
res.parallel.2 = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc,
par.set = numeric_ps, control = ctrl)
parallelStop()
stop.time.parallel.2 <- Sys.time()
delta.time.p2[i] <- stop.time.parallel.2 - start.time.parallel.2
#In parallel with 4 CPUs
start.time.parallel.4 <- Sys.time()
parallelStart(mode="multicore", cpu=4, level="mlr.tuneParams")
res.parallel.4 = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc,
par.set = numeric_ps, control = ctrl)
parallelStop()
stop.time.parallel.4 <- Sys.time()
delta.time.p4[i] <- stop.time.parallel.4 - start.time.parallel.4
#In parallel with 8 CPUs
start.time.parallel.8 <- Sys.time()
parallelStart(mode="multicore", cpu=8, level="mlr.tuneParams")
res.parallel.8 = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc,
par.set = numeric_ps, control = ctrl)
parallelStop()
stop.time.parallel.8 <- Sys.time()
delta.time.p8[i] <- stop.time.parallel.8 - start.time.parallel.8
#In parallel with 16 CPUs
start.time.parallel.16 <- Sys.time()
parallelStart(mode="multicore", cpu=16, level="mlr.tuneParams")
res.parallel.16 = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc,
par.set = numeric_ps, control = ctrl)
parallelStop()
stop.time.parallel.16 <- Sys.time()
delta.time.p16[i] <- stop.time.parallel.16 - start.time.parallel.16
}
delta.time <- rbind(delta.time.serial, delta.time.p2, delta.time.p4, delta.time.p8, delta.time.p16)
save(delta.time, file="delta.time.RData")
library(mlr)
library(parallel)
system.time({t = lapply(1:4,function(i) {
m = matrix(1:10^6,ncol=1000)
t = system.time({
m%*%t(m)
})
return(t)
})})
system.time({
mc_t = mclapply(1:4,function(m){
m = matrix(1:10^6,ncol=1000)
t = system.time({
m%*%t(m)
})
return(t)
},mc.cores=2)
})