-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathparallelStop.R
56 lines (50 loc) · 1.98 KB
/
parallelStop.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
#' @title Stops parallelization.
#'
#' @description
#' Sets mode to \dQuote{local}, i.e., parallelization is turned
#' off and all necessary stuff is cleaned up.
#'
#' For socket and mpi mode `parallel::stopCluster()` is called.
#'
#' For BatchJobs mode the subdirectory of the `storagedir`
#' containing the exported objects is removed.
#'
#' After a subsequent call of [parallelStart()], no exported objects
#' are present on the slaves and no libraries are loaded,
#' i.e., you have clean R sessions on the slaves.
#'
#' @return Nothing.
#' @export
parallelStop = function() {
# only do something if we are in "started" state
if (isStatusStarted()) {
if (isModeSocket() || isModeMPI()) {
# only stop if we registred one (exception in parallelStart can happen)
# the whole following code is full of horrible stuff but I cannot change that
# parallel is really buggy and the design is horrible
# a) stopCluster will not work when called via stopCluster(NULL) on the default cluster
# Through some envir assign "magic" cl gets set to NULL before it is stopped
# via S3 inheritance
# b) stopCluster will also throw amn exception when none is registered. great, and apparently
# we have no way of asking whether one is alrealdy registered.
cl = get("default", envir = getFromNamespace(".reg", ns = "parallel"))
if (!is.null(cl)) {
stopCluster(cl = cl)
setDefaultCluster(NULL)
}
} else if (isModeBatchJobs()) {
# delete registry file dir
unlink(getBatchJobsRegFileDir(), recursive = TRUE)
}
if (!isModeLocal()) {
showInfoMessage("Stopped parallelization. All cleaned up.")
}
}
# remove our local export collection (local + multicore mode)
rm(list = ls(PKG_LOCAL_ENV), envir = PKG_LOCAL_ENV)
# in any case be in local / stopped mode now
options(parallelMap.mode = MODE_LOCAL)
options(parallelMap.status = STATUS_STOPPED)
# FIXME do we clean up log files?
invisible(NULL)
}