-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtestscript.R
94 lines (67 loc) · 1.78 KB
/
testscript.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
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
########################################################
## Test cluster
library(threadpool)
dir()
## Generate some tasks
cl_name <- "cluster"
n <- 20
x <- seq_len(n)
x <- as.list(x)
f <- function(num) {
pid <- Sys.getpid()
cat("PID ", pid, " is running task ", num, "\n")
Sys.sleep(1)
paste0(pid, " is finished running ", num, "!")
}
## Run cluster as it should
cluster_initialize(cl_name, x, f, env = globalenv())
cl <- cluster_join(cl_name)
cluster_run(cl)
r <- cluster_reduce(cl)
cluster_shutdown(cl)
delete_cluster(cl_name)
## More debug!
cluster_initialize(cl_name, x, f, env = globalenv())
cl <- cluster_join(cl_name)
onecycle <- function(cl) {
jt <- cluster_next_task(cl)
print(class(jt))
msg <- capture.output(result <- threadpool:::task_run(jt$value,
globalenv()))
print(msg)
cluster_finish_task(cl, jt, result)
}
replicate(n, onecycle(cl))
jq <- cl$jobqueue
is_empty_input(jq)
is_empty_output(jq)
jq$queue$list()
dequeue(jq)
delete_cluster(cl_name)
## Debug cluster
cl <- cluster_create(cl_name)
jq <- cl$jobqueue
is_empty_input(jq)
is_empty_output(jq)
cluster_add_tasks(cl, x, f)
threadpool:::exportEnv(cl, globalenv())
peek(cl$jobqueue)
jq$queue$list()
jt <- cluster_next_task(cl)
jq$queue$list()
result <- threadpool:::task_run(jt$value, globalenv())
shelf2output(jq, jt$key, result)
is_empty_input(jq)
is_empty_output(jq)
shelf_list(jq)
jq$queue$list()
dequeue(jq)
jq$queue$list()
jt <- cluster_next_task(cl)
msg <- capture.output(result <- threadpool:::task_run(jt$value, globalenv()))
print(msg)
cluster_finish_task(cl, jt, result)
jq$queue$list()
is_empty_input(jq)
is_empty_output(jq)
########################################################