pystokes a case study of accelerating python using cython
play

PyStokes: A case study of accelerating Python using Cython Rajesh - PowerPoint PPT Presentation

PyStokes: A case study of accelerating Python using Cython Rajesh Singh Jan 31, 2015 1 Contributors 2 Outline Stokes law Rigid body motion of active colloids 3 Outline Stokes law Rigid body motion of active colloids


  1. PyStokes: A case study of accelerating Python using Cython Rajesh Singh Jan 31, 2015 1

  2. Contributors 2

  3. Outline • Stokes law • Rigid body motion of active colloids 3

  4. Outline • Stokes law • Rigid body motion of active colloids • Python 3

  5. Outline • Stokes law • Rigid body motion of active colloids • Python • Cython 3

  6. Outline • Stokes law • Rigid body motion of active colloids • Python • Cython • Python and Cython 3

  7. Outline • Stokes law • Rigid body motion of active colloids • Python • Cython • Python and Cython • PyStokes 3

  8. Outline • Stokes law • Rigid body motion of active colloids • Python • Cython • Python and Cython • PyStokes • Benchmarks 3

  9. Stokes law 4

  10. Stokes law F n V n = 6 πη a 4

  11. Stokes law F n V n = 6 πη a T n Ω n = 8 πη a 3 4

  12. Rigid body motion of active colloids N � � � � π ( T , l σ ) · V ( l σ ) µ TT nm · F B m + µ TR nm · T B V n = + m , nm m m =1 l σ, m N � � π ( R , l σ ) · V ( l σ ) � µ RT nm · F B m + µ RR nm · T B � Ω n = + nm m . m m =1 l σ, m J. Stat. Mech. (2015) P06017 5

  13. Python 1 Free and open source 2 High level & interpreted 3 Interactive environment 4 Object-oriented 6

  14. Python 1 Free and open source 5 Speed 2 High level & interpreted 6 Dictionary lookups 3 Interactive environment 7 Function calling overheads 4 Object-oriented 8 GIL - global interpreter lock 6

  15. Cython • Attempt to make a superset of python 7

  16. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C 7

  17. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C • Compiled 7

  18. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C • Compiled • Cdef variables, attributes, functions 7

  19. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C • Compiled • Cdef variables, attributes, functions • Supports parallelism (openMP) by opening GIL 7

  20. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C • Compiled • Cdef variables, attributes, functions • Supports parallelism (openMP) by opening GIL • Memoryviews allow efficient access to memory buffers like numpy arrays without python overhead 7

  21. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C • Compiled • Cdef variables, attributes, functions • Supports parallelism (openMP) by opening GIL • Memoryviews allow efficient access to memory buffers like numpy arrays without python overhead • Steps involves in building a cython code 1 A .pyx file is compiled by cython to .c 7

  22. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C • Compiled • Cdef variables, attributes, functions • Supports parallelism (openMP) by opening GIL • Memoryviews allow efficient access to memory buffers like numpy arrays without python overhead • Steps involves in building a cython code 1 A .pyx file is compiled by cython to .c 2 The .c file is then compiled by the C compiler 7

  23. Cython • Attempt to make a superset of python • High level coolness of python along with the speed of C • Compiled • Cdef variables, attributes, functions • Supports parallelism (openMP) by opening GIL • Memoryviews allow efficient access to memory buffers like numpy arrays without python overhead • Steps involves in building a cython code 1 A .pyx file is compiled by cython to .c 2 The .c file is then compiled by the C compiler 3 Building can be done in a single step using a setup.py 7

  24. Python and Cython 8

  25. Python and Cython 9

  26. Python and Cython 10

  27. Python and Cython • Cython is three orders of magnitude FASTER than Python! 10

  28. Python and Cython • Cython is three orders of magnitude FASTER than Python! • The Cython code is as fast as C code!! 10

  29. PyStokes: README.md • Cython library for computing Stokes flows produced by spheres • The library computes flow and RBM • Geometries supported • unbounded • wall-bounded • periodic • Free and open source • Planned developments • linear solvers • fast multipole accelerations • data layout • References • R. Singh, A. Laskar, and R. Adhikari. PyStokes: Hampi, Nov 2014. • S. Ghose and R. Adhikari. Phys. Rev. Lett., 112(11):118102, 2014. • R. Singh, S. Ghose and R. Adhikari. J. Stat. Mech, P06017, 2015 11

  30. PyStokes: Usage import pystokes , p y f o r c e s import numpy as np a , Np = 1 , 100 L , dim = 128 , 3 dt , T = 0.01 , 100 v = np . ze ros ( dim ∗ Np ) ; r = v ; F = v ; pRbm = pystokes . p e r i o d i c .Rbm(a , Np, L) f f = p y f o r c e s . f o r c e F i e l d s . Forces (Np) for t t in range (T) : f f . sedimentation (F , g= − 10) pRbm. s t o k e s l e t V ( v , r , F) r = ( r + (F/(0.75 ∗ a ) + v ) ∗ dt)%L 12

  31. PyStokes: Example Figure: Crowley instability in a sedimenting lattice. 13

  32. PyStokes: Benchmarks Figure: Propulsion matrix calculation using the PyStokes library Present implementation scales • linearly with # cores • quadratic with # particles 14

  33. Summary • Free and open source library • Efficient and fast evaluation of Stokes flow • A python front end for the user • Present implementation scales • linearly with # cores • quadratic with # particles 15

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend