inst/doc/Parallel.R

## ---- echo = FALSE, message = FALSE, warning = FALSE--------------------------
library(ParallelLogger)

## -----------------------------------------------------------------------------
cluster <- makeCluster(numberOfThreads = 3)

## -----------------------------------------------------------------------------
fun <- function(x, constant) {
     return(x * constant)
}

## -----------------------------------------------------------------------------
x <- 1:3
clusterApply(cluster, x, fun, constant = 2)

## -----------------------------------------------------------------------------
doBigJob <- function(largeVector) {
  doTinyJob <- function(x){
    return(x^2)
  }
  cluster <- makeCluster(numberOfThreads = 3)
  clusterApply(cluster, largeVector, doTinyJob)
  stopCluster(cluster)
}

## -----------------------------------------------------------------------------
doTinyJob <- function(x){
  return(x^2)
}

doBigJob <- function(largeVector) {
  cluster <- makeCluster(numberOfThreads = 3)
  clusterApply(cluster, largeVector, doTinyJob)
  stopCluster(cluster)
}

## -----------------------------------------------------------------------------
stopCluster(cluster)

Try the ParallelLogger package in your browser

Any scripts or data that you put into this service are public.

ParallelLogger documentation built on Aug. 22, 2023, 5:11 p.m.