560 views

Uploaded by Don Stewart

We address the tension between software generality and performance in the domain of simulations based on Monte-Carlo methods. We simultaneously achieve generality and high performance by a n…Full description

save

- Improving Data Structures
- Domain Specific Languages for Domain Specific Problems
- lock free
- Simulation Lab report 9.doc
- The Design and Implementation of xmonad
- Modeling a Composition PDF Transport
- Lecture 1
- Engineering Large Projects in Haskell: A Decade of FP at Galois
- LBNL-49407
- paper A.pdf
- Engineering Large Projects in a Functional Language
- Loop Fusion in Haskell
- 4100f1
- Algorithm MTech
- Introduction to Parallel Computing
- Distributed Systems Exercise I
- Minimization of open orders: application of a re-distribution coordination policy
- Chapter 1
- Neural computation platforms: to the Blue Brain and beyond
- Motion Estimation
- MObile Communication
- On-Chip Network-Enabled Multicore Platforms.pdf
- Ensayo MPI
- annotatedbib
- Chap2 Slides
- 4.Course Plan ACA.docx
- A Vlsi Design for Full Search Block Matching Motion Estimation
- A Neural Network on GPU - Code Project
- Nodes Modes Codes
- Tracker Thesis Very Good
- Multicore Haskell Now!
- Multicore programming in Haskell
- An Introduction to Communicating Haskell Processes
- The Semantics of Asynchronous Exceptions
- Concurrent Orchestration in Haskell
- Hackage, Cabal and the Haskell Platform: The Second Year
- Engineering Large Projects in a Functional Language
- Loop Fusion in Haskell
- Modern Benchmarking in Haskell
- Galois Tech Talk: A Scalable Io Manager for GHC
- Evaluation strategies and synchronization: things to watch for
- Building a business with Haskell: Case Studies: Cryptol, HaLVM and Copilot
- Practical Haskell Programming: scripting with types
- Stream Fusion for Haskell Arrays
- A Wander Through GHC's New IO Library
- Haskell: Batteries Included
- Engineering Large Projects in Haskell: A Decade of FP at Galois
- Multicore Haskell Now!
- Haskell Arrays Accelerated with GPUs
- Multicore Programming in Haskell Now!
- The Birth of the Industrial Haskell Group : CUFP 2009
- The Haskell Platform: Status Report
- Supercompilation for Haskell

Gabriele Keller Hugh Chaffey-Millar Manuel M. T. Chakravarty Don Stewart Christopher Barner-Kowollik University of New South Wales

Programming Languages and Systems & Centre for Advanced Macromolecular Design

Don Stewart | Galois Inc

Specialising Simulator Generators

Imagine. . .

You are not a computer scientist, but a chemist!

• You study new polymers and their efﬁcient production • The search space is too big to try all possible approaches

in the lab

Don Stewart | Galois Inc

Specialising Simulator Generators

Imagine. . .

You are not a computer scientist, but a chemist!

• You study new polymers and their efﬁcient production • The search space is too big to try all possible approaches

in the lab Kinetic models (here, polymerisation of bulk styrene)

Don Stewart | Galois Inc

Specialising Simulator Generators

Imagine. . .

You are not a computer scientist, but a chemist!

• You study new polymers and their efﬁcient production • The search space is too big to try all possible approaches

in the lab Kinetic models (here, polymerisation of bulk styrene)

**Exploration by way of computational chemistry
**

• Turn kinetic models into PDEs • Solve with a deterministic solver, esp. h-p-Galerkin method

Don Stewart | Galois Inc Specialising Simulator Generators

Solving PDEs gives molecular weight distribution (MWD)

14000 concentration -1 /mol L 14000 12000 10000 8000 6000 4000 7000 2000 0 10000 7500 5000 simulated time / seconds

0

800

700

600

500 400 degree of polymerisation

2500 300 200 100 0 0

Don Stewart | Galois Inc

Specialising Simulator Generators

Solving PDEs gives molecular weight distribution (MWD)

