Documente Academic
Documente Profesional
Documente Cultură
Lecture Notes
Nicola Offeddu
Marcel Thielmann
Madis Ollikainen
Summer Semester 2014
Preface
This is the first part of a provvisory draft of the script. The rest of the script will follow
during the semester. Since the course covered a rather broad spectrum of topics, time
ofted did not allow to treat them deeply. This is also why, as you will notice while
reading, special attention has been paid in giving some references along the text. If
during your (fruitful) learning, you should notice any mistake, typoes, or in the case
you would like some extra information, explanation, reference or whatsoever about the
methods, the scientists or the sources, please notify us (nico.offeddu@gmail.com). We
would be really happy to receive feedback and to integrate/modify/expand the script.
You can be sure that your fellow (and onfollowing generations of) students will be more
than grateful for that.
iii
Table of contents
Preface
1 Monte Carlo Methods
1.1 Classical Statistical Physics . . . . . . . . . . . . . . . . . .
1.1.1 Phase Space . . . . . . . . . . . . . . . . . . . . . . .
1.1.2 Ensembles . . . . . . . . . . . . . . . . . . . . . . . .
1.1.3 The Ising Model . . . . . . . . . . . . . . . . . . . .
1.2 Monte Carlo Algorithms . . . . . . . . . . . . . . . . . . . .
1.2.1 Markov Chains in Monte Carlo: M(RT)2 , Glauber,
and Creutz algorithms . . . . . . . . . . . . . . . . .
1.2.2 Boundary conditions: . . . . . . . . . . . . . . . . . .
1.2.3 Sampling Uncorrelated Configurations . . . . . . . .
1.3 Finite Size Methods . . . . . . . . . . . . . . . . . . . . . . .
1.3.1 Binder Cumulant . . . . . . . . . . . . . . . . . . . .
1.3.2 First Order Transition . . . . . . . . . . . . . . . . .
1.4 Cluster algorithms . . . . . . . . . . . . . . . . . . . . . . .
1.4.1 Potts Model . . . . . . . . . . . . . . . . . . . . . . .
1.4.2 O(n) Model . . . . . . . . . . . . . . . . . . . . . . .
1.4.3 Implementation of Cluster Algorithms . . . . . . . .
1.5 Histogram Methods . . . . . . . . . . . . . . . . . . . . . . .
1.5.1 Broad Histogram Method . . . . . . . . . . . . . . .
1.5.2 Flat Histogram Method . . . . . . . . . . . . . . . .
1.5.3 Umbrella sampling . . . . . . . . . . . . . . . . . . .
1.6 Renormalization Group . . . . . . . . . . . . . . . . . . . . .
1.6.1 Real Space Renormalization . . . . . . . . . . . . . .
1.6.2 Generalization . . . . . . . . . . . . . . . . . . . . . .
1.6.3 Monte Carlo Renormalization Group . . . . . . . . .
iii
1
1
1
2
3
9
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Kawasaki
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
9
14
15
18
18
20
23
23
26
28
30
30
32
33
34
34
38
39
2 Parallelization
2.1 Multi Spin Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
43
45
3 Bibliography
49
A Codes
51
vi
Table of contents
A.1
A.2
A.3
A.4
vi
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
51
52
54
55
(1.1)
constant:
t = 0. Mind that this does not mean that the system is not allowed to
jump from one configuration to another. As in usual statistical physics, the thermal
average of a quantity Q over its distribution is defined as
hQi =
1X
Q (X) (X),
X
(1.2)
where is the volume of the phase space such that 1 X (X) = 1. With this
definition, systems can be described by means of some averaged quantities, such as
temperature, energy and pressure.
P
1.1.2 Ensembles
The point of an experiment is to read out some observable quantities out of a system,
while controlling others. Generally it is not possible to set all the desired thermal
quantities to a given value. As an intuitive example, think of a classical gas the
dynamics of which is given by perfect elastic collisions. It is impossible to compress
the volume and keep the pressure and the temperature unchanged. It is clear that
depending on which quantities are being held constant, and which others are let free,
the system will behave differently. There are quantities which are called conjugate to
another, like the volume V and the pressure p. One can fix either V or p, not both.
Other examples are energy and temperature (E, T ), particle number and chemical
~ , H).
~
potential (N, ), magnetization and magnetic field (M
Depending on which of
these values are held constant, the system is called
Microcanonical ensemble: fix E,V, N
Canonical ensemble: fix T,V, N
Canonical pressure ensemble: fix T,p, N
Grandcanonical ensemble: fix T,V,
Microcanonical Ensemble:
In the microcanonical ensemble, the number of particles, the volume and the energy of
the system are fixed. This means that any configuration X that the system can assume
has the same energy E (X) = constant. Without proof, the probability of the system
to be in any configuration is also constant:
peq (X) =
1
(H (X) E)
Zmc
X
X
(1.3)
Canonical Ensemble:
In an experiment, microcanonical ensembles must be created by completely isolating
the system from the outer world, not allowing it to exchange its energy with the outside.
This is rarely the case in an experiment since it is difficult to realize in practice. Much
more common is the situation in which the temperature T is fixed (for example, if the
experiment is done at room temperature). This is the case for the canonical ensemble.
One can derive that the probability for a system to be in a certain configuration X
(with energy E (X)) is given by the Boltzmann factor:
1
E (X)
peq (X) =
,
exp
ZT
kB T
"
(1.4)
hQi =
E(X)
1 X
Q (X) e kB T .
ZT X
For the grandcanonical ensemble we will need some extra information to describe
open systems by the means of a coupling to an external heat bath.
The simplest approach to the Ising model is imagining a squared lattice and assuming
that every variable i {1, 1} on the lattice only affects the nearest neighbors (see
Fig. 1.1). This restriction can be relaxed by letting the sites interact with the next
nearest neighbors or even farther sites. If we think of the variables as spins, their
interaction is given by the Hamiltonian
H (X) = J
N
X
i j H
i,j:nn
{z
A
i .
(1.5)
i=1
}|
{z
B
where A is the interaction between all the nearest neighbors (nn), and B the interaction
of each site with an external magnetic field H. Note that if two spins are parallel, then
the energy is lowered (J) and if they are anti-parallel the energy is increased (+J).
The first term in Eq. (1.5) tries to create order in the system (in the sense of the spins
being aligned in the same direction) by reducing the energy when neighboring variables
are in the same state. The second term tends to align the spins in the direction of the
external field H. While the energy is lower in an ordered state, the heat tends to destroy
the order by flipping single spins. Beyond a critical temperature Tc (i.e., for T > Tc ),
the system is dominated by randomness and there is no alignment of the spins anymore.
This transition, like any other phase transition (e.g. sol-gel transition) between ordered
and disordered states, can be characterized by an order parameter. In the case of the
Ising model, the order parameter is given by the spontaneous magnetization (see Fig.
1.2).
The order parameter in the Ising model
The magnetization is defined as
*
M (T ) =
N
1 X
i ,
N i=1
(1.6)
that is, the thermal average of the mean value of the spins. This alone would not be a
good measure since taking the thermal average of a quantity means taking the mean
value over all the possible states. The problem with this procedure is that for any given
state there will always exist an opposite state in which all the spins are flipped. In the
average these two configurations cancel each other out. Thus, on average, every state
will always cancel out with its opposite companion and the averaged magnetization
will always be zero. A better quantity is the spontaneous magnetization:
*
MS (T ) lim
~
H0
N
1 X
i
N i=1
(1.7)
~ that aligns
Here the symmetry of the Ising model is broken by applying a small field H
the spins in one direction. Now it will not be the same if the spins are up or down, and
the thermal average of the spontaneous magnetization wont be zero anymore. Another
way of breaking the symmetry would be fixing the boundaries of the lattice in a certain
state. This is not practical if periodic boundaries are being used.
In the proximity of the critical temperature, the spontaneous magnetization decays
like a power law:
MS (T Tc ) ,
(1.8)
where is known analytically in 2D (1/8), and numerically in 3D ( 0.326) (See Fig.
1.2).
Response functions:
Response functions are second derivatives of the free energy2 Ef = 1 ln (Z):
M
(T )
|T Tc |
H T,H=0
(1.9)
E
CV (T )
|T Tc |
T H=0
(1.10)
The divergence of these functions at the critical temperature can be used to determine
the critical temperature itself. We will encounter these functions again later in the
context of the nth order transition (see Sec. 1.3.2).
The following established nomenclature is unfortunate: with , the thermodynamical quantity kB1T
is meant, not the exponent presented in the power law (1.8). See classical statistical physics
textbooks for more information.
exp
H
+
H
i
i
0
hM (T, H)i
X
i=1
i=1
=
(T ) =
N
H
H
X
X
H=0
exp H0 + H
i
i=1
X
|
{z
}
=Z (H)
T
with =
(T ) =
1
kB T
and H0 = J
i,j:nn i j .
2
h
N
exp H0
i=1 i
P
+ H
i=1 i
ZT (H)
{z
|
D
=
=
}
2
M (T )
hD
H=0
P
i=1 i exp
PN
H0 + H
(ZT (H))2
|
{z
hM (T )i
M (T )2 hM (T )i2 0
i2
i=1 i
}
PN
(1.11)
hD
E (T )2 hE (T )i2
(1.12)
You may have already noticed that these expressions are suspiciously similar to the
classical definition of the variance. These two last formulae are both very important in
Monte Carlo simulations, as we will learn further on. See Fig. 1.3, 1.4, and 1.1.3. In
the vicinity of Tc (see Fig. 1.3), the magnetic susceptibility decays like a power law:
(T ) |T Tc |
with =7/4 in 2D and 1.24 ind 3D. Near Tc (see Fig. 1.4), the specific heat can
also be described by a power law:
C (T ) |T Tc |
where the decay is logarithmic in 2D (= 0) and numerically known in 3D ( 0.11).
H=0
Correlation length3
The correlation function describes to
which extent two sites (or extended regions) are related. It is defined by the
thermal average of the product of the values of sites at different positions:
C(R) h (0) (R)i .
(1.13)
C(R) M 2 + ae
See Fig. 1.1.3 and the lecture notes Computational Physics of the previous course.
For more information about these the exponents, see Stanley (1999) and Stanley (1971)
(1.14)
10
T (X Y ) = 1
3. Reversibility: T (X Y ) = T (Y X)
Once a configuration is proposed, one can accept the new configuration with probability
A(X Y ) or reject it with probability 1 A(X Y ). The transition probability is
then given by
W (X Y ) = T (X Y ) A(X Y ).
(1.15)
With the transition probability one can investigate the probability of finding the state
in a certain configuration (during the stochastic process, not in real time!) p (X, ).
The master equation describes how the distribution evolves in time.
X
dp (X, ) X
p(X)W (X Y )
p(Y )W (Y X)
=
d
Y
Y
(1.16)
For Markov chains, it is known that the system always reaches a stationary state (called
pst ) defined by the derivative in Eq. (1.16) being zero. The transition probability must
fulfill
1. Ergodicity: any configuration must be reachable: X, Y : W (X Y ) 0
2. Normalization:
3. Homogeneity:
W (X Y ) = 1
Note that the condition of reversibility is not required anymore. This is one of the
effects of introducing A (X Y ). Just think of a two level system, in which one of the
two energy levels is higher (e.g. the electronic shells in an atom): At low energies it
would be nonsense to equally sample the excited and the ground state of the electrons.
On the contrary, at very high energies the sampling will have to reflect the higher
probability of being in an excited state, rather then in the ground state. In order for
the Markov chain algorithm to choose effectively which areas of the phase space to
explore, somehow W has to depend on the system. Imposing the distribution of the
stationary states pst as the equilibrium distribution of the physical system pst (a real
and measurable distribution) is called detailed balance:
dp (X, )
!
= 0 pst = peq
d
10
(1.17)
11
peq (Y )W (Y X) =
peq (X)W (X Y ).
(1.18)
M(RT)2 algorithm:
If equation (1.18) is fulfilled, we automatically found the way to fulfill detailed balance
by the chosen W and peq . The algorithm (also called Metropolis algorithm5 ) uses the
acceptance probability
peq (Y )
A (X Y ) = min 1,
.
peq (X)
"
"
##
1
ZT
(1.19)
h
exp E(X)
the acceptance
kB T
E
= min 1, exp
kB T
"
"
##
(1.20)
which means that if the energy decreases, theh step isi always accepted, and if the energy
increases it is accepted with probability exp kE
. Plugging Eq. (1.19) with peq into
BT
Eq. (1.18) shows that detailed balance is fulfilled. For a more detailed discussion about
the Metropolis and alternatives algorithms (e.g. Glauber dynamics), see Herrmann
(2012). The algorithm has been then generalized in 1970 (Hastings, 1969). We can use
this rather general algorithm to explore the phase space of the Ising model, by flipping
the values on the lattice following the acceptance probability. Summarized, the steps
in the Metropolis algorithm would then be:
5
The rather curious name of this algorithm finds its reason in the names of the authors of the paper
in which it was proposed: Metropolis et al. (1953). RT is squared because besides Metropolis,
the other four authors of the paper formed two married couples and therefore carried the same
family names. The real contributions of some of the authors (in particular of Metropolis and of
A.H. Teller) is subject of controversy (Barth, 2003; Gubernatis, 2005). It has been even stated by
Roy Glauber and Emilio Segr that the original algorithm was invented by Enrico Fermi, which
described it to Metropolis while they were working together at Los Alamos and later reinvented
by Stan Ulam (Segr, 1970).
11
12
exp kE
BT
A (X Y )
1 + exp kE
BT
(1.21)
One can see that the expression in Eq. (1.21) fulfills Eq. (1.18):
1=1
h
1 + exp kE
BT
E
E
i = exp
h
exp +
E
kB T
kB T
1 + exp
"
"
kB T
1 + exp
+ kE
BT
i
exp kE
BT
1 + exp kE
BT
E
1 + exp +
kB T
"
#!
exp kE
BT
h
exp
T (XY ) symmetric
const. temperature
exp kE
BT
EX EY
E
exp +
= exp
kB T
kB T
i =
exp
"
1 + exp kE
BT
h
"
EX
E
kB T
h
i exp +
kB T
exp kEBYT
h
exp + kE
BT
EY
EX
h
i = exp
h
i
E
kB T 1 + exp
kB T 1 + exp + E
kB T
kB T
Mind that knowledge about the whole system configuration before the spin flip is not
needed here: only the local configuration around the site is relevant. With J = 1, the
probability to flip the spin i is:
Ai =
12
exp
1+
2i hi
k T
hB
i
i hi
exp 2
kB T
13
with hi being the local field as usual hi = j=nn j . Using the abbreviation pi
exp[2hi ]
1+exp[2hi ] , one can express the probability to flip the spin as being
P
pflip =
1 pi
for i = 1
for i = +1
and
pno flip =
1 p
pi
for i = 1
for i = +1
(1.22)
+1
with propability pi
1 with propability 1 pi
with
pi
exp [2hi ]
1 + exp [2hi ]
This method which does not depend on the spin at time t, is called heat bath MC.
Binary mixtures (Kawasaki dynamics):
In this method, the sum of the spins pointing up and the sum of the spins pointing
down (i.e., the magnetization) is held constant. Kawasaki dynamics can be used for
simulating binary mixtures of gases and other systems were the population numbers
are conserved. In the case of a two species mixture, the energy is larger for A-B bonds,
with A and B being the two species in the binary mixture (spin up and spin down
particles, two different gas molecules, etc.). What one can do is to switch two particles
with a certain probability and then add the configuration to the averaging loop.
Creutz algorithm:
Let us consider a situation in which energy is constant. The algorithm generally used in
this case is the Creutz algorithm. In this technique the condition of energy conservation
is relaxed a bit and energy is not exactly conserved anymore. The movement in phase
space is therefore not strictly constrained to a subspace of constant energy, but we have
a certain additional volume in which we can freely move. The condition is softened by
introducing a demon, which is a small reservoir of energy Ed that can store a certain
maximum energy Em :
Choose a site
Calculate E for the spin flip
Accept the change if Em Ed E 0
13
14
This method is completely deterministic (besides the fact that one can randomly choose
the sites to update) and therefore reversible. The drawback is that the temperature
of the system is not known, but it can be estimated with the Boltzmann distribution.
h
i
Taking a histogram of the energies Ed one observes a distribution P (Ed ) exp kEBdT .
The fit is not optimal, since one has very few values of Ed . The bigger Em , the faster
is the method, since the condition of constant energy is relaxed and the exploration of
phase space is less restricted to certain regions.
Q2R:
In the case of Em 0, the Creutz algorithm becomes a totalistic cellular automaton
called Q2R. The update rules on a square lattice are then given by
i,j ( + 1) = f (xij ) i,j ( )
with
xi,j = i1,j + i+1,j + i,j1 + i,j+1
and
f (x) =
1
0
if x = 2
if x =
6 2
In this case, the spins are flipped if and only if the change in energy is zero. This can
be implemented in a very efficient way using multi spin coding. The changer word
defined by f (x) can be expressed in a very elegant way using logical functions:
( + 1) = ( ) {[(1 2 ) (3 4 )] [(1 3 ) (2 4 )]}
This logical expression can be computed in roughly 12 cycles (8 logical operation and
4 fetches) which last typically around 10ns. At this computational speed and using
multi spin coding (see Sec. 2.1) one can roughly update 4 sites per nanosecond. The
method is extremely fast, deterministic and reversible. The problem is that it is not
ergodic, and that it strongly depends on the initial configuration. As an example, try
to imagine the development of a small lattice, in which only 2,1 and 1,2 are equal
to +1. In fact, this method is not used in statistical physics but it is useful for other
purposes e.g., neuroinformatics or cellular automata.
14
15
If our system is big enough7 one identies the two sides of the lattice as being neighbors. (i,L+1 i,1 , and L+1,j 1,j ). Identifying the last element of a row (or column) with the first element of the next row (or column) leads to so called helical boundary condition. i,L+1 i+1,1 , therefore one can use only one index k = i + j(L 1)
instead of keeping track of two.
eq.
p (X, ) A (X ( )) =
p (X, 0 ) A (X( ))
(1.23)
hA( )i hA()i
hA(0 )i hA()i
(1.24)
The non-linear correlation time Anl describes the relaxation towards equilibrium:
Anl
7
Z
0
nl
A ( ) d
(1.25)
Big here is not purely arbitrary but it depends on what we want to simulate. A good measure of
big can be that the edges of the system are uncorrelated. It is clear that this method is useless in
small lattices.
15
16
Anl |T Tc |zA
(1.26)
nl
with zA
being the non-linear dynamical critical exponent. This means that at Tc , the
time needed to reach equilibrium diverges!
The linear correlation function of two values A, B
AB ( ) =
with
hA (0 ) B ( )i =
(1.27)
p (X, 0 ) A (X (0 )) B (X ( ))
is now a proper correlation function. Note that it goes from 1 to 0 when goes to
infinity. If A = B, we call Eq. (1.27) the autocorrelation function. For the spin-spin
correlation in the Ising model we get:
( ) =
Z
0
AB ( ) d
(1.28)
Figure 1.8: Spin-spin autocorrelation function over MC time in the Ising model.
16
17
(1.29)
nl
zE
=1
(1.30)
(1.31)
(1.32)
Decorrelated configurations:
The behavior we studied until now is only
valid in the case of an infinite lattice. In
a finite system there is no divergence by
definition (See Herrmann (2012)). The
correlation length diverges at the critical
temperature Tc :
L = (T ) |T Tc |
AB |T Tc |zAB L
(1.33)
zAB
This is a problem when sampling big systems since the computation becomes very
expensive. To be sure not to sample correlated configurations one should
reach equilibrium first (discard n0 = c nl (T ) configurations).
Sample every nth
e = c (T ) configurations.
17
18
z nl
and ne = cL
where c 3 is a "safety factor" to make be sure to discard enough samples. A trick for
reducing this effect is using cluster algorithms, which we will encounter later on.
18
19
M4
L
2
3 hM i2L
=
L FM 4 (T Tc ) L
2
i
h
i2 = FC (T Tc ) L
1
L FM 2 (T Tc ) L
19
20
If T = TC , then the scaling function FC , which is just the ratio of two other scaling
functions, is a constant which is independent of the lattice size. For T > TC , the
magnetization follows a Gaussian distribution according to
s
PL (M ) =
Ld
M 2 Ld
exp
,
L
L
"
with L
= kB T 2L . Since the
fourth moment equals three times the second moment
D
E
D
E2
4
2
squared M = 3 M
it follows that UL must be zero. Below the critical temL
perature (T < Tc ) there are two ground states in the ordered phase (one with positive
and one with negative magnetization).
1
PL (M ) =
2
Ld
(M MS )2 Ld
(M + MS )2 Ld
exp
+ exp
l
L
L
(
"
"
#)
(1.36)
E2
for T < Tc
3
UL = const. for T = Tc
(1.37)
0
for T > Tc
This is the most efficient way to calculate the critical temperature, since the Binder
cumulant UL is a quantity which is very sensitive to the temperature. For infinite
systems it shows a jump at Tc .
Figure 1.11: Binder cumulant for 2D finite systems in the Ising model.
20
21
Figure 1.12: 4D finite systems for the Ising model. Note that the lines do not cross all at
the same point.
1
M (T, L) = L FM (T Tc ) L + Lx FM
(T Tc ) L + ...
with x = max
, 1 ,
1 .
21
22
the first derivative of the free energy. This leads to the susceptibility assuming a delta
peak at H = 0. This kind of phase transition is more common in nature than second
order transitions.
(b) Susceptibility
Binder derived that if the distribution of the magnetization is described by two Gaussians, the magnetization (in dependence on the field H) has the form of a tanh(Ld ).
22
23
d
M (H) = D
L H + ML tanh HML L
L (H) =
M
ML Ld
= D
+
.
L
H
cosh2 (HML Ld )
(1.38)
(1.39)
Similarly to the scaling for the second order transition, we can scale the maximum of
the susceptibility (L (H = 0) Ld ) and the width of the peak (L Ld ).
Figure 1.15: Susceptibility for different system sizes in the Ising model.
Figure 1.16: Data Collapse for scaled susceptibility for different system sizes in the
Ising model.
23
24
X
i,j=nn
i ,j H1
i ,1
(1.40)
with i {1, ..., q}, and q being an integer 2. In this case, the state 1 is favored, by
lowering the energy whenever a site is in this particular state. The sites of the lattice
we are dealing with can assume more than just two states (up/down, as we had in the
Ising model). The interesting fact now is that there is a strong connection between the
Potts model and the well known bond percolation model. After Kasteleyn and Fortuin
(1969), which we will discuss now, the two models have related partition functions.
24
Cluster algorithms
25
Figure 1.17: Specific heat for two dimensional Potts model with q=10. On the right the
scaling for different sizes.
Any system is characterized by its partition function. From the latter one can derive
all other thermodynamic quantities. Therefore the complete knowledge of the partition
function corresponds to the complete knowledge of the system. If two systems have
exactly the same partition function, those two systems are therefore equivalent. In the
following, we will prove a relation between the bond percolation and the Potts model.
The Kasteleyn and Fortuin theorem:
Consider the Potts model not on a square lattice, but on an arbitrary graph of nodes
connected with bonds. On the nodes we have q possible states, and for every connection
we have an energy cost of 1 if two connected nodes are in a different state and of 0 if
they are in the same state.
E=J
with =
0
1
(1.41)
We also introduce two operations on the bonds: the contraction C and deletion D
(see Fig. 1.18). Bonds can thus be either removed by merging two sites (which implies
that they have the same state) or be simply removed.
25
26
The partition function is the sum over all the possible configurations weighted by
the Boltzmann factor:
Z=
(1.41)
eE(X) =
eJ
XY
X
(1.42)
eJ
We will now consider a particular bond 1 and rewrite the partition function as
X
X
eJ1
Y
6=1
eJ =
eJ + eJ
= ZC + e
eJ
X,i =j 6=1
J
(ZD ZC )
= 1 eJ ZC + eJ ZD
= pZC + (1 p) ZD
Here i and j are the states at the two ends of the bonds, ZC and ZD are the partition
functions of the graphs contracted and deleted at 1 respectively and p 1 eJ .
We have now divided the partition function in a sum of two other partition functions,
namely the partition function of the same system with a deleted bond and the partition
function of the same system with a contracted bond. We can repeat this operation on
another bond 2 , and we find that
Z = p2 ZC1 ,C2 + p(1 p)ZC1 ,D2 + (1 p)2 ZD1 ,D2 .
26
27
Cluster algorithms
We repeat this operation on every bond. At the end the graph is reduced to a set of
separated points corresponding to connected/contracted bonds: the clusters of sites
which are connected and in the same state. The partition function is then reduced to:
Z=
configuration of
E
bond percolation configurations
bond percolation
(1.43)
where c and d are the numbers of contracted and deleted bonds respectively. We have
now an equivalence between a purely geometrical model (percolation) and a thermal
(or magnetic) model with a Hamiltonian (Potts model). Interestingly, one could now
choose values for q which are not integers. This made no sense in the beginning since
q was introduced as the state of each site.
Coniglio-Klein clusters:
Mind that the equivalence between the bond percolation model and the magnetic model
is of statistical nature, since a particular bond configuration can have several spin configurations and a particular spin configuration can have several bond configurations.
The fact that the value of the spins is absent in Eq. (1.43) forms the base for cluster algorithms. The probability of a given cluster C to be in a certain state 0 is independent
of the state itself:
p(C, 0 ) = pcC (1 p)dC
q # of clusters pc (1 p)d
(1.44)
bond percolation
without cluster C
This means that flipping this particular cluster wont affect the partition function
(and therefore the energy) so that it is possible to accept the flip with probability one.
This can be seen by looking at the detailed balance for this system:
p(C, 1 )W [(C, 1 ) (C, 2 )] = p(C, 2 )W [(C, 2 ) (C, 1 )]
(1.45)
27
28
This is a very important model for describing phenomena related to magnetism (e.g.,
ferromagnetism). The variables on the sites are n-dimensional vectors. The Hamiltonian resembles the one of the Potts model in the sense that it favors alignment of the
variables:
H=J
X
i,j:nn
~i S
~j + H1
S
~ 1 with S
~i = S 1 , S 2 , ..., S n
S
i
i
i
i
~
and S
i = 1
(1.46)
For n = 1 we retrieve the Ising model, for n = 2 we have the XY-model, for n = 3 the
Heisenberg model and finally, for n = we have the spherical model.
Note that the models for various values of n are not equivalent. In fact, there are huge
differences. As an example, the XY-model does not exhibit any phase transition from
an ordered to a disordered state. The proof of this statement can be found in Mermin
and Wagner (1966), and it is known as the Mermin-Wagner theorem. Ernst Ising
himself proved in his PhD thesis that the one dimensional case also does not exhibit
any phase transition. In three dimensions, however, there are phase transitions and the
behavior regarding magnetization, susceptibility and specific heat is very similar to the
behavior of the Ising model we studied earlier (critical temperature, critical exponents
etc.).
For Monte Carlo simulations with continuous degrees of freedom we have to adapt
our techniques because phase space is not a discrete set of configurations anymore. The
classical strategy is to make spin flips by modifying the spin locally by a fixed amount
~0 = S
~i + S.
~ The classical Metropolis algorithm can then be used in
(a rotation): S
i
the same fashion as in the discrete models. In order to use cluster methods one can
project a group of spins onto a plane, and then reflect the spins with respect to the
plane.
In order to obtain clusters one has to find a method to identify equal spins. The
probability to find equal spins in a continuous model vanishes and one can therefore
considers a certain range of values instead(if two spins are equal within a certain error,
then they belong to the same cluster).
28
Cluster algorithms
29
29
30
p 1 eJ . Once the clusters are determined, they can be flipped using any of the
dynamics mentioned above. The basic procedure is as follows:
Occupy the bonds with probability p 1 eJ if sites are in the same state.
Identify the clusters with the Hoshen-Kopelman algorithm.
Flip the clusters with probability 0.5 for Ising or choose always a new state for
q > 2.
Repeat the procedure.
Wolff algorithm:
In this variant only one cluster is flipped per step using the Leath algorithm:
Choose a site randomly.
If neighboring sites are in the same state, add them to the cluster with probability
p 1 eJ .
Repeat this for any site on the boundaries of the cluster, until all the bonds of
the cluster have been checked exactly once.
Choose any new state for the cluster.
Repeat the procedure.
30
31
Histogram Methods
X
1 X
Q (E) pT (E) with ZT =
pT (E)
ZT E
E
(1.47)
where pT (E) g (E) e kB T with g (E) being the density of states (i.e. the number of
states with energy E). This takes into account the fact that more configurations can
have the same energy. The goal is to compute the quantity Q at another temperature
P
T : Q (T ) = Z1 E Q (E) pT (E). The density of states contains all the information
T
needed. Using the definition of g (E) yields
p
(E) = g (E) e
BT
=
|{z}
def. of g (E)
E
kB T
E
E
pT (E) exp
+
kB T
kB T
(1.48)
We have now obtained an expression for the quantity Q at the temperature T without
having to measure any distribution at temperature T, since fT,T are known scalars.
The drawback of this method is that the values of Q (E) are sampled around the
maximum of pT (E), which converges to a delta distribution for large systems. This
means that if T and T are not very close, the statistics are very poor, and results will
be inaccurate or even wrong. One possible solution consists of interpolating data from
several temperatures (multi-canonical method) but this involves calculations for many
temperatures, which is also not efficient for large systems. Another solution to this
problem has been presented in de Oliveira et al. (1996) and will be also treated in this
chapter.
31
32
configurations increases with higher energy. A plain random walk through phase space
would also have the problem that it would explore only the regions with high energies.
To explore all the regions equally (with respect to the energy) we can create a Markov
chain in which the number of processes that increase the energy by E (we shall call
this number Nup ) and the number of processes that decrease the energy (Ndown ) fulfill
an equivalent condition to detailed balance to reach a homogeneous steady state:
g (E + E) Ndown (E + E) = g (E) Nup (E) .
(1.49)
The motion (in phase space) towards higher energies can then be penalized with
Metropolis-like dynamics:
Choose a new configuration
If the new energy is lower, accept the move
If the new energy is higher then accept with probability
Ndown (E+E)
Nup (E)
However, we havent obtained the function g (E) yet. Therefore we will take the logarithm of Eq. (1.49) and divide by E
log [g (E + E)] log [g (E)] = log [Nup (E)] log [Ndown (E + E)]
Nup (E)
log [g (E)]
1
=
log
E
E
Ndown (E + E)
"
(1.50)
which we can numerically integrate to obtain g (E). Estimates of Nup and Ndown can
be obtained by checking if a change of state at each site would increase or decrease the
energy.
32
Histogram Methods
33
k ET
Q (E) g (E) e
k ET
B
g (E) e
Figure 1.22: The continuous line is the analytic solution of the specific heat for a 32x32
lattice. The crosses represents the result of
the BHMC and the circles are the result for
the usual histogram.
33
34
E(C)
BT
w (C) e
E(C)
BT
C w (C) e
with
hAi =
hA/wiw
.
h1/wiw
(1.51)
Summarizing, some of the most common techniques related to the histogram methods
are
Wang-Landau method
Multiple histogram method
Multicanonical MC
Flat Histogram method
Umbrella sampling
34
Renormalization Group
35
[...]We can construct certain transformations on the Hamiltonian of the system for which the critical
point is a fixed point. Meaning that observables do not change, no matter how many times we apply
these transformations. (Wilson, 1975)
9
Extensive quantities change with the size of the system, like the volume or the total mass of a
gas. Intensive quantities are not dependent on the system size, e.g., the energy density or the
temperature.
8
35
36
renormalize the quantity itself to the system size. With F being the renormalized free
energy,
= ld F (, H) with T Tc .
F , H
(1.52)
We then make use of the scaling law close to the critical point:
F (, H) = ld F (lyT , lyH H)
= ld F (lyT , lyH H)
F , H
= lyH H.
= lyT , H
(1.53)
l
= l = lyT
1
.
Majority rule
An easy example that can be regarded as renormalization of a spin systems is the
majority rule. One considers local groups of spins i , and instead of considering
P
them
all separately taking a mean over that local group of spins:
i = sign
region i (see
Fig. 1.23). Attention must be paid on how the transformation is done. In a one
dimensional lattice with up/down spins for example it would be an error to apply this
transformation on an even number of spins, since the sign is then not well defined for
all the possible situations. The fact that one deals with system of a finite size is also
something that has to be taken into account: one can renormalize up to a certain scale,
before finite size effects are visible.
36
Renormalization Group
37
Figure 1.23: Majority rule for a 2D Ising model. The spins are grouped into larger regions
and averaged. If the majority of the spins is in a certain state, that region is considered as a
single spin in that state.
Figure 1.24: Decimation of spins: every second spin in every direction is ignored.
37
38
To see explicitly what happens with the system, we calculate the partition function
Z. We will split the partition function into two terms: one for the even sites and one
for the odd sites. With K = KJB T and using
A=
X
s2n+1 =1
Z=
s2i =1 2i
X Y
X Y
s2i+1 =1 2i+1
s2i =1 2i
X Y
s2i =1 2i
N
= [z (K)] 2
X Y
eK s2i s2i+2
s2i =1 2i
0
There are only two possible states, and we can compute z (K) eK s2i s2i+2 = 2cosh [K (s2i + s2i+2 )]
explicitly:
K 0 s2i s2i+2
z (K) e
2cosh [2K]
2
(1.54)
38
39
Renormalization Group
Generally, when renormalizing a system, there are two steps that one has to undertake:
Decide which scale to change (e.g., the length of the system, the spins, etc.).
Evaluate the consequences for the system (e.g., for the Hamiltonian, the free
energy, etc.).
1.6.2 Generalization
In the above example it was possible to fulfill the condition of constant free energy with
just one coupling constant. Luckily, the transformation rule for the coupling constant
K was enough to fulfill all the conditions expressed by eq. (1.54). Generally this is not
the case, and more coupling constants (e.g., next nearest neighbors) are needed to close
the system of equations. We therefore have to construct a renormalized Hamiltonian
made up of renormalized coupling constants which generally contain many possible
interactions:
=
H
M
X
with O
=
K O
=1
X Y
i+k
(1.55)
i k
K
transformation. We do this calculating the Jacobian T, = K
:
K =
K
T, |K K K
(1.56)
39
40
To analyze the behavior of the system close to criticality, we will consider the eigenvalues 1 , ..., M and the eigenvectors 1 , ..., M of the linearized transformation 1.56.
From linear algebra we know that = . Clearly, if > 1 we have an unstable
~ increases at every iteration of the transformation).
situation (the distance from K
The biggest eigenvalue will be the dominating one (which is the temperature exponent
in the Ising model). We can identify the scaling field = lyT with the eigenvector of
the transformation, and the scaling factor with eigenvalue T = lyT ,
=
1
ln [l]
=
.
yT
ln [T ]
This means that we can now calculate critical exponents using the scaling behavior of
the system, if the scaling factor l is known.
40
e
OP
K O
K O
F
K
(1.57)
41
Renormalization Group
where F = ln [Z] is the free energy. Using the fluctuation-dissipation theorem one can
also numerically calculate the response functions:
hO i
= hO O i hO i hO i
K
D
E
D
E D
E
O
O O
hO i
= O
,
,
Using the chain rule, one can calculate with equation (1.57) that
O
D
E
D
(n)
O
X K
T, (n+1)
, .
Thus we can obtain T, from the correlation functions by solving a set of M coupled
linear equations. We can iterate this method, in order to get systematically better
values, if we are at the point K = K .
41
42
Figure 1.27: for a 4-state Potts model in 2D. Note the convergence.
Errors in MCRG
There are many error sources in this technique, that originate from the fact that we
are using a combination of several tricks to calculate our results, of which one should
be aware of:
Statistical errors
Truncation of the Hamiltonian to the Mth order.
Finite number of scaling iterations
Finite Size effects
No precise knowledge of K
42
2 Parallelization
In this short Chapter we will briefly discuss the main methods for making computations faster in a very general way. Parallelization can lead to an improvement of the
computation time of up to entire orders of magnitude! The easiest way to parallelize is
by farming: repeating the same calculations on many different computers/processors
with different data. This can be very easy to program in situations like Monte Carlo,
where one has to repeat the exact same sequence of operations as many times as possible. Of course, this is mostly not regarded as smart parallelization. Already with
some very basic knowledge of computer architecture there is the possibility of drastically improving the efficiency of the programs. Two ways to parallelize, which imply
a little deeper understanding of how a computer works, are presented in the chapter
(multi-spin coding and vectorization). The chapter is obviously not exhaustive,
and for the interested reader dedicated lectures are recommended.
{z
(i+20)
{z
(1)
(2.1)
43
44
Chapter 2: Parallelization
And for the values of the spin on the sites we can use another integer N:
Nj = (1 , ..., 0, 0, 3i2 , ..., 0, 0, 1 )
|
{z
(i)
(2.2)
| {z }
(1)
where the value of 3i2 defines the ith spin. This way, only one bit remains unused,
instead of 63 (or 31, depending on the computer architecture). The price that one has
to pay is that we must be carefulabout how we organize the storage of the variables in
the words. This is because neighboring variables should not be stored in the same word.
As mentioned before, besides a purely memory storage question, the main advantage is
a much faster calculation. For this we will make use of bitwise logical functions XOR,
AND and OR (, and ). First, to extract the information about one site out of an
integer, we will define the mask: 7 (0, ..., 0, 1, 1, 1). This can be used to fetch the
value out of the last three digits of an integer Nj , as defined before.
7 Nj = (0, ..., 0, 1, 1, 1) bitwise (1 , ..., 62 , 63 , 64 ) = (0, ...0, 62 , 63 , 64 )
(2.3)
With the circular right shift operator (ror) or the circular left shift operator (lor) one
can act a clockwise (or counter-clockwise) permutation of the bits stored in an integer
variable
ror [(1 , 2 , 3 , 4 , 5 ), 2] = (4 , 5 , 1 , 2 , 3 )
(2.4)
Combining the two operations defined in equations (2.3) and (2.4) allows us to fetch
all the 21 sites or energy values stored in an integer. Similarly for the calculation of
the energy, only one cycle is needed to calculate the energy of 21 sites:
Ej = Nj Nright + Nj Nlef t +, ...+, Nj Ndown
For an example of implementation in C/C++, see A.1.
44
(2.5)
Vectorization
45
2.2 Vectorization
Multiple instruction - single data:
Vectorization means organizing the routines in such a way that many operations can be
done simultaneously. Vectorization only works in the innermost loops. As an example
1
2
3
i_max = 1 0 0 0 0 ;
f o r ( i =1; i<=i_max ; i ++){
A( i ) = B( i ) (C( i ) + D( i ) ) ;
5
6
7
In the loop, one has to do several operations: fetch the values of the vectors A,B,C,D,
multiply them, adding etc. ... The aim is to parallelize all these operations in a pipe.
This is usually already implemented in the compilers, so that the user does not have to
care about it. In more complicated routines this may have to be implemented directly.
The bad features for vectorization of a routine include
Short loops.
Conditional branchings like if-statements.
Indirect addressing.
If the loop is smaller than the assembly line then theres no need to bother programming in a vectorized way (i.e. if im ax in the upper example would be 4 or 5).
Another problem is that the instructions must be repetitive without interruptions or
exceptions like if-statements. There are ways to handle some cases in which a distinction is needed, but this is often a problem. An example would be replacing
1
2
3
i f (P( i )>z ) {
s = s ;
}
by
1
s = s s i g n ( zP( i ) ) ;
In order for vectorization to be maximally exploited, one has to make sure that the
inner loop is the largest. One can, for example, transform a n-dimensional system in
a one dimensional system using helical boundary conditions and appropriate indexing.
Other important elements of an efficient vectorized routine are
45
46
Chapter 2: Parallelization
Make update in inner loop, i.e. no loops inside this loop.
Use a vectorized random number generator.
Split up loops that cannot be vectorized.
SIMD vs MIMD:
There are many types of parallelization, but one can roughly divide them into two
groups according to the flexibility of the process and accessibility of your memory
access: Single Instruction - Multiple Data (SIMD) and Multiple Instruction - Multiple
Data. In the first case one applies the same set of instructions to all the data. In
the second one, different instructions are applied to different data, with the drawback
that the routines loose simplicity. There are shared memory computers which have the
advantage that they are really flexible in the organization of the data structure and
distributed memory computers which are much easier to build and program. Finally,
there is the possibility of combining a great number of processors, each of them with
very basic features or a smaller number of more powerful processors (coarse graining
vs fine graining). For each combination there exist different solutions with different
programming philosophies.
SIMD
MIMD
shared memory distributed memory
coarse grained
fine grained
MC parallelization:
Monte Carlo on regular lattices is well suited for parallelization because of a number
of reasons:
Local processes that do not involve the whole system (nearest neighbors).
Domain composition is possible (sub-lattices).
Use standard domain decomposition and distribute using in MPI.
Use logical mask to extract one sub-lattice.
Use periodic shift (CSHIFT) to get neighbors for periodic boundary conditions.
There are many options for dividing a system into domains. Depending on the
situations it can be more convenient to increase the domains or reducing the interfaces
between the domains in case that the processes need to work independently (e.g., in
the case of distributed memory). It is also possible to dynamically change the size of
46
Vectorization
47
the domains and the position of the interfaces. For an example of parallelization, see
Section A.2.
Figure 2.2: Different interface setups for domain decomposition of a square lattice
47
48
Chapter 2: Parallelization
and implemented by the graphics processing units (graphic cards) that they produce.
Graphic cards are capable of very fast computation of easy operations, and that can
be used in some cases to do scientific computing. Message Passing Instruction (MPI)
is a standardized and portable message-passing system. This means that instructions
can be passed by the user within programs written in languages such as Java or C++.
See Section A.3 for basic examples of MPI coding.
Amdahls law:
The bottleneck of parallelization is the communication between processors. Processors
are not isolated units that completely work on their own, and the more one slices the
system into domains, the more communication between processors is needed. This is
generally not efficient and usually slows down the parallelization.
Figure 2.3: Efficiency of Parallelization. On the right the fraction of parallelized time to
total time.
48
3 Bibliography
K. Barth. Oral History Transcript Dr. Marshall Rosenbluth. 2003. URL http:
//www.aip.org/history/ohilist/28636_1.html.
P.M.C. de Oliveira, T.J.P. Penna, and H.J. Herrmann. Broad histogram method.
Brazilian Journal of Physics, (26):677, 1996.
J.E. Gubernatis.
Marshall rosenbluth and the metropolis algorithm.
AIP,
2005. URL http://scitation.aip.org/content/aip/journal/pop/12/5/10.
1063/1.1887186.
W.K. Hastings. Monte carlo sampling methods using markov chains and their applications. BioMetrika, 1969. URL http://biomet.oxfordjournals.org/content/57/
1/97.
H.J. Herrmann. Introduction to Computational Physics. lecture notes, 2012.
S.K. Ma. Monte carlo renormalization group. Phys. Rev. Lett., 37:461, 1976.
N.D. Mermin and H. Wagner. Absence of ferromagnetism or antiferromagnetism in
one- or two-dimensional isotropic heisenberg models. Phys. Rev. Lett., (17):1133,
1966.
N. Metropolis, A. W. Rosenbluth, M.N. Rosenbluth, A.H. Teller, and E. Teller.
Equation of state calculations by fast computing machines. J. of Chem. Phys.,
1953. URL http://en.wikipedia.org/wiki/Equation_of_State_Calculations_
by_Fast_Computing_Machines.
T. Niemeijer and J.M.J. van Leeuwen. Renormalization: Theory ising-like spin systems. Phase transitions and critical phenomena, 6. URL http://en.wikipedia.
org/wiki/Phase_transitions_and_critical_phenomena.
Z.W. Salzburg, J.D. Jacobson, W. Fickett, and W.W. Wood. Excitation of non-radial
stellar oscillations by gravitational waves: a first model. Chem Phys, (30):65, 1959.
E. Segr. Enrico Fermi, Physicist. University of Chicago Press, 1970. ISBN 0-22674473-6.
H.E. Stanley. Introduction to Phase Transitions and Critical Phenomena. Clarendon,
Oxford, 1971.
49
50
Chapter 3: Bibliography
50
Appendix A
Codes
In this Section, the codes have been taken by various open sources online. The routines
have been heavily shortened and altered for the sake of the explanations, mainly in
Chapter 2. It is obvious that the codes have not been tested and that we do not
guarantee for the compatibility of what are meant to be simple examples for this
scriptum.
#i n c l u d e <s t d i o . h>
2
3
4
5
6
7
8
// go through t h e 21 s i t e s s t o r e d
// i n N with f i e l d v a l u e s E
f o r ( i =1; i <=21; i ++){
z=r a n f ( ) ;
// random number f o r t h e f l i p
i f ( z<P(E&7) ) { // f e t c h t h e v a l u e from t h e l o o k up t a b l e
cw=(cw | 1 ) ; // t h i s v a l u e has t o be f l i p p e d l a t e r
}
10
11
12
13
14
15
16
17
18
19
// c i r c u l a r r i g h t s h i f t
// t o g e t t h e next s i t e
cw=r o r ( cw , 3 ) ;
E=r o r (E , 3 ) ;
20
21
22
cw=r o r ( cw , 1 ) ; // i g n o r e t h e l a s t unused b i t
N=(N^cw ) ;
// f l i p t h e s p i n s i n N
chapters/codes/multi_spin.cpp
51
52
Chapter A: Codes
A.2 Parallelization
1
2
3
4
5
!
!
pi_hpf . hpf compute p i by i n t e g r . f ( x ) = 4 / ( 1 + x 2 ) from 0 t o 1
!
This i s an Adaptor 7 . 0 c o m p a t i b l e HPF program
!
PROGRAM pi_hpf
6
7
8
9
10
11
IMPLICIT NONE
DOUBLE PRECISION
PI25DT , pi , h , sum , x
REAL
t ( 2 ) , t _ s t a r t , t_end
INTEGER
n , i , numprocs
PARAMETER( PI25DT = 3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3D0 )
12
13
14
! HPF$
! HPF$
PROCESSORS, DIMENSION(NUMBER_OF_PROCESSORS( ) ) : : a l l _ p r o c s
PROCESSORS : : one_proc
! ADP$
! ADP$
REPLICATED ONTO a l l _ p r o c s : : n
SINGLE : : t _ s t a r t , t_end , t , PI25DT , numprocs , p i
15
16
17
18
19
20
21
22
INTERFACE
EXTRINSIC(F77_SERIAL) FUNCTION ETIME( t )
REAL : : ETIME, t ( 2 )
END FUNCTION ETIME
23
24
25
26
27
28
29
numprocs = NUMBER_OF_PROCESSORS( )
WRITE( , ) "HPF i n i t i a l i z e d with " , numprocs , " p r o c e s s o r s "
30
31
DO
32
33
34
35
36
37
38
t _ s t a r t = ETIME( t )
39
40
41
h = 1 . 0 d0/n
sum = 0 . 0 d0
42
43
44
45
46
47
! HPF$
INDEPENDENT, NEW( i , x ) , REDUCTION( sum )
DO i = 1 , n
x = h (DBLE( i ) 0 . 5 d0 )
sum = sum + 4 . d0 / ( 1 . d0 + xx )
END DO
52
Parallelization
53
48
49
p i = h sum
50
51
52
53
54
55
56
t_end = ETIME( t )
WRITE( , ) " Elapsed time i s " , t_endt _ s t a r t
CALL PrintOut ( )
57
58
END DO
59
60
chapters/codes/parallel_pi.f
53
54
Chapter A: Codes
A.3 MPI
1
2
3
/ C Example /
#i n c l u d e <s t d i o . h>
#i n c l u d e <mpi . h>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/
/ g e t c u r r e n t p r o c e s s i d /
/ g e t number o f p r o c e s s e s /
%d\n " , rank , s i z e ) ;
chapters/codes/mpi.cpp
1
2
3
4
c F o r t r a n example
program h e l l o
i n c l u d e mpif . h
i n t e g e r rank , s i z e , i e r r o r , tag , s t a t u s (MPI_STATUS_SIZE)
5
6
7
8
9
10
11
c a l l MPI_INIT( i e r r o r )
c a l l MPI_COMM_SIZE(MPI_COMM_WORLD, s i z e , i e r r o r )
c a l l MPI_COMM_RANK(MPI_COMM_WORLD, rank , i e r r o r )
p r i n t , node , rank , : H e l l o world
c a l l MPI_FINALIZE( i e r r o r )
end
chapters/codes/mpi.f
54
55
// Program t o go through a l l p a r t i c l e s i n c e l l i =2
2
3
[...]
4
5
6
7
i n d e x _ p a r t i c l e = FIRST [ i ] ;
// t h e i n d e x o f t h e f i r s t
// p a r t i c l e i n t h e i t h c e l l
8
9
10
N=0;
// c o u n t e r
11
12
13
14
15
i f ( i n d e x _ p a r t i c l e !=0) {
N=1;
// t h e r e s a t l e a s t 1 p a r t i c l e
16
j = First [ i ] ;
w h i l e ( j !=0) {
17
18
19
20
21
22
23
24
25
26
27
N++;
28
29
30
31
[...]
chapters/codes/linked_cells.cpp
55