registerDoParabar {doParabar}R Documentation

Register Parallel Implementation

Description

The registerDoParabar() function registers the provided backend created by parabar::start_backend() to be used as the parallel processing backend for the foreach::%dopar% operator implementation.

Usage

registerDoParabar(backend)

Arguments

backend

An object of class parabar::Backend representing the backend to be used for the foreach::%dopar% operator implementation.

Details

Additional information about the registered parallel backend can be extracted using the foreach::getDoParName(), foreach::getDoParRegistered(), foreach::getDoParVersion(), and foreach::getDoParWorkers() functions. See the Examples section.

Value

The registerDoParabar() function returns void.

Completeness

The parallel backend implementation for the foreach::%dopar% operator is provided by the doPar() function. Please check the Details section of its documentation to understand the extent of completeness of the implementation.

See Also

doParabar, doPar(), parabar::start_backend() and parabar::stop_backend().

Examples

# Manually load the libraries.
library(doParabar)
library(parabar)
library(foreach)

# Create an asynchronous `parabar` backend.
backend <- start_backend(cores = 2, cluster_type = "psock", backend_type = "async")

# Register the backend with the `foreach` package for the `%dopar%` operator.
registerDoParabar(backend)

# Get the parallel backend name.
getDoParName()

# Check that the parallel backend has been registered.
getDoParRegistered()

# Get the current version of backend registration.
getDoParVersion()

# Get the number of cores used by the backend.
getDoParWorkers()

# Define some variables strangers to the backend.
x <- 10
y <- 100
z <- "Not to be exported."

# Used the registered backend to run a task in parallel via `foreach`.
results <- foreach(i = 1:300, .export = c("x", "y"), .combine = c) %dopar% {
    # Sleep a bit.
    Sys.sleep(0.01)

    # Compute and return.
    i + x + y
}

# Show a few results.
head(results, n = 10)
tail(results, n = 10)

# Verify that the variable `z` was not exported.
try(evaluate(backend, z))

# To make packages available on the backend, see the `.packages` argument.

# Stop the backend.
stop_backend(backend)


[Package doParabar version 1.0.2 Index]