Parallel Computing in OpenMC

Introduction to Parallel Computing

Now that we understand how to run basic simulations, let's speed them up using parallel computing. Monte Carlo simulations are perfect for parallel computing since each particle is independent.

Parallel Methods

  • MPI: Multiple computers/processors
  • OpenMP: Multiple CPU cores
  • Hybrid: Combine both methods

When to Use

  • Large geometries
  • Many particles needed
  • Complex physics
  • Multiple computers available

Basic Parallel Usage

The simplest way to run in parallel is using MPI with the Python API:

Running with MPI

python
# Create your model as usual
model = openmc.Model(
    geometry=geometry,
    materials=materials,
    settings=settings
)

# Run with 4 processors
model.run(mpi_args=['mpiexec', '-n', '4'])

Using Multiple Cores

python
# Set number of threads
model.run(openmc_exec_kwargs={
    'threads': 4  # Use 4 CPU cores
})

Tip: Start with a small number of processors/cores to test your setup. Then scale up based on your needs and available resources.

Performance Tips

Best Practices

  • Use enough particles (10000 per processor)
  • Monitor memory usage
  • Check load balancing
  • Save results periodically

Common Issues

  • Too few particles per processor
  • Memory limitations
  • Network bottlenecks
  • File system contention

Example Settings

python
# Good settings for parallel runs
settings = openmc.Settings()
settings.particles = 100000  # Plenty for 4-8 processors
settings.batches = 100
settings.inactive = 20

# Optional: Track performance
settings.verbosity = 7  # Show timing info

Additional Resources