Running MCNP Simulations

From setup to execution and monitoring

Essential Setup

Before running any MCNP simulation, you need to ensure your environment is properly configured. MCNP requires access to nuclear data libraries and proper system settings to function correctly. The most critical requirement is setting the DATAPATH environment variable to point to your cross-section data.

Environment Configuration

bash
# Linux/Mac setup
export DATAPATH=/opt/mcnp/MCNP_DATA
export PATH=$PATH:/opt/mcnp/bin

# Windows setup  
set DATAPATH=C:\MCNP\MCNP_DATA
set PATH=%PATH%;C:\MCNP\bin

# Verify setup
mcnp6       # Run with no args to see version info

The DATAPATH variable tells MCNP where to find nuclear cross-section libraries. Without this, MCNP cannot access the nuclear data needed for transport calculations. The PATH variable should include the MCNP executable directory so you can run mcnp6 from any location.

Running Your First Simulation

Once your environment is configured, running MCNP simulations becomes straightforward. The basic command structure uses simple keyword arguments to specify input files, output destinations, and execution options.

Basic Execution

bash
# Simple run with default settings
mcnp6 i=uranium_sphere.i o=uranium_sphere.o

# Run with custom output file name
mcnp6 i=fuel_assembly.i n=fuel_results.out

# Continue from previous checkpoint
mcnp6 c i=fuel_assembly.i n=fuel_results.out r=fuel_assembly.r

The 'i=' parameter specifies your input file, while 'o=' or 'n=' designates the output file. MCNP will create several additional files during execution, including a RUNTPE file for checkpointing and restart capabilities. The 'c' option continues a previous calculation from where it left off.

Monitoring Progress

MCNP provides real-time feedback during execution through screen output and log files. For criticality calculations, you'll see k-effective values converging as the simulation progresses. The output shows cycle numbers, particle counts, and statistical information.

bash
# Monitor progress in real-time (while MCNP runs)
tail -f output.o

# Check for completion
grep "final estimated" output.o

The tail command lets you monitor MCNP's progress in real-time, while grep searches for completion indicators in the output file. For additional debugging, add a DBCN card to your input deck.

Parallel Processing

Modern MCNP simulations benefit significantly from parallel processing. MCNP can distribute particle histories across multiple CPU cores, dramatically reducing calculation time. The key is understanding how to specify the number of parallel tasks and manage memory allocation.

Shared Memory Parallelism

bash
# Run with 8 parallel tasks on one node
mcnp6 i=input.i o=output.o tasks 8

# Optimal task count (usually equals CPU cores)
mcnp6 i=input.i o=output.o tasks $(nproc)

The tasks parameter should typically equal the number of CPU cores on your system. Each task shares the available system memory. Too many tasks can slow down calculations due to memory contention and communication overhead.

Distributed Memory (MPI)

bash
# Run across multiple nodes with MPI
mpirun -np 32 mcnp6.mpi i=input.i o=output.o

# SLURM job script example
#!/bin/bash
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=16
#SBATCH --time=24:00:00
#SBATCH --mem=64G

srun mcnp6.mpi i=reactor.i o=reactor.o

MPI parallelism allows MCNP to run across multiple compute nodes, scaling to hundreds or thousands of cores. This requires the MPI-enabled version of MCNP (mcnp6.mpi) and appropriate job scheduler configuration. The total number of MPI ranks should balance communication overhead with computational efficiency.

Checkpoint and Restart

Long-running simulations need checkpoint capabilities to protect against system failures and time limits. MCNP automatically creates RUNTPE files that capture the complete simulation state, allowing seamless restarts from any checkpoint.

bash
# Add PRDMP card to your input deck for checkpointing:
#   PRDMP 2J 1    (controls dump/print frequency)

# Restart from checkpoint
mcnp6 c i=input.i o=output_new.o r=output.r

# Verify restart statistics match
grep "cycles" output.o output_new.o

The PRDMP card controls dump and print frequency. In MCNP, "J" means "jump" (use the default value for that position). When restarting, MCNP continues from the exact state saved in the RUNTPE file, maintaining statistical consistency. Always verify that restarted runs show continuous cycle numbering.

Troubleshooting Common Issues

Geometry Problems

Lost particles are the most common MCNP error, usually indicating geometry problems where particles enter undefined regions or encounter surface intersections. MCNP provides detailed tracking information to help identify these issues.

bash
# Plot geometry to check for gaps
mcnp6 i=input.i ip

# Add LOST card to input to control lost particle limit
# Add PTRAC card to input for detailed particle tracking

The plotting mode (ip) lets you visualize your geometry to identify gaps or overlaps. Add a LOST card to your input deck to control how many particles can be lost before termination. The PTRAC data card enables detailed particle tracking output.

Performance Issues

Slow simulations often result from inefficient variance reduction, poor geometry organization, or inappropriate physics settings. MCNP provides tools to diagnose and optimize performance bottlenecks.

bash
# Profile particle tracking time
# Add DBCN card to input deck for debug output

# Weight windows and importance sampling are
# controlled via data cards (WWP, WWE, IMP) in
# the input deck, not command-line options.

MCNP reports memory usage in the output file header. Debug output shows time spent in different parts of the calculation, identifying bottlenecks. Weight window parameters (WWP data card) can dramatically improve efficiency for deep penetration problems.

Best Practices for Production Runs

Always test your input with a small number of particles first to verify geometry and physics settings. Use appropriate checkpoint intervals based on your system's reliability and job time limits. Monitor memory usage and adjust task counts to avoid swapping.

Keep detailed records of simulation parameters, especially for parametric studies. Document any unusual results or convergence issues. Use version control for input files and maintain consistent naming conventions for output files.