Rock Paper Scissors Model Using MPI

Rock Paper Scissors Model Using MPI
Jinzi Mac Huang
05/17/2015
Rock Paper Scissors (RPS) Model describes the competition between three
reactants A, B and C with the reaction and diffusion:
A + B ⇒ AA with rate µ1 ,
B + C ⇒ BB with rate µ2 ,
C + A ⇒ CC with rate µ3 ,
A + ⇒ AA with rate d1 ,
B + ⇒ BB with rate d2 ,
C + ⇒ CC with rate d3 .
Here µi is the reaction rate and di is the diffusion rate. The role of A, B and
C is just like the role of rock, paper and scissors in the RPS game. This system
is a classical reaction diffusion system, which is related to the study of pattern
formation and biodiversity. In this final project, 2D and 3D Monte Carlo styled
lattice models are made to study the spatial pattern formation and temporal
oscillation in the RPS model.
In the lattice simulation, the evolution in time is achieved by letting each
reactant check its neighbours and react with them with a probability equals
to the reaction rate. If there is any empty neighbour, the reactant can decide
whether or not to occupy the neighbour with a probability equals to its diffusion
rate. Since the conflict might happen if two reactants want to take the same
position, a random variable is adopted to control the acceptance from different
reactants with equal chance.
The result of 2D simulation is shown in the the movie1 . In the simulation we
use d1 = 0.8, d2 = 0.7, d3 = 0.8 and µ1 = 0.3, µ2 = 0.8, µ3 = 0.8 with periodic
boundary condition. Each reactant is initially placed at a single point on the
1000 × 1000 lattice. From the simulation, we see the growing reactant density
quickly breaks into small structures, the population (density) of reactant goes
to an equilibrium distribution as those structures occupy the whole domain. We
should note that this system is far from equilibrium, as we’ll show later that
the population is oscillatory in time.
1 http://math.nyu.edu/
~jinzi/public/MonteCarlo2015/mov1.mp4
1
Figure 1: Small scale pattern formed by one reactant
(a)
(b)
Estimated fractal dimension = 1.900908
14
10
Estimated correlation length = 4.57 (lattice size)
0
Caa
Caa~� e
12
spatial correlation for a
ln( N
box
)
10
− r / 4.57
8
6
4
2
0
0
1
2
3
n*ln(2)
4
5
6
7
0
5
10
15
20
r = | xi − xj |
25
30
35
Figure 2: Spatial patterns contain the information of fractal dimension and
correlation length. (a) The fractal dimension obtained from box counting. (b)
Log-linear plot of spatial correlation.
We can extract the pattern formed by one reactant as the system breaks into
small structures. Figure 1 shows such patterns, from the inset we can see that
the pattern has a length scale of several lattice units. To study the pattern, we
can use the box counting method to determine the fractal dimension. As shown
in Figure 2(a), this pattern has fractal dimension 1.9, which is very close to 2D
pattern. Next we can study the typical length scale of the system, one way to do
this is to study the correlation length of the pattern. If the spatial correlation
C(|x−x0 |) decays exponentially in distance, we can define the correlation length
l if C(|x − x0 |) ∼ exp(−|x − x0 |/l). Figure 2(b) shows the log-linear plot of
the spatial correlation, we see the correlation decays exponentially within a
very short distance, after line fitting we conclude that our RPS system has a
correlation length of l = 4.57 lattice units.
Next we can extend our simulation to 3D. As the computation gets more
2
100 %
time = 1/efficiency
80 %
60 %
40 %
20 %
0
4
8
16
32
64
number of cores
Figure 3: Strong scalability of the 3D lattice simulation.
intensive, a paralleled version of program is adopted in our simulation. The
parallelism is achieved through the Message Passing Interface (MPI)2 running
on the supercomputer Stampede.
The main computational kernel in the RPS model is to generate random
numbers and check the char value on each slot.Hence the parallelism is straightforward using MPI: each core takes charge of one computing domain and evolves
it into next time step, then they communicate boundary information through
MPI non-blocking communication. After that, similar conflict resolving schemes
are performed as we did in the 2D program.
One major deficiency in our code, is that the cubic computing domain is
divided into several slices. This causes the inter-core information grows too fast
as the size of computation grows. One remedy is to cutting the domain by
small blocks, which can lead to the reduction of total surface area (boundary
information). However doing so brings new difficulty of parallelism since we
need to order each block and let them find its neighbours, hence we did not add
such a feature to the program, which could be a future implementation.
We can also study the scalability of our program. This study is carried on
the Stampede with 8, 16, 32 and 64 cores, the runtime result has been shown on
Figure 3. We can see the program is almost strong scalable, but as we suggested
before, the situation gets worse as we increase the size of computation.
In the 3D simulation, we use d1 = d2 = d3 = 0.8 and µ1 = 0.4, µ2 = 0.6, µ3 =
0.8 on a cubic lattice of size 200 × 200 × 200 with periodic boundary. Though
the study of spatial correlation would be expensive, we can still use the 3D
simulation to study the population dynamics of RPS model. The population
dynamics is shown on Figure 4, we see the population of each reactant grows
exponentially at the beginning, and then different reactants start to react with
each other and finally go to a stage that has small spatial structures everywhere.
Denote the population density of A, B and C as a(t), b(t) and c(t), we can
2 https://www.mpich.org
3
4
x 10
6
a
b
c
3.5
3
population
2.5
2
1.5
1
0.5
0
0
500
1000
1500
2000
2500
3000
t
Figure 4: Population dynamics for the 3D RPS model.
conclude a(t) + b(t) + c(t) = 1 for large enough t. Next we write down the
evolutionary equation of a(t), b(t) and c(t) with the mean field approximation:
∂t a(t) = a(t)[µ1 b(t) − µ3 c(t)]
∂t b(t) = b(t)[µ2 c(t) − µ1 a(t)]
∂t c(t) = c(t)[µ3 a(t) − µ2 b(t)]
This ODE system has a fixed point at (a∗ , b∗ , c∗ ) = (µ2 , µ3 , µ1 )/(µ1 +µ2 +µ3 ).
Denote u = (a − a∗ , b − b∗ )T , we can write down the linearized equations around
this fixed point:
1
µ2 µ3
µ2 (µ1 + µ3 )
∂t u = Lu, where L =
.
−µ2 + µ3
µ1 + µ2 + µ3 −µ3 (µ1 + µ2 )
p
L has 2 eigenvalues λ = ±i µ1 µ2 µ3 /(µ1 + µ2 + µ3 ), they correspond to
the temporal oscillation frequency of:
p
f = µ1 µ2 µ3 /(µ1 + µ2 + µ3 )/2π
In our case µ1 = 0.4, µ2 = 0.6, µ3 = 0.8, we have f = 0.052. So we should
be able to see this frequency if we look at the spectra of population. Figure 5
shows the population (mean free) and its Fourier transform, we obtain a peak at
k = 108 in the frequency space. This peak corresponds to a temporal frequency
of f = 2π/k = 0.0582, which is close to our theoretical prediction. Oscillations
instead of equilibrium supports our argument that this system is actually far
from equilibrium.
In conclusion, we confirmed the existence of spatial patterns and temporal
oscillations in the RPS model, and the diversity is observed to be preserved in
this simple model. The future work could involve the mutation among A, B and
4
4
1
x 10
population
a
b
c
0.5
0
−0.5
−1
1000
1020
1040
1060
1080
5
1100
t
1120
1140
5
x 10
1180
1200
5
x 10
6
8
x 10
5
6
4
|fft(c)|
|fft(b)|
6
|fft(a)|
1160
4
2
2
0
0
0
0
4
3
2
1
500
1000
500
k
k
1000
0
0
500
1000
k
Figure 5: Population (mean subtracted) and its Fourier transform at large t.
C, which is common in the competition between bacteria. The stability of diversity could be another interesting topic, the mean field ODE system is marginally
stable so the thermal fluctuation might destroy the diversity eventually.
References
[1] Kerr, Benjamin, Margaret A. Riley, Marcus W. Feldman, and Brendan JM
Bohannan. ”Local dispersal promotes biodiversity in a real-life game of rockpaperscissors.” Nature 418, no. 6894 (2002): 171-174.
[2] Vanag, Vladimir K., and Irving R. Epstein. ”Pattern formation mechanisms
in reaction-diffusion systems.” International Journal of Developmental Biology 53.5 (2009): 673.
[3] Vanag, Vladimir K., and Irving R. Epstein. ”Segmented spiral waves in a
reaction-diffusion system.” Proceedings of the National Academy of Sciences
100, no. 25 (2003): 14635-14638.
[4] He, Qian, Mauro Mobilia, and Uwe C. Tuber. ”Spatial rock-paper-scissors
models with inhomogeneous reaction rates.” Physical Review E 82, no. 5
(2010): 051909.
[5] May, Robert M., and Warren J. Leonard. ”Nonlinear aspects of competition
between three species.” SIAM Journal on Applied Mathematics 29, no. 2
(1975): 243-253.
5