next up previous
Next: Measurements Up: Computer Simulation Previous: Programming the Metropolis

Code for Metropolis Algorithm (in C)

/* Metropolis Monte Carlo update of 2-d Ising ferromagnet */ #include extern int size; void metropolis(sweeps) int sweeps; { int imet,i,j,ipos,jpos,ineg,jneg; int old_spin,new_spin,spin_sum; int old_energy,new_energy; double energy_diff; double ranf(); /* random number generator */ /* Loop over sweeps */ for (imet=0;imet ranf() ) ) { /* Accept the change */ spin[i][j] = new_spin; } }} /* end of loop over sites */ } /* end of loop over sweeps */ }



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