Parallel Processing in the sspse Package

Share:

Description

As the estimation requires MCMC, sspse can take advantage of multiple CPUs or CPU cores on the system on which it runs, as well as computing clusters. It uses package parallel and snow to facilitate this, and supports MPI cluster type and likely PSOCK.

Usage

1
2
beginparallel(parallel = 1, type = "MPI", seed = NULL,
  packagenames = c("sspse"), verbose = TRUE)

Arguments

parallel

scale; Number of threads in which to run the sampling. Defaults to 1 (no parallelism).

type

API to use for parallel processing. Supported values are "MPI" and "PSOCK". Defaults to using the parallel package with MPI clusters.

seed

integer; random number integer seed. Defaults to NULL to use whatever the state of the random number generator is at the time of the

packagenames

Names of packages in which load to get the package to run functions in addition to those autodetected. This argument should not be needed outside of very strange setups.

verbose

logical; if this is TRUE, the program will print out additional information. call.

Details

The number of nodes used and the parallel API are controlled using the parallel and type arguments.

PSOCK clusters

The parallel package is used with PSOCK clusters by default, to utilize multiple cores on a system. The number of cores on a system can be determined with the detectCores function.

This method works with the base installation of R on all platforms, and does not require additional software.

Examples

 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
## Not run: 
# Uses 2 SOCK clusters for MCMLE estimation
N0 <- 200
n <- 100
K <- 10

# Create probabilities for a Waring distribution
# with scaling parameter 3 and mean 5, but truncated at K=10.
probs <- c(0.33333333,0.19047619,0.11904762,0.07936508,0.05555556,
           0.04040404,0.03030303,0.02331002,0.01831502,0.01465201)
probs <- probs / sum(probs)

# Look at the degree distribution for the prior
# Plot these if you want
# plot(x=1:K,y=probs,type="l")
# points(x=1:K,y=probs)
#
# Create a sample
#
set.seed(1)
pop<-sample(1:K, size=N0, replace = TRUE, prob = probs)
s<-sample(pop, size=n, replace = FALSE, prob = pop)

out <- posteriorsize(s=s,interval=10,parallel=2)
plot(out, HPD.level=0.9,data=pop[s])
summary(out, HPD.level=0.9)
# Let's look at some MCMC diagnostics
plot(out, HPD.level=0.9,mcmc=TRUE)

## End(Not run)