next up previous
Next: Code for Metropolis Up: Computer Simulation Previous: Metropolis Algorithm for

Programming the Metropolis Algorithm

Update a single site at a time. Choose sites at random to ensure no bias (in most cases, this is not really necessary, and a simple contiguous loop over lattice sites is sufficient).

A loop over all sites is referred to as one Metropolis sweep (or iteration).

The probabilistic part of the algorithm is done using a random number generator (hence the name -- Monte Carlo -- in reference to games of chance). Generate a random floating point number r in [0,1). A process with probability p is performed if r < p.

The Metropolis algorithm is very simple to program.



Paul Coddington, Northeast Parallel Architectures Center at Syracuse University, paulc@npac.syr.edu