Making Python computations fast

  • Published on

  • View

  • Download


<ul><li><p>Copyright 2015 Russel Winder 1</p><p>Making Python computations fast</p><p>Dr Russel Winder</p><p>email: @russel_winder</p><p>Web:</p><p></p></li><li><p>Copyright 2015 Russel Winder 2</p><p>Presentation slots arevery short</p></li><li><p>Copyright 2015 Russel Winder 3</p><p>Structure</p><p>BeginningMiddleEnd</p></li><li><p>Copyright 2015 Russel Winder 4</p><p>What is the value of ? </p></li><li><p>Copyright 2015 Russel Winder 5</p></li><li><p>Copyright 2015 Russel Winder 6</p><p>It's simples. 2009</p></li><li><p>Copyright 20072015 Russel Winder 7</p><p>The Maths</p><p>The equation:</p><p>Leads to the approximation formula: </p><p>i=0n 4</p><p>(1+xi2) x</p><p>01 4(1+x2)</p><p>dx= </p></li><li><p>Copyright 20072015 Russel Winder 8</p><p>The ConceptionCalculate an approximation to the area undera conic section by filling the area with a knownnumber of rectangles of known size and thensum the areas of the rectangles. </p><p>The narrower the rectangles, the more accurate the approximation.</p><p>This is a data parallel problem andembarrassingly parallel.</p></li><li><p>Copyright 20072015 Russel Winder 9</p><p>The Parallelism Addition is commutative and associative so we can partition the overall summation in any way we want:</p><p>a + b + c + d + e + f</p><p>( a + b ) + ( c + d ) + ( e + f )</p><p>Can partition the overall sum into bits tobe done on different processors.This should make things faster.</p></li><li><p>Copyright 20072015 Russel Winder 10</p><p>Adding the Parallelism Instead of doing all the calculations sequentially, partition the problem into a number of chunks.</p><p>problem</p><p>subproblem</p><p>result</p><p>subproblem</p><p>subproblem</p><p>subproblem</p><p>.</p><p>.</p><p>.</p><p>scatter gather</p><p>fork join</p><p>reduce</p><p>Data parallel</p><p>map</p></li><li><p>Copyright 20072015 Russel Winder 11</p><p>Some Code Sequential. Use threads to obtain parallelismnot. Use process to obtain parallelism.</p><p>Friends don't let friends use Python 2 instead of Python 3.</p></li><li><p>Copyright 20072015 Russel Winder 12</p><p>It is all just too slow.</p></li><li><p>Copyright 20072015 Russel Winder 13</p><p>More Code Use Cython. Use Numba.</p><p>cf. lightning talk at PyConUK 2014.</p></li><li><p>Copyright 20072015 Russel Winder 14</p><p>A lot faster but iscontrolling parallelism inPython the thing to do</p></li><li><p>Copyright 20072015 Russel Winder 15</p><p>Even More Code Use NumPy. Use C. Use C++/Boost. Use D/PyD. Use Chapel/PyChapel.</p><p>Offload the whole computation,Leaving Python code as thecoordination code.</p><p></p><p></p><p></p><p></p><p></p></li><li><p>Copyright 20072015 Russel Winder 16</p><p>Parallelism and computationis not Python's forte.</p><p>(Even though Python is a great language.)</p></li><li><p>Copyright 20072015 Russel Winder 17</p><p>So do not do it.</p></li><li><p>Copyright 20072015 Russel Winder 18</p><p>NUMA</p><p>PGAS</p></li><li><p>Copyright 20072015 Russel Winder 19</p><p>Employ a multilingual,polyglot programming mentality.</p></li><li><p>Copyright 2015 Russel Winder 20</p><p>Making Python computations fast</p><p>Dr Russel Winder</p><p>email: @russel_winder</p><p>Web:</p><p></p></li><li><p>Copyright 2015 Russel Winder 21</p><p>John, you were a truly Pythonic hero,I miss your physical presence here.</p><p>Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21</p></li></ul>