Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 36d1d24
  • /
  • bootParallel.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:45cd14e09b3a35a6eeae70446bbd3ecae8f37335
directory badge
swh:1:dir:36d1d2425fc627c5172b397b4f25e2b00fd38892

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
bootParallel.R
suppressMessages(library(doParallel))
cl <- makePSOCKcluster(4)
registerDoParallel(cl)

cat(sprintf('doParallel %s\n', packageVersion('doParallel')))
junk <- matrix(0, 1000000, 8)
cat(sprintf('Size of extra junk data: %d bytes\n', object.size(junk)))

x <- iris[which(iris[,5] != "setosa"), c(1,5)]

trials <- 10000

ptime <- system.time({
  r <- foreach(icount(trials), .combine=cbind,
               .export='junk') %dopar% {
    ind <- sample(100, 100, replace=TRUE)
    result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
    coefficients(result1)
  }
})[3]
cat(sprintf('parallel foreach:                    %6.1f sec\n', ptime))

ptime2 <- system.time({
  snowopts <- list(preschedule=TRUE)
  r <- foreach(icount(trials), .combine=cbind,
               .export='junk', .options.snow=snowopts) %dopar% {
    ind <- sample(100, 100, replace=TRUE)
    result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
    coefficients(result1)
  }
})[3]
cat(sprintf('parallel foreach with prescheduling: %6.1f sec\n', ptime2))


ptime3 <- system.time({
  chunks <- getDoParWorkers()
  r <- foreach(n=idiv(trials, chunks=chunks), .combine=cbind,
               .export='junk') %dopar% {
    y <- lapply(seq_len(n), function(i) {
      ind <- sample(100, 100, replace=TRUE)
      result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
      coefficients(result1)
    })
    do.call('cbind', y)
  }
})[3]
cat(sprintf('chunked parallel foreach:            %6.1f sec\n', ptime3))

ptime4 <- system.time({
  mkworker <- function(x, junk) {
    force(x)
    force(junk)
    function(i) {
      ind <- sample(100, 100, replace=TRUE)
      result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
      coefficients(result1)
    }
  }
  y <- parLapply(cl, seq_len(trials), mkworker(x, junk))
  r <- do.call('cbind', y)
})[3]
cat(sprintf('parLapply:                           %6.1f sec\n', ptime4))

stime <- system.time({
  y <- lapply(seq_len(trials), function(i) {
    ind <- sample(100, 100, replace=TRUE)
    result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
    coefficients(result1)
  })
  r <- do.call('cbind', y)
})[3]
cat(sprintf('sequential lapply:                   %6.1f sec\n', stime))

stime2 <- system.time({
  r <- foreach(icount(trials), .combine=cbind) %do% {
    ind <- sample(100, 100, replace=TRUE)
    result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
    coefficients(result1)
  }
})[3]
cat(sprintf('sequential foreach:                  %6.1f sec\n', stime2))

stopCluster(cl)

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API