makeRegistry
constructs the inter-communication object for all functions in batchtools
.
All communication transactions are processed via the file system:
All information required to run a job is stored as JobCollection
in a file in the
a subdirectory of the file.dir
directory.
Each jobs stores its results as well as computational status information (start time, end time, error message, ...)
also on the file system which is regular merged parsed by the master using syncRegistry
.
After integrating the new information into the Registry, the Registry is serialized to the file system via saveRegistry
.
Both syncRegistry
and saveRegistry
are called whenever required internally.
Therefore it should be safe to quit the R session at any time.
Work can later be resumed by calling loadRegistry
which de-serializes the registry from
the file system.The registry created last is saved in the package namespace (unless make.default
is set to
FALSE
) and can be retrieved via getDefaultRegistry
.
Canceled jobs and repeatedly submitted jobs may leave stray files behind.
These can be swept using sweepRegistry
.
clearRegistry
completely erases all jobs from a registry, including log files and results,
and thus allows you to start over.
makeRegistry(file.dir = "registry", work.dir = getwd(),
conf.file = findConfFile(), packages = character(0L),
namespaces = character(0L), source = character(0L),
load = character(0L), seed = NULL, make.default = TRUE)getDefaultRegistry()
setDefaultRegistry(reg)
loadRegistry(file.dir = getwd(), work.dir = NULL,
conf.file = findConfFile(), make.default = TRUE, update.paths = FALSE)
saveRegistry(reg = getDefaultRegistry())
sweepRegistry(reg = getDefaultRegistry())
clearRegistry(reg = getDefaultRegistry())
syncRegistry(reg = getDefaultRegistry())
character(1)
]
Path where all files of the registry are saved.
Default is directory “registry” in the current working directory.
The provided path will get normalized unless it is given relative to the home directory
(i.e., starting with “~”). Note that some templates do not handle relative paths well. If you pass NA
, a temporary directory will be used.
This way, you can create disposable registries for btlapply
or examples.
By default, the temporary directory tempdir()
will be used.
If you want to use another directory, e.g. a directory which is shared between nodes,
you can set it in your configuration file by setting the variable temp.dir
.
character(1)
]
Working directory for R process for running jobs.
Defaults to the working directory currently set during Registry construction (see getwd
).
loadRegistry
uses the stored work.dir
, but you may also explicitly overwrite it,
e.g., after switching to another system.The provided path will get normalized unless it is given relative to the home directory (i.e., starting with “~”). Note that some templates do not handle relative paths well.
character(1)
]
Path to a configuration file which is sourced while the registry is created.
For example, you can set cluster functions or default resources in it.
The script is executed inside the environment of the registry after the defaults for all variables are set,
thus you can set and overwrite slots, e.g. default.resources = list(walltime = 3600)
to set default resources. The file lookup defaults to a heuristic which first tries to read “batchtools.conf.R” in the current working directory.
If not found, it looks for a configuration file “config.R” in the OS dependent user configuration directory
as reported by via rappdirs::user_config_dir("batchtools", expand = FALSE)
(e.g., on linux this
usually resolves to “~/.config/batchtools/config.R”).
If this file is also not found, the heuristic finally tries to read the file “.batchtools.conf.R” in the
home directory (“~”).
Set to character(0)
if you want to disable this heuristic.
character
]
Packages that will always be loaded on each node.
Uses require
internally.
Default is character(0)
.character
]
Same as packages
, but the packages will not be attached.
Uses requireNamespace
internally.
Default is character(0)
.character
]
Files which should be sourced on the slaves prior to executing a job.
Calls sys.source
using the .GlobalEnv
.character
]
Files which should be loaded on the slaves prior to executing a job.
Calls load
using the .GlobalEnv
.integer(1)
]
Start seed for jobs. Each job uses the (seed
+ job.id
) as seed.
Default is a random number in the range [1, .Machine$integer.max/2
].logical(1)
]
If set to TRUE
, the created registry is saved inside the package
namespace and acts as default registry. You might want to switch this
off if you work with multiple registries simultaneously.
Default is TRUE
.Registry
]
Registry. If not explicitly passed, uses the default registry (see setDefaultRegistry
).logical(1)
]
If set to TRUE
, the file.dir
and work.dir
will be updated in the registry. Note that this is
likely to break computation on the system! Only do this if no jobs are currently running. Default is FALSE
.
If the provided file.dir
does not match the stored file.dir
, loadRegistry
will return a
registry in read-only mode.makeRegistry
, loadRegistry
, getDefaultRegistry
and setDefaultRegistry
return an environment of class “Registry” with the following slots:
file.dir
[path]:work.dir
[path]:temp.dir
[path]:file.dir
is NA
.packages
[character()]:namespaces
[character()]:seed
[integer(1)]:seed + job.id
is set.cluster.functions
[cluster.functions]:conf.file
. Set via a call to makeClusterFunctions
. See example.default.resources
[named list()]:conf.file
. Named list of default resources.max.concurrent.jobs
[integer(1)]:conf.file
. Maximum number of concurrent jobs for a single user and current registry on the system.
submitJobs
will try to respect this setting.defs
[data.table]:status
[data.table]:getJobStatus
.resources
[data.table]:getJobResources
.tags
[data.table]:The other functions saveRegistry
, syncRegistry
, sweepRegistry
and clearRegistry
return TRUE
if the registry has been altered and successfully stored on the file system.
tmp = makeRegistry(file.dir = NA, make.default = FALSE)
print(tmp)
# Set cluster functions to interactive mode and start jobs in external R sessions
tmp$cluster.functions = makeClusterFunctionsInteractive(external = TRUE)
# Change packages to load
tmp$packages = c("MASS")
saveRegistry(reg = tmp)
Run the code above in your browser using DataLab