[gambit-list] optimizing computer simulations of the Ising model

Marijn Schouten (hkBst) hkBst at gentoo.org
Wed Feb 25 12:13:53 EST 2009


Hi Gambitters,

I want to use Scheme to implement a computer simulation of the Ising model of
spins. Background: http://en.wikipedia.org/wiki/Ising_model

Basically all the algorithm does is allocate a vector of spins and flip them
randomly in such a way that a representative sampling at a specified temperature
is produced.

Efficiency of the algorithm is very important as it would allow me to study
larger samples.

Currently on my own system after compilation: with a sample size of 40x40 I can
do 1000 flips/site in a little over 3 seconds. Currently the simulation starts
from an all up state and displays some variables and the end configuration of
the sample. It looks like this:

$ time gsi ising -e "(main 1000)"
D: 2, N: 1600, L: 40, BETA*J: .3, RANDOM-STATE:
10624525222961816100342112271285465503733219408383542344109
E: 72, M: -40
+-++++---++---+-+-+-++++--+----+++-+-+--
+++-+---+-+------++---+-+--+--+++++++---
----+-+--+--+-+--+-+-+++-++---------++-+
---+---+--++-++++-++++-+--+++-++---+--+-
++++--++-+----++++----+-++---+----+-+++-
-----+++--+---+-+++++-++++-+---+++-+++-+
++-+--+-+---+--+++++-+-+---+++++-++---+-
-+---+--++--++--+---++++--+-----+-+-+--+
----+-+--+---++--+-++-+--+----+++---++--
--++-++---+-++++--+++-++++----+-+++++---
++-+-+-+-+-+++-+-++++++-+---+---++-+-+--
+--+---++-++++----+-++-+-+-++-++-------+
+--------+++-+-+++---+-+--+-+---++--+-++
+---++-+-+++++++--+-++--+-+++-++++---++-
+--+----+++--+--+-+---+++-+-+---+--+++++
++-+++-+++--+++--+-++++--++-+---+-+-++++
+-+---+++--+-+--+++-+--+---+-++++++-+++-
++---++---+-+--++-+++----+-+++--+++-+---
++-++-+--+---+++-----+-+----+--+-+-+-+-+
++--++--+--+-+++--++++--+++++--++-+--+-+
-+---++--+-++--++-+--++-+-++--+-++++-+-+
+----+-+--+++--+---+--+-+++--++--++-+++-
++++--+-++--++++----+-++-+--------+-++++
+-----+++++++-+-+--++-++-+--+++--++-++++
+--++-+-++-------+-+++-----++-+-++-+-++-
+--+++--+-+++--+---+---+-----++-+-++-+++
--+-+-+---+-+++----+-+--------+----+-+-+
-+--+--+-+++-+-----+-+----++++-++-++-++-
-+-++-+-+--+--+----+++--+-+-+-++--+++-+-
+-+++-+-++-+-+++++-+----+-+-+--+-++----+
+------+-+---+-++-+-++++-++-++-++---++-+
++----++-+-+--+-+-+++-+-+---+++-----++-+
++++-++++-++-+-+++--++++-++-+--+++++-++-
++-----+++++--++--+-+-+-++-+-+++------+-
++++-+++---+---+-+-++-+---+-+----++++--+
+---++--++---++-+----------+-----+---++-
---++-++--+--++--+--++-+----+--+-++----+
++--++--+--++++-+---++-++------++-++----
-++-++-++-++---+----+-++---++++++--++-++
+-----+++++--++-+-+---+-++---+-++--++-+-


real    0m3.507s
user    0m3.198s
sys     0m0.007s

to compile the program I use:

  gsc -cc-options "-O2 -march=native" ising


I do not know enough about Gambit to know what's fast and what's not and I have
no experience with profiling, so I would appreciate some pointers on how to go
about optimizing the program.

As a side note I was also hoping to compare the performance of various Schemes
for this workload, but it seems the ones I tried so far (bigloo and guile) do
not support srfi-27 (Sources of Random Bits) much. (It worked in guile until
just now when I added a few bits to be able to change the pseudorandom number
generator seed.) If anyone knows other implementations where it would run that
would be cool.

Finally, the source is attached. Any comments appreciated.

Thanks in advance,

Marijn

-- 
Sarcasm puts the iron in irony, cynicism the steel.

Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ising.scm
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20090225/129f6522/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20090225/129f6522/attachment.sig>


More information about the Gambit-list mailing list