Skip to content

Instantly share code, notes, and snippets.

@mja
Created November 2, 2012 11:56
Show Gist options
  • Save mja/4000654 to your computer and use it in GitHub Desktop.
Save mja/4000654 to your computer and use it in GitHub Desktop.
Running OpenMx with multicore
require(OpenMx)
library(parallel)
data(demoOneFactor)
manifests <- names(demoOneFactor)
latents <- c("G")
factorModel <- mxModel(name="One Factor",
type="RAM",
manifestVars = manifests,
latentVars = latents,
mxPath(from=latents, to=manifests),
mxPath(from=manifests, arrows=2),
mxPath(from=latents, arrows=2, free=FALSE, values=1.0),
mxData(observed=cov(demoOneFactor), type="cov", numObs=500)
)
# limit to 1 thread for multicore
mxOption(NULL, 'Number of Threads', 1)
# vary number of observations for data
factorFits <- mclapply(seq(500, 1000, by=100),
function(obs, model) mxRun(mxModel(model, mxData(observed=cov(demoOneFactor), type="cov", numObs=obs))),
model=factorModel, mc.cores=6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment