Docsity

Efficient Parallelization of Stochastic Simulation Algorithm for Chemically Reacting Systems on the Graphics Processing Unit | WRIT 1, Papers of Creative writing

Toggle sidebar
bg1
EFFICIENT PARALLELIZATION OF
STOCHASTIC SIMULATION ALGORITHM
FOR CHEMICALLY REACTING SYSTEMS ON
THE GRAPHICS PROCESSING UNIT
H. Li ∗,1L. Petzold ∗,2,3
∗Department of Computer Science, University of
California, Santa Barbara, CA 93106, U.S.A.
Abstract: In biological systems formed by living cells, the small populations of
some reactant species can result in inherent randomness which cannot be captured
by traditional deterministic approaches. In that case, a more accurate simulation
can be obtained by using the Stochastic Simulation Algorithm (SSA). Many
stochastic realizations are required to capture accurate statistical information of
the solution. This carries a very high computational cost. The current generation
of graphics processing units (GPU) is well-suited to this task. We describe our
implementation, and present some computational experiments illustrating the
power of this technology for this important and challenging class of problems.
Keywords: Stochastic simulation; Chemically reacting systems; System biology;
Parallel; GPU.
1. INTRODUCTION
Chemically reacting systems have traditionally
been simulated by solving a set of coupled or-
dinary differential equations (ODEs). Although
the traditional deterministic approaches are suf-
ficient for most systems, they fail to capture the
natural stochasticity in some biochemical sys-
tems formed by living cells (Gillespie, 1976; Gille-
spie, 1977; McAdams and Arkin, 1997; A. Arkin,
J. Ross and H.H. McAdams, Aug 1998), in which
the small population of a few critical reactant
⋆This work was supported in part by the U.S. Department
of Energy under DOE award No. DE-FG02-04ER25621, by
the National Science Foundation under NSF awards CCF-
0428912, CTS-0205584, CCF-326576, and by the Institute
for Collaborative Biotechnologies through grant DAAD19-
03-D004 from the U.S. Army Research Office.
3Corresponding author, phone: 805-893-5362, fax: 805-
893-5435
species can cause the behavior of the system
to be discrete and stochastic. The dynamics of
those systems can be simulated accurately using
the machinery of Markov process theory, specif-
ically the stochastic simulation algorithm (SSA)
of Gillespie (Gillespie, 1976; Gillespie, 1977). For
many realistic biochemical systems the compu-
tational cost of simulation by the SSA can be
very high. The original form of the SSA is called
the Direct Method (DM). Much recent work has
focused on speeding up the SSA by reformulating
the algorithm (Gibson and Bruck, 2000; Y. Cao,
H. Li and L. Petzold, 2004; J. M. McColluma,
G. D. Peterson, C. D. Cox, M. L. Simpson and
N. F. Samatova, Feb. 2005; J. Blue and Sulli-
van, 1995; Schulze, 2002; Li and Petzold, 2006).
Often, the SSA is used to generate large (typ-
ically ten thousand to a million) ensembles of
stochastic realizations to approximate probability
density functions of species populations or other
output variables. In this case, even the most ef-
pf3
pf4
pf5

Partial preview of the text

Download Efficient Parallelization of Stochastic Simulation Algorithm for Chemically Reacting Systems on the Graphics Processing Unit | WRIT 1 and more Papers Creative writing in PDF only on Docsity!

EFFICIENT PARALLELIZATION OF

STOCHASTIC SIMULATION ALGORITHM

FOR CHEMICALLY REACTING SYSTEMS ON

THE GRAPHICS PROCESSING UNIT

H. Li ∗,^1 L. Petzold ∗,^2 ,^3

∗ (^) Department of Computer Science, University of California, Santa Barbara, CA 93106, U.S.A.

Abstract: In biological systems formed by living cells, the small populations of some reactant species can result in inherent randomness which cannot be captured by traditional deterministic approaches. In that case, a more accurate simulation can be obtained by using the Stochastic Simulation Algorithm (SSA). Many stochastic realizations are required to capture accurate statistical information of the solution. This carries a very high computational cost. The current generation of graphics processing units (GPU) is well-suited to this task. We describe our implementation, and present some computational experiments illustrating the power of this technology for this important and challenging class of problems.

Keywords: Stochastic simulation; Chemically reacting systems; System biology; Parallel; GPU.

1. INTRODUCTION

Chemically reacting systems have traditionally been simulated by solving a set of coupled or- dinary differential equations (ODEs). Although the traditional deterministic approaches are suf- ficient for most systems, they fail to capture the natural stochasticity in some biochemical sys- tems formed by living cells (Gillespie, 1976; Gille- spie, 1977; McAdams and Arkin, 1997; A. Arkin, J. Ross and H.H. McAdams, Aug 1998), in which the small population of a few critical reactant

⋆ (^) This work was supported in part by the U.S. Department of Energy under DOE award No. DE-FG02-04ER25621, by the National Science Foundation under NSF awards CCF- 0428912, CTS-0205584, CCF-326576, and by the Institute for Collaborative Biotechnologies through grant DAAD19- 03-D004 from the U.S. Army Research Office. (^1) [email protected] (^2) [email protected] (^3) Corresponding author, phone: 805-893-5362, fax: 805- 893-

species can cause the behavior of the system to be discrete and stochastic. The dynamics of those systems can be simulated accurately using the machinery of Markov process theory, specif- ically the stochastic simulation algorithm (SSA) of Gillespie (Gillespie, 1976; Gillespie, 1977). For many realistic biochemical systems the compu- tational cost of simulation by the SSA can be very high. The original form of the SSA is called the Direct Method (DM). Much recent work has focused on speeding up the SSA by reformulating the algorithm (Gibson and Bruck, 2000; Y. Cao, H. Li and L. Petzold, 2004; J. M. McColluma, G. D. Peterson, C. D. Cox, M. L. Simpson and N. F. Samatova, Feb. 2005; J. Blue and Sulli- van, 1995; Schulze, 2002; Li and Petzold, 2006). Often, the SSA is used to generate large (typ- ically ten thousand to a million) ensembles of stochastic realizations to approximate probability density functions of species populations or other output variables. In this case, even the most ef-

ficient implementation of the SSA will be very time consuming. Parallel computation on clusters has been used to speed up the simulation of such ensembles (H. Li, Y. Cao, L. Petzold and D. Gillespie, 2007). In (M. Yoshimi, Y. Osana, Y. lwaoka, A. Funahashi, N-Hiroi, Y. Shibata, N. lwanaga, H. Kitano and H. Amano, 2005), the use of Field Programmable Gate Arrays (FPGAs) is investigated to speed up the SSA simulation. However, clusters are still relatively expensive to buy and maintain, and specialized devices such as FPGAs are difficult to program. In this paper we introduce an efficient parallelization of ensem- bles of SSA simulations for chemically reacting systems on the low cost graphics processing unit (GPU) NVIDIA GeForce 8800GTX 4.

This paper is organized as follows. In Section 2 we briefly review the Stochastic Simulation Al- gorithm and some basics of parallel computation with the graphics processing unit. In section 3 we introduce the efficient parallelization of SSA on the GPU. Simulation results are presented in Sec- tion 4, and in Section 5 we draw some conclusions.

2. BACKGROUND

2.1 Stochastic Simulation Algorithm

The Stochastic Simulation Algorithm applies to a spatially homogeneous chemically reacting system within a fixed volume at a constant temperature. The system involves N molecular species {S 1 ,.. ., SN } represented by the dynamical state vector X(t) = (X 1 (t),... , XN (t)) where Xi(t) is the population of species Si in the system at time t, and M chemical reaction channels {R 1 ,... , RM }. Each reaction channel Rj is characterized by a propensity function aj and state change vector νj = {ν 1 j ,... , νN j }, where aj (x)dt is the prob- ability, given X(t) = x, that one Rj reaction will occur in the next infinitesimal time interval [t, t + dt), and νij is the change in the number of species Si due to one Rj reaction.

The Next Reaction Density Function (Gillespie, 2001), which is the basis of SSA, gives the joint probability that reaction Rj will be the next reaction and will occur in the infinitesimal time interval [t, t + dt), given X(t) = x. By applying the laws of probability, the joint density function is formulated as follows:

P (τ, j | xt, t) = aj (xt)e−a^0 (xt)τ^ , (1)

where a 0 (xt) =

∑M

j=1 aj^ (xt).

Starting from (1), the time τ , given X(t) = x, that the next reaction will fire at t + τ , is the

(^4) At the time of this writing, the NVIDIA GeForce 8800GTX costs about $400.

exponentially distributed random variable with mean (^) a 01 (x)

P (τ |x, t) = a 0 (xt)e−a^0 (xt^ )τ^ (τ ≥ 0), (2) The index j of that firing reaction is the integer random variable with probability

P (j|τ, x, t) =

aj (xt) a 0 (xt)

(j = 1, ...., M ). (3)

Thus on each step of the simulation, the random pairs (τ, j) are obtained based on the standard Monte Carlo inversion generating rules: first we produce two uniform random numbers r 1 and r 2 from U (0, 1), the uniform distribution on [0, 1]. Then τ is given by

τ =

a 0 (xt)

ln

r 1

The index j of the selected reaction is the smallest integer in [1, M ] such that

∑^ j

j′^ =

aj′ (xt) > r 2 a 0 (xt). (5)

Finally, the population vector X is updated by the state change vector ν, and the simulation is advanced to the next reacting time. Because SSA must simulate every reaction event, simulation with SSA can be quite computationally demanding. When an ensemble (ten thousand to a million realizations or more) must be gener- ated, the computation can become intractable. A number of different formulations of SSA have been proposed, in an effort to speed up the sim- ulation (Gibson and Bruck, 2000; Y. Cao, H. Li and L. Petzold, 2004; J. M. McColluma, G. D. Peterson, C. D. Cox, M. L. Simpson and N. F. Samatova, Feb. 2005; J. Blue and Sullivan, 1995; Schulze, 2002; Li and Petzold, 2006). The most time-consuming step of the SSA is the selection of the next reaction to fire. The complexity of this step for the Direct Method is O(M ), where M is the number of reactions. To the best of our knowledge, the fastest known SSA formulation is something we call the Logarithmic Direct Method (LDM) because its complexity for the critical step is O(logM ). The LDM algorithm comes from the literature on Kinetic Monte Carlo (KMC) algo- rithms. The SSA is a type of KMC algorithm that is applied to chemical kinetics. Because of the spe- cial structure of the chemical kinetics problems, it has been possible to put SSA on a solid theoretical foundation. Further efficiency of the LDM can be achieved by using sparse matrix techniques in the system state update stage (Li and Petzold, 2006). It is this method (LDM with sparse matrix up-

DRAMDRAM

Cache

ALU

Control

ALU

ALU

ALU

DRAM

Cache

ALU

Control

ALU

ALU

ALU

DRAM

Fig. 1. CPU vs. GPU arichitecture

write ability to reduce the dependence of ap- plication performance on the DRAM bandwidth (Corporation, n.d.a).

The structure of CUDA computation broadly fol- lows the data-parallel model: each of the proces- sors executes the same sequence of instructions on different sets of the data in parallel. The data can be broken into a 1D or 2D grid of blocks, and each block can be 1D, 2D or 3D and can allow up to 512 threads which can collaborate through shared memory. Threads within a block can collaborate via the shared memory.

Unfortunately, currently the CPU and GPU can- not run in parallel. Also it is not possible to download data and run a kernel in parallel, or to execute multiple kernels at the same time through the CUDA. Users can use a single kernel to per- form multiple tasks by branching in the kernel based on the thread id, but the branches will slow down the simulation.

3. IMPLEMENTATION DETAILS

3.1 Parallelism across the simulations

Our focus is on computation of ensembles of SSA realizations. Ensembles of SSA runs for chemically reacting systems are very well-suited for imple- mentation on the GPU through the CUDA. The simulation code can be put into a single kernel running in parallel on a large set of system stat vectors X(t). The large set of final stat vectors X(tf inal) will contain the desired results.

The initial conditions X(0) and the stoichiometric matrix ν originally will be in the host memory. We must copy them to the device memory by CUDAMemcpy in the driver running on the the CPU. We minimize the transfer between the host and device by using an intermediate data struc- ture on the device and batch a few small trans- fers into a big transfer to reduce the overhead for each transfer. Next, we need to consider the relatively large global memory vs. the limited- size shared memory. The global memory adjacent

to the GPU chip has higher latency and lower bandwidth than the on-chip shared memory. It takes about 400-600 clock cycle latency to access the global memory vs. 4 clock cycles to read or write the shared memory. To effectively use the GPU, our simulation makes as much use of on- chip shared memory as possible. We load X(0) and the stoichiometric matrix ν from the device memory to the shared memory at the very begin- ning of the kernel, process the data (propensity calculation, state vector update, etc.) in shared memory, and write the result back to the device memory at the end. Because the same instruction sequence is executed for each data set, there is a low requirement for flow control. This matches the GPU’s architecture. The instruction sequence is performed on a large number of data sets which do not need to swap out, hence the memory access latency is negligible compared with the arithmetic calculation. The CUDA allows each block to contain at most 512 threads, but blocks with the same dimension and size that run the same kernel can be put into a grid of blocks. Thus the total number of threads for one kernel can be very large. Given the total number of realizations of SSA to be simulated, the number of threads per block and the number of blocks must be carefully balanced to maximize the utilization of computation resources. For stochas- tic simulation, we can’t use too many threads per block since there is only a limited shared memory and all system state vectors and propensities have been put in shared memory for efficient frequent access. Thus the number P of threads per block should satisfy (N + M ) ∗ 4 ∗ P + α < 16 K, where N is the number of chemical species, M is the number of reactions, 4 is the size (in bytes) of an integer/float variable, 16K is the maximum shared memory we can use within one block, and α is the shared memory used by the random number generator (this is relatively small).

Random Number Generation Statistical results can only be relied on if the independence of the random number samples can be guaranteed. Thus

generating independent sequence of random num- bers is one of the important issues of implementing simulation for ensembles of stochastic simulation algorithms in parallel.

Originally we considered pre-generating a large number of random numbers by the CPU. Since the CPU and GPU can’t run in parallel, we can pre-generate a huge number of random numbers and store them in the shared memory and swap back to the CPU to generate more when they are used up. Alternatively, we could pre-generate a huge number of random numbers and put them in the global memory. Both methods will waste too much time for data access. Furthermore, the Scalable Parallel Random Number Generators Li- brary (SPRNG) (Mascagni, 1999; Mascagni and Srinivasan., 2000), which we use in our StochKit (H. Li, Y. Cao, L. Petzold and D. Gillespie, 2007) package for discrete stochastic simulation because of its excellent statistical properties, cannot be implemented on the GPU due to its complicated data structure. The only solution appears to im- plement a simple random number generator on the GPU. Experts suggest using a mature random number generator instead of inventing a new one, since it requires great care and extensive testing to evaluate a random number generator(Richard P. Brent, 1992). Thus we chose the Mersenne Twister from the literature in our application (members, n.d.).

The Mersenne Twister (MT) was developed by Makoto Matsumoto and Takuji Nishimura ( Makoto Matsumoto and Takuji Nishimura, 1998) in 1997. This method has passed many statistical random- ness tests including the stringent Diehard tests (members, n.d.). The fully tested MT random number generator can efficiently generate high quality, long period random sequences with high order of dimensional equidistribution. Another good property of the MT is its efficient use of memory. Thus it is very suitable for our appli- cation. The original single threaded C version was developed by Takuji Nishimurar and Makoto Matsumoto, with initialization improved in 2002 (Podlozhnyuk, n.d.). In our implementation we modified Eric Mills’s multithreaded C implemen- tation (members, n.d.). Since our application re- quires a huge number of random numbers even for one realization of a simple model, we use the shared memory for random number generation to minimize the data launching and accessing time. This random number generation implementation allows 227 threads for each block, which is more than the number of threads needed by the stochas- tic simulation.

4. PARALLEL SIMULATION

PERFORMANCE

The performance of the parallel simulation is lim- ited by the number of processors available for the computation, the workload of the available proces- sors, and the communication and synchronization costs. It is important to note that more processors does not necessarily mean better performance. Our simulations were run on the NVIDIA GeForce 8800GTX installed on a personal computer with Intel Pentium 3.00Ghz CPU and 3.50GB of RAM with physical Address Extension, and Windows XP Professional Version 2002 with Service Pack

Example 4.1. Decay Dimerization Model The decay dimerization model (Gillespie, 2001) involves three reacting species S 1 , S 2 , S 3 and four reaction channels R 1 , R 2 , R 3 , R 4

S 1 c 1 → 0 S 1 + S 1

c 3 ⇀↽ c 2

S 2

S 2

c 4 → S 3.

We used the reaction rate constants from (Gillespie, 2001), c 1 = 1, c 2 = 0. 002 , c 3 = 0. 5 , c 4 = 0. 04 , (7) and the initial conditions X 1 = 10^4 , X 2 = X 3 = 0. (8)

The simulation performance has been extraordi- nary, as shown in Figure 3. For 30000 realizations, the parallel (GPU) simulation is almost 215 times faster than the sequential simulation on the host computer.

0 0.5 1 1.5 2 2.5 3 3. x 10^4

0

1

2

3

4

4.5 x 10

5

Number of Realizations

Simulation Time (ms)

Performance Comparison Sequential Method Parallel Method (GPU)

Fig. 3. Simulation time for dimer decay model on GPU vs. host computer.

In general, as the size of the system increases, the speed-up of the GPU decreases because of the limited shared memory. However, most bio- chemical systems are loosely coupled. Very large

5. CONCLUSIONS

The SSA is the workhorse algorithm for discrete stochastic simulation in systems biology. Even the most efficient implementations of the SSA can be very time-consuming. Often the SSA is used to generate ensembles (typically ten thousand to a million) of stochastic simulations. The current generation of GPUs appears to be very well-suited for this purpose. On the two model problems we tested, we observed speedups about 200 times for the GPU, over the time to compute on the host workstation. With this impressive performance improvement, in one day we can generate data which would require more than six months of computation with the sequential code.

This technology is not quite ready for the novice user. Programs must be written to be memory efficient, with the GPU architecture in mind. The computation is limited to single precision, the API does not yet have all the features to take full advantage of the architecture, transferring data to the GPU is time consuming, the CPU and GPU cannot compute simultaneously, and there are a number of problems and limitations that NVIDIA is still working on.

REFERENCES

Makoto Matsumoto and Takuji Nishimura (1998). Mersenne Twister: a 623-dimensionally equidistributed uniform pseudo-random number generator. ACM Transactions on Modeling and Computer Simulation (TOMACS) 8 , 3–30. A. Arkin, J. Ross and H.H. McAdams (Aug 1998). Stochastic kinetic analysis of developmental pathway bifurcation in phage λ-infected E. Coli cells. Genetics 149 , 1633–1648. Corporation, NVIDIA (n.d.a). NVIDIA CUDA Compute Unified Device Architecture Pro- gramming Guide. http://developer.download.nvidia.com. Corporation, NVIDIA (n.d.b). NVIDIA home- page. http://www.nvidia.com. Gibson, M. and J. Bruck (2000). Efficient ex- act stochastic simulation of chemical systems with many species and many channels. J. Phys. Chem. 105 , 1876–1889. Gillespie, D.T. (1976). A general method for numerically simulating the stochastic time evolution of coupled chemical reactions. J. Comp. Phys. 22 , 403–434. Gillespie, D.T. (1977). Exact stochastic simula- tion of coupled chemical reactions. J. Phys. Chem. 81 , 2340–2361. Gillespie, D.T. (2001). Approximate accelerated stochastic simulation of chemically reacting systems. J. Chem. Phys. 115 (4), 1716–1733.

H. Li, Y. Cao, L. Petzold and D. Gillespie (2007). Algorithms and software for stochas- tic simulation of biochemical reacting sys- tems. Biotechnology Progress. Submitted. J. Blue, I. Beichl and F. Sullivan (1995). Faster Monte Carlo simulations. Physical Rev. E 51 , 867–868. J. M. McColluma, G. D. Peterson, C. D. Cox, M. L. Simpson and N. F. Samatova (Feb. 2005). The sorting direct method for stochastic sim- ulation of biochemical systems with varying reaction execution behavior. J. Comput. Biol. Chem. 30 , 39–49. Li, H. and L. Petzold (2006). Logarithmic Di- rect Method for discrete stochastic simula- tion of chemically reacting systems. Tech- nical report. Department of Computer Sci- ence, University of California, Santa Barbara. http://www.engr.ucsb.edu/∼cse. M. Yoshimi, Y. Osana, Y. lwaoka, A. Funahashi, N-Hiroi, Y. Shibata, N. lwanaga, H. Kitano and H. Amano (2005). The design of scalable stochastic biochemical simulator on FPGA. Proc. of I. C. on Field Programmable Tech- nologies (FPT2005) pp. 139–140. Mascagni, M. (1999). SPRNG: A scalable library for pseudorandom number generation. In: Proceedings of the Ninth SIAM Conference on Parallel Processing for Scientific Computing. San Antonio, Texas. Mascagni, M. and A. Srinivasan. (2000). SPRNG: A scalable library for pseudorandom number generation. In: ACM Transactions on Math- ematical Software. Vol. 26. pp. 436–461. McAdams, H.H. and A. Arkin (1997). Stochastic mechanisms in gene expression. Proc. Natl. Acad. Sci. USA 94 , 814–819. members, NVIDIA Forums (n.d.). NVIDIA fo- rums. http://forums.nvidia.com. N. Shnerb, Y. Louzoun, E. Bettelheim, S. Solomon (2000). The Importance of Being Discrete - Life Always Wins on the Surface Proc. Proc. Natl. Acad. Sci. USA 97 , 10332. people, PCperspective (n.d.). PCperspective. http://www.pcper.com. Podlozhnyuk, Victor (n.d.). Mersenne Twister. http://developer.download.nvidia. com. Richard P. Brent (1992). Uniform Random Num- ber Generators for Vector and Parallel Com- puters. Report TR-CS-92-02. Schulze, T. P. (2002). Kinetic Monte Carlo simu- lations with minimal searching. Physical Re- view E 65 (3), 036704. Y. Cao, H. Li and L. Petzold (2004). Efficient formulation of the stochastic simulation al- gorithm for chemically reacting systems. J. Phys. Chem. 121 (9), 4059–4067.