is it possible to run spatstat functions on multiple processors

334 Views Asked by At

I am curios to know if spastat functions like envelope or MAD tests can be run on multiple processors on a machine to speed up calculations? Is there any document or tutorial to do this?

Thank you.

1

There are 1 best solutions below

3
On BEST ANSWER


Unfortunately, parallelisation is not an integrated part of spatstat, but rather left to the user. For envelopes and MAD tests the easiest option is probably to run envelope with a smaller number of realisations on each core and then combine the results using pool.envelope. How to run envelope in parallel may depend on your setup. A simple possibility is to use parallel::mclapply which I know works out of the box on linux, but much better cross platform alternatives are surely available in packages on CRAN:

library(spatstat)
ppplist <- replicate(4, cells, simplify = FALSE)
envlist <- parallel::mclapply(ppplist, spatstat::envelope, savefuns = TRUE, nsim = 10)
envfinal <- do.call(pool, envlist)
envfinal
#> Pointwise critical envelopes for K(r)
#> and observed value for 'X[[i]]'
#> Obtained from 40 simulations of CSR
#> Alternative: two.sided
#> Significance level of pointwise Monte Carlo test: 2/41 = 0.0488
#> .....................................................................
#>      Math.label     Description                                      
#> r    r              distance argument r                              
#> obs  hat(K)[obs](r) observed value of K(r) for data pattern          
#> theo K[theo](r)     theoretical value of K(r) for CSR                
#> lo   hat(K)[lo](r)  lower pointwise envelope of K(r) from simulations
#> hi   hat(K)[hi](r)  upper pointwise envelope of K(r) from simulations
#> .....................................................................
#> Default plot formula:  .~r
#> where "." stands for 'obs', 'theo', 'hi', 'lo'
#> Columns 'lo' and 'hi' will be plotted as shading (by default)
#> Recommended range of argument r: [0, 0.25]
#> Available range of argument r: [0, 0.25]