C----------------------------------------------------------------------C
C C
C Metropolis Monte Carlo update of the Ising model C
C in Fortran with message passing (e.g. MPI). C
C C
C As long as size is >=2, don't have to do a red/black checkerboard C
C update, since sites being updated simultaneously on different C
C processors will not be neighbors. C
C C
C----------------------------------------------------------------------C
SUBROUTINE metupdate(iterations)
INCLUDE "common.h"
INTEGER iterations
INTEGER n,i,j
INTEGER old_spin, new_spin
INTEGER spin_sum, old_energy, new_energy, energy_diff
INTEGER spin1,spin2,spin3,spin4
INTEGER shift
REAL random
DO n=1,iterations
DO i=1,size
DO j=1,size
old_spin = spin(i,j)
new_spin = -old_spin
C
C -------- Get neighboring spins.
C shift is a function defined to handle the
C periodic boundary conditions and passing of
C data between processors.
C
spin1 = shift(i-1,j)
spin2 = shift(i+1,j)
spin3 = shift(i,j-1)
spin4 = shift(i,j+1)
C
C -------- Sum neighboring spins to get energy.
C
spin_sum = spin1 + spin2 + spin3 + spin4
old_energy = old_spin * spin_sum
new_energy = - old_energy
energy_diff = new_energy - old_energy
C
C -------- Metropolis accept/reject step.
C
IF ( ( energy_diff.LE.0 ) .OR.
& ( EXP(-beta*energy_diff).GT.random() ) ) THEN
spin(i,j) = new_spin
ENDIF
ENDDO
ENDDO
ENDDO
RETURN
END