14000 concentration -1 /mol L 14000 12000 10000 8000 6000 4000 7000 2000 0 10000 7500 5000 simulated time / seconds

0

800

700

600

500 400 degree of polymerisation

2500 300 200 100 0 0

**Problems encountered by chemists
**

• Scalability: slow for complex systems (star polymers) • Generality: missing microscopic information: multiple chain lengths (i.e., star polymers) cross-linking densities and branching copolymer composition • Improving both speed and information content seems hard

Don Stewart | Galois Inc Specialising Simulator Generators

**Back To Being a Programming Languages Researcher!
**

Attack the problem from a different angle

• Replace deterministic by stochastic solver • Don’t solve PDEs, use microscopic simulation

Don Stewart | Galois Inc

Specialising Simulator Generators

**Back To Being a Programming Languages Researcher!
**

Attack the problem from a different angle

• Replace deterministic by stochastic solver • Don’t solve PDEs, use microscopic simulation

Turn the problem into a programming languages problem Regard kinetic models as probabilistic rewrite systems

Don Stewart | Galois Inc

Specialising Simulator Generators

**Back To Being a Programming Languages Researcher!
**

Attack the problem from a different angle

• Replace deterministic by stochastic solver • Don’t solve PDEs, use microscopic simulation

Turn the problem into a programming languages problem Regard kinetic models as probabilistic rewrite systems

**Potential to gain both speed and information content
**

• Microscopic simulation gives microscopic information • Stochastic solvers (Monte-Carlo) are easier to parallelise • We know much about speeding up the execution of RSes

Don Stewart | Galois Inc Specialising Simulator Generators

**Microscopic simulation of polymerisation kinetics
**

The soup—aka system state

• Multiset of molecules • Subscript is chain length of a polymer • Monomers have no subscript • Star polymers have multiple subscripts

Don Stewart | Galois Inc

Specialising Simulator Generators

**Microscopic simulation of polymerisation kinetics
**

The soup—aka system state

• Multiset of molecules • Subscript is chain length of a polymer • Monomers have no subscript • Star polymers have multiple subscripts

**Reactions with rate coefﬁcients—aka probabilistic rewrite rules Reactions:
**

• Consume one or two molecules • Produce one or two molecules

I → I• + I• [kd ] I• + M → P1 Pn + M → Pn+1 Pn + Pm → Dn+m [ki ] [kp ] [kt ]

Rate coefﬁcients:

• Reaction probability relative to

molecule concentration

Don Stewart | Galois Inc

Specialising Simulator Generators

Structure of the simulation

** Compute reaction probabilities, known as rates:
**

Product of the reaction’s rate coefﬁcient and current concentration of the reactants Stored in reaction rate tree Determines the probability distribution function Rate coefﬁcients are experimentally determined

Don Stewart | Galois Inc Specialising Simulator Generators

Structure of the simulation

** Randomly pick a reaction
**

Reaction rate tree enables fast reaction selection given a uniformly distributed random number E.g., we might pick Pn + Pm → Pn+m [NB: we haven’t ﬁxed n and m yet]

Don Stewart | Galois Inc

Specialising Simulator Generators

Structure of the simulation

** Randomly pick the molecules
**

For monomers, there is nothing to do For polymers, we need to pick one or more chain lengths E.g., For Pn + Pm → Pn+m , pick n and m randomly (from available lengths) In some systems, different chain lengths react with different probabilities

Don Stewart | Galois Inc Specialising Simulator Generators

Structure of the simulation

** Compute reaction products
**

Update the concentration of molecules E.g., remove Pn and Pm and add Pn+m Advance system clock (non-trivial)

Don Stewart | Galois Inc

Specialising Simulator Generators

Specialisation

Reaction kinetics as probabilistic multiset rewriting

• Direct implementation of the four simulator steps

=⇒ interpreter for the rewrite system

Don Stewart | Galois Inc

Specialising Simulator Generators

Specialisation

Reaction kinetics as probabilistic multiset rewriting

• Direct implementation of the four simulator steps

**=⇒ interpreter for the rewrite system
**

• Performance is an issue: Let’s compile the rewrite system!

Which part of the simulator is worth compiling?

Don Stewart | Galois Inc

Specialising Simulator Generators

Specialisation

Reaction kinetics as probabilistic multiset rewriting

• Direct implementation of the four simulator steps

**=⇒ interpreter for the rewrite system
**

• Performance is an issue: Let’s compile the rewrite system!

**Which part of the simulator is worth compiling?
**

• Only code that depends on the kinetics model (our

**“program”) • The code that updates the system state according to a selected reaction and reactants:
**

1 2 3

Update molecule count—i.e., reactant concentrations Adapt reaction probabilities Modify reaction rate tree

Don Stewart | Galois Inc

Specialising Simulator Generators

**Runtime system as template (using CPP to instantiate)
**

#include "genpolymer.h" // generated by simulator generator void oneReaction () { // . . . variable declarations omitted. . .

updateProbabilities (); reactIndex = pickRndReact (); mol1Len = pickRndMol (reactToSpecInd1 (reactIndex)); if (consumesTwoMols (reactIndex)) mol2Len = pickRndMol (reactToSpecInd2 (reactIndex)); switch (reactIndex) // compute reaction products DO_REACT_BODY // deﬁned in genpolymer.h incrementMolCnt (resMol1Spec, resMol1Len); if (resMolCnt == 2) incrementMolCnt (resMol2Spec, resMol2Len); advanceSystemTime (); // compute ∆t of this reaction }

Don Stewart | Galois Inc

Specialising Simulator Generators

**Simulator generator in Haskell
**

• Compiles the kinetics model (probabilistic rewrite system) • For example, I → I• + I•

⇓ #define I_Star 2 ... #define DECOMPOSITION 0 ... #define DO_REACT_BODY \ {case DECOMPOSITION:\ resMolCnt = 2;\ resMol1Spec = I_Star;\ resMol2Spec = I_Star;\ break;\ ...

genpolymer.h

Don Stewart | Galois Inc

Specialising Simulator Generators

Haskell

Programming in Haskell

• Popular functional language: fast, all functions, no OO! • Pure – no side effects by default • Richly and strongly typed – no runtime type errors • Easy to parallelise, implicit and explicit cheap threads • Algebraic data types – good for symbolic manipulation

Example: data parallel dot product dotp :: [: Double :] → [: Double :] → Double dotp v w = sumP (zipWithP (∗) v w)

Don Stewart | Galois Inc

Specialising Simulator Generators

**Specialising Simulator Generator
**

• Input is reaction speciﬁcation • Custom C runtime for reaction generated from Haskell • All inputs become static constants • C compiler then aggressively optimises the reaction

implementation

• Run compiled reaction and inspect results

Portability

• Simulator generation easy to retarget: single core,

multicore, clusters

• Just port the simulator runtime

Don Stewart | Galois Inc

Specialising Simulator Generators

Parallelisation

Vanilla Monte-Carlo • Probability distribution function is static

• All stochastic events are independent • Embarrassingly parallel

Don Stewart | Galois Inc

Specialising Simulator Generators

Parallelisation

Vanilla Monte-Carlo • Probability distribution function is static

• All stochastic events are independent • Embarrassingly parallel

**Markov-chain Monte-Carlo • Probability distribution function is dynamic
**

• It is dependent on previous stochastic events • Fully sequential (no parallelism)

Don Stewart | Galois Inc

Specialising Simulator Generators

Parallelisation

Vanilla Monte-Carlo • Probability distribution function is static

• All stochastic events are independent • Embarrassingly parallel

**Markov-chain Monte-Carlo • Probability distribution function is dynamic
**

• It is dependent on previous stochastic events • Fully sequential (no parallelism)

**Our solution: stirring
**

• Physical reality: only molecules in close proximity can react • Stirring: regularly, exchange and average system state • Optimal stirring frequency dependant on Brownian motion

Don Stewart | Galois Inc Specialising Simulator Generators

Benchmarks

Specialised versus unspecialised

70 generic simulator (gcc) generic simulator (icc) specialised simulator (gcc) specialised simulator (icc)

60

50

Time (sec)

40

30

20

10

0

107

2*107 3*107 Simulator steps

4*107

5*107

**[icc = Intel C Compiler; gcc = GNU C Compiler]
**

Don Stewart | Galois Inc Specialising Simulator Generators

Parallel speedup

8 P4 cluster (1010 particles) Opteron SMP (10 9 particles) P4 cluster (109 particles) Opteron SMP (10 particles)

10

8

7

7

6 Relative Speedup

6

5

5

4

4

3

3

2

2

1 1 2 3 4 PE 5 6 7 8

1

[P4 cluster = Intel P4, 3.2GHz, with GigaBit Ethernet; Opteron SMP = AMD Athlon 64 3200+, 2.2GHz, with HyperTransport 1.0]

Don Stewart | Galois Inc Specialising Simulator Generators

**Deterministic versus Monte-Carlo
**

40000 35000 100000 logarithmic depiction

simulation time / seconds

30000 25000 20000 15000 10000 5000 0 10000 1000 100 10 (1) (2) (3) (4) (5) (6) (7) (8) (9)

(1) PREDICI original 0.02

(2) PREDICI optimised 0.01

(3) PREDICI optimised 0.02

(4) PREDICI optimised 0.05

(5) MC 1010

(6) MC 109

(7)

(8)

(9) MC 109 / 8

MC 1010 / 8 MC 1010 / 16

[PREDICI = commercial coarse-grained h-p-Galerkin simulator; MC with 4 PEs matches PREDICI with 109 particles and accuracy 0.02]

Don Stewart | Galois Inc

Specialising Simulator Generators

Lessons Learnt

Make it a PL problem

• It can be worthwhile to turn seemingly non-PL problems

(shortcomings with deterministic PDE solvers) into PL problems (multiset rewriting & code specialisation)

Don Stewart | Galois Inc

Specialising Simulator Generators

Lessons Learnt

Make it a PL problem

• It can be worthwhile to turn seemingly non-PL problems

(shortcomings with deterministic PDE solvers) into PL problems (multiset rewriting & code specialisation) Declarative languages for computationally-intensive code

• Generative approaches can outperform hand-coded

**low-level code
**

• Generators/compilers are a core domain of functional

languages

• Why not generate code for your next hard simulator

problem?

Don Stewart | Galois Inc

Specialising Simulator Generators

Lessons Learnt

Make it a PL problem

• It can be worthwhile to turn seemingly non-PL problems

(shortcomings with deterministic PDE solvers) into PL problems (multiset rewriting & code specialisation) Declarative languages for computationally-intensive code

• Generative approaches can outperform hand-coded

**low-level code
**

• Generators/compilers are a core domain of functional

languages

• Why not generate code for your next hard simulator

problem? Prototyping

• Simulator development by prototyping in Haskell (→ paper)

Don Stewart | Galois Inc Specialising Simulator Generators

**Specialisation of inner loops in Monte-Carlo solvers
**

• MC always execute an inner loop very many times • Specialisation is worthwhile whenever signiﬁcant

parameters are ﬁxed over all or many iterations

Don Stewart | Galois Inc

Specialising Simulator Generators

**Specialisation of inner loops in Monte-Carlo solvers
**

• MC always execute an inner loop very many times • Specialisation is worthwhile whenever signiﬁcant

parameters are ﬁxed over all or many iterations Parallelisation of Markov-chain Monte-Carlo • Averaging of parallel system states (i.e., stirring) is generally applicable in MCMC

Don Stewart | Galois Inc

Specialising Simulator Generators

Conclusions

**Specialising Monte-Carlo simulator generators
**

• Kinetics models as probabilistic rewrite systems • Highly optimised low-level code • Parallelisation of Markov-chain Monte-Carlo • First competitive Monte-Carlo simulator for polymerisation

**kinetics, produces microscopic information Future work • Other polymer structures (meshes)
**

• Application to ﬁnancial mathematics

Don Stewart | Galois Inc

Specialising Simulator Generators

Thanks!

Make sure you understand compilers

Don Stewart | Galois Inc

Specialising Simulator Generators

- Improving Data StructuresUploaded byDon Stewart
- Domain Specific Languages for Domain Specific ProblemsUploaded byDon Stewart
- lock freeUploaded bysavio77
- Simulation Lab report 9.docUploaded byMuhammad Irshad Nazeer
- The Design and Implementation of xmonadUploaded byDon Stewart
- Modeling a Composition PDF TransportUploaded byMohamad Poortoosi
- Lecture 1Uploaded byHoward Nguyen
- Engineering Large Projects in Haskell: A Decade of FP at GaloisUploaded byDon Stewart
- LBNL-49407Uploaded byLuckysaluter Saluter
- paper A.pdfUploaded byPhulturoo Khan
- Engineering Large Projects in a Functional LanguageUploaded byDon Stewart
- Loop Fusion in HaskellUploaded byDon Stewart
- 4100f1Uploaded byPrana Koirala
- Algorithm MTechUploaded byDebranjan Pal
- Introduction to Parallel ComputingUploaded byMuhammed İkbaL Gürbüz
- Distributed Systems Exercise IUploaded bymamakip
- Minimization of open orders: application of a re-distribution coordination policyUploaded byal9028
- Chapter 1Uploaded byfarooqahmedqureshi
- Neural computation platforms: to the Blue Brain and beyondUploaded byvaljok
- Motion EstimationUploaded bygech4
- MObile CommunicationUploaded byNikhil Prakash
- On-Chip Network-Enabled Multicore Platforms.pdfUploaded byvenkatmusala
- Ensayo MPIUploaded byDaniel Lara
- annotatedbibUploaded byapi-252350142
- Chap2 SlidesUploaded byflorenceprasad
- 4.Course Plan ACA.docxUploaded bymenakadevi
- A Vlsi Design for Full Search Block Matching Motion EstimationUploaded byhtmabalhp
- A Neural Network on GPU - Code ProjectUploaded byNadix Privado
- Nodes Modes CodesUploaded byzine68
- Tracker Thesis Very GoodUploaded bySiva Kumar

- Multicore Haskell Now!Uploaded byDon Stewart
- Multicore programming in HaskellUploaded byDon Stewart
- An Introduction to Communicating Haskell ProcessesUploaded byDon Stewart
- The Semantics of Asynchronous ExceptionsUploaded byDon Stewart
- Concurrent Orchestration in HaskellUploaded byDon Stewart
- Hackage, Cabal and the Haskell Platform: The Second YearUploaded byDon Stewart
- Engineering Large Projects in a Functional LanguageUploaded byDon Stewart
- Loop Fusion in HaskellUploaded byDon Stewart
- Modern Benchmarking in HaskellUploaded byDon Stewart
- Galois Tech Talk: A Scalable Io Manager for GHCUploaded byDon Stewart
- Evaluation strategies and synchronization: things to watch forUploaded byDon Stewart
- Building a business with Haskell: Case Studies: Cryptol, HaLVM and CopilotUploaded byDon Stewart
- Practical Haskell Programming: scripting with typesUploaded byDon Stewart
- Stream Fusion for Haskell ArraysUploaded byDon Stewart
- A Wander Through GHC's New IO LibraryUploaded byDon Stewart
- Haskell: Batteries IncludedUploaded byDon Stewart
- Engineering Large Projects in Haskell: A Decade of FP at GaloisUploaded byDon Stewart
- Multicore Haskell Now!Uploaded byDon Stewart
- Haskell Arrays Accelerated with GPUsUploaded byDon Stewart
- Multicore Programming in Haskell Now!Uploaded byDon Stewart
- The Birth of the Industrial Haskell Group : CUFP 2009Uploaded byDon Stewart
- The Haskell Platform: Status ReportUploaded byDon Stewart
- Supercompilation for HaskellUploaded byDon Stewart