From: K.-Michael A. <kmi...@gm...> - 2012-06-06 22:46:55
|
Dear all, I was wondering if the good old VPython gas simulation that uses numpy so efficiently will run as nicely in Glowscript? Does Glowscript offer efficient arrays? Best regards, Michael |
From: Bruce S. <Bru...@nc...> - 2012-06-06 23:40:13
|
The quick answer to "numpy in GlowScript" is "no". GlowScript (glowscript.org) is necessarily written in JavaScript, and GlowScript user programs are necessarily written in JavaScript (or CoffeeScript, which compiles to JavaScript). JavaScript is slower than C++ but considerably faster than Python. To my knowledge, there is no possibility for something like numpy, which runs at the speed of C. However, here is the stars program in GlowScript, a program which is very similar to the gas program: http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Stars (You need to enable WebGL in your browser; see the Help at glowscript.org.) As you see, it runs adequately fast. However, if you examine the code, you'll see that David Scherer pulled some unintuitive tricks to get the speed to be adequate. In fairness, you might say that the use of numpy in the VPython demo programs stars.py and gas.py is also pretty unintuitive. Another speed issue to consider is that because GlowScript uses WebGL, which requires the use of modern GPU-type graphics cards, many kinds of graphics can be significantly faster than in VPython, which currently uses GPUs only optionally, for textures. I've been dreaming of a VPython+ that would also require the use of a modern graphics card. I just released GlowScript 1.0 which includes some major new capabilities. A particularly interesting example is a pulse running along a rug: http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Rug For another capability that goes beyond VPython, here is transparency done right: http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Transparency In VPython, transparent objects are sorted by their pos attribute, with the result that intersecting transparent objects cannot be displayed correctly. I implemented "depth peeling" in GlowScript which uses the GPUs to do pixel-level sorting. Here are the details: http://www.khronos.org/message_boards/viewtopic.php?f=44&t=4905 Bruce Sherwood On Wed, Jun 6, 2012 at 4:46 PM, K.-Michael Aye <kmi...@gm...> wrote: > Dear all, > > I was wondering if the good old VPython gas simulation that uses numpy > so efficiently will run as nicely in Glowscript? Does Glowscript offer > efficient arrays? > > Best regards, > Michael |
From: Bruce S. <Bru...@nc...> - 2012-06-07 05:02:34
|
I should add for completeness that JavaScript does offer typed arrays such as Float32Array, in which all elements are 32-bit floats. A major use of these typed arrays is for communication between CPU and GPUs on the graphics card. Bruce Sherwood > On Wed, Jun 6, 2012 at 4:46 PM, K.-Michael Aye <kmi...@gm...> wrote: >> Dear all, >> >> I was wondering if the good old VPython gas simulation that uses numpy >> so efficiently will run as nicely in Glowscript? Does Glowscript offer >> efficient arrays? >> >> Best regards, >> Michael |
From: Bruce S. <Bru...@nc...> - 2012-06-08 04:47:43
|
I've now converted the VPython demo program gas.py to GlowScript: http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/HardSphereGas To run the program, you need to have a WebGL-enabled browser and a modern graphics card. For details, see the Help at glowscript.org. As for speed, this is what I found: VPython gas.py with 100 atoms, dt = 1e-5, no graphing: 100 iterations = 1.1 seconds. This similar Glowsript program with same conditions: 100 iterations = 11.7 seconds. Presumably the big difference is the Python numpy library, which runs at C speed, and which eliminates some explicit loops. Bruce Sherwood |
From: Bruce S. <Bru...@nc...> - 2012-06-08 23:15:09
|
Correction: I made my measurements with Chrome on a 64-bit Windows machine, unaware that Chrome runs slowly on 64-bit machines because it is a 32-bit application. Here are improved measurements, copied from comments in the GlowScript program: On a 32-bit Windows computer running Chrome: VPython gas.py with 100 atoms, dt = 1e-5, rate(100), no graphing: 100 iterations = 1 second. The similar Glowsript program with same conditions: 100 iterations = 4.5 seconds. /With rate(300), VPython is 0.35 s, GlowScript remains 4.5 s. Presumably the big difference is the Python numpy library, which runs at C speed, and which eliminates some explicit loops. Note that on a 64-bit Windows computer Chrome runs this program half as fast as on a 32-bit computer, because Chrome is a 32-bit application. On 64-bit Windows Firefox is a 64-bit application and runs the program twice as fast as Chrome. Bruce Sherwood On Thu, Jun 7, 2012 at 10:47 PM, Bruce Sherwood <Bru...@nc...> wrote: > I've now converted the VPython demo program gas.py to GlowScript: > > http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/HardSphereGas > > To run the program, you need to have a WebGL-enabled browser and a > modern graphics card. For details, see the Help at glowscript.org. > > As for speed, this is what I found: > > VPython gas.py with 100 atoms, dt = 1e-5, no graphing: 100 iterations > = 1.1 seconds. This similar Glowsript program with same conditions: > 100 iterations = 11.7 seconds. Presumably the big difference is the > Python numpy library, which runs at C speed, and which eliminates some > explicit loops. > > Bruce Sherwood |
From: Bruce S. <Bru...@nc...> - 2012-06-09 02:36:48
|
I was wrong. Firefox on my Windows 7 machine is also a 32-bit application, but it runs the gas program about twice as fast as Chrome. I also see the higher speed in Safari on a Macbook Pro of comparable speed. Bruce Sherwood On Fri, Jun 8, 2012 at 3:49 PM, Bruce Sherwood <Bru...@nc...> wrote: > Correction: I made my measurements with Chrome on a 64-bit Windows > machine, unaware that Chrome runs slowly on 64-bit machines because it > is a 32-bit application. Here are improved measurements, copied from > comments in the GlowScript program: > > On a 32-bit Windows computer running Chrome: VPython gas.py with 100 > atoms, dt = 1e-5, rate(100), no graphing: 100 iterations = 1 second. > > The similar Glowsript program with same conditions: 100 iterations = > 4.5 seconds. > > /With rate(300), VPython is 0.35 s, GlowScript remains 4.5 s. > > Presumably the big difference is the Python numpy library, which runs > at C speed, and which eliminates some explicit loops. > > Note that on a 64-bit Windows computer Chrome runs this program half > as fast as on a 32-bit computer, because Chrome is a 32-bit > application. On 64-bit Windows Firefox is a 64-bit application and > runs the program twice as fast as Chrome. > > Bruce Sherwood > > On Thu, Jun 7, 2012 at 10:47 PM, Bruce Sherwood <Bru...@nc...> wrote: >> I've now converted the VPython demo program gas.py to GlowScript: >> >> http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/HardSphereGas >> >> To run the program, you need to have a WebGL-enabled browser and a >> modern graphics card. For details, see the Help at glowscript.org. >> >> As for speed, this is what I found: >> >> VPython gas.py with 100 atoms, dt = 1e-5, no graphing: 100 iterations >> = 1.1 seconds. This similar Glowsript program with same conditions: >> 100 iterations = 11.7 seconds. Presumably the big difference is the >> Python numpy library, which runs at C speed, and which eliminates some >> explicit loops. >> >> Bruce Sherwood |
From: Bruce S. <Bru...@nc...> - 2012-06-11 03:59:37
|
After more study of GlowScript vs. VPython versions of the VPython gas.py program: VPython gas.py with 100 atoms, dt = 1e-5, rate 500, no graphing: 100 iterations = 0.4 seconds. If gas.py is modified to not use numpy, the time is 3.6 s. The similar Glowsript program with same conditions: 100 iterations = 3.2 seconds on Firefox. Oddly, on at least one 64-bit Windows machine, the time is 5.3 seconds on Chrome. On a 32-bit Windows laptop, 4.2 seconds on Firefox, 2.5 seconds on Chrome, the reverse of the ordering on the other Windows machine. There is a very major difference between Chrome and Firefox. With Firefox, the animation periodically freezes, probably due to JavaScript garbage collection. These freeze-ups do not occur with Chrome or Safari. ----------------------- You can run this program (if you have a WebGL-enabled browser; see the Help at glowscript.org) at http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/HardSphereGas A summary statement is that the factor of 10 speed advantage of VPython over GlowScript comes completely from the parallel C-speed numpy arrays. Without numpy, the VPython and GlowScript (Python and JavaScript) execution speeds are about the same. I had mistakenly thought that JavaScript was much faster than Python, but that seems not to be the case. Bruce Sherwood |
From: Bruce S. <Bru...@nc...> - 2012-06-12 05:34:35
|
The plot thickens. David Scherer rewrote a small piece of the GlowScript gas example, and the time on both Chrome and Firefox dropped to 1 second, not so different from the 0.4 second seen with the numpy version. (The change has to do with disabling vector overloading in the GlowScript handling of JavaScript.) Bruce Sherwood On Sun, Jun 10, 2012 at 9:59 PM, Bruce Sherwood <Bru...@nc...> wrote: > After more study of GlowScript vs. VPython versions of the VPython > gas.py program: > > VPython gas.py with 100 atoms, dt = 1e-5, rate 500, no graphing: 100 > iterations = 0.4 seconds. > > If gas.py is modified to not use numpy, the time is 3.6 s. > > The similar Glowsript program with same conditions: 100 iterations = > 3.2 seconds on Firefox. > > Oddly, on at least one 64-bit Windows machine, the time is 5.3 seconds > on Chrome. > > On a 32-bit Windows laptop, 4.2 seconds on Firefox, 2.5 seconds on > Chrome, the reverse of the ordering on the other Windows machine. > > There is a very major difference between Chrome and Firefox. With > Firefox, the animation periodically freezes, probably due to > JavaScript garbage collection. These freeze-ups do not occur with > Chrome or Safari. > > ----------------------- > > You can run this program (if you have a WebGL-enabled browser; see the > Help at glowscript.org) at > > http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/HardSphereGas > > A summary statement is that the factor of 10 speed advantage of > VPython over GlowScript comes completely from the parallel C-speed > numpy arrays. Without numpy, the VPython and GlowScript (Python and > JavaScript) execution speeds are about the same. I had mistakenly > thought that JavaScript was much faster than Python, but that seems > not to be the case. > > Bruce Sherwood |