@@ -285,80 +285,6 @@ speed by using Pathos rather than GNU Parallel—see this
285
285
aftenroon's session.
286
286
287
287
288
- ## Using ` pycallgraph ` to see a flowchart of function calls
289
-
290
- SnakeViz gives a very useful graphical representation of how different
291
- functions' execution times relate to each other. In many cases it can
292
- also show which functions call which, but in more complex cases this
293
- becomes unclear. ` pycallgraph ` gives an alternative view of this; it
294
- doesn't use ` cProfile ` , but instead runs the program itself and
295
- records which functions call which, and how long they take. A
296
- disadvantage of this over ` cProfile ` is that as it is written in pure
297
- Python, it adds significant overhead to the program's run time.
298
-
299
- To get started with ` pycallgraph ` we will need to install it into our
300
- conda environment on the cluster. In addition, we also need to install
301
- Graphviz, a piece of software for rendering graphs which ` pycallgraph `
302
- depends on.
303
-
304
- ~~~
305
- $ pip install pycallgraph
306
- $ conda install graphviz
307
- ~~~
308
- {: .language-bash}
309
-
310
- With that out of the way, we can re-run the Monte Carlo example, now
311
- using ` pycallgraph ` . Similarly to ` cProfile ` , there is an initial part
312
- telling ` pycallgraph ` what to do, followed by the Python program to
313
- run and any arguments.
314
-
315
- ~~~
316
- $ pycallgraph graphviz -- ./mc.py 0 1 0.1 1000000 test.dat
317
- ~~~
318
- {: .language-bash}
319
-
320
- Once this completes, it will create a file called ` pycallgraph.png ` in
321
- the current working directory. You can copy this to your machine to
322
- view using FileZilla, or with the command
323
-
324
- ~~~
325
- $ # This runs on your computer, not on the supercomputer
326
- $ scp s.your.username@sunbird.swansea.ac.uk:high-performance-python-examples/pycallgraph.png ~/Desktop/
327
- ~~~
328
- {: .language-bash}
329
-
330
- Open this image in your favourite image viewer, and you can get a look
331
- at how the function calls in the program relate to each
332
- other. Functions that are part of Python are in grey, while functions
333
- that are part of your program are in more interesting colours.
334
-
335
- > ## Displaying graphics from the cluster
336
- >
337
- > If you have a piece of software called an "X Server" installed on
338
- > your machine, you can display graphics from the cluster without
339
- > having to copy image files back. GNU/Linux's graphics are based on
340
- > X, so if you are running GNU/Linux then you won't need to install
341
- > anything. On Mac, [ XQuartz] ( https://www.xquartz.org ) will do this
342
- > job, while on Windows,
343
- > [ VcXsrv] ( https://sourceforge.net/projects/vcxsrv/ ) is available.
344
- >
345
- > Once this is installed, you can add the ` -X ` flag to your ` ssh `
346
- > command when connecting to the cluster, and graphical applications
347
- > running on the cluster will appear on your machine. For example, to
348
- > display the output of ` pycallgraph ` , you can run
349
- >
350
- > ~~~
351
- > display pycallgraph.png
352
- > ~~~
353
- > {:.language-bash}
354
- {: .callout}
355
-
356
- The main result we can see from this program is that `pycallgraph` has
357
- increased the run time by an order of magnitude compared to
358
- `cProfile`; this program isn't complicated enough to benefit from this
359
- detailed view of the call graph.
360
-
361
-
362
288
## Using ` timeit ` for quick and dirty timings
363
289
364
290
Sometimes you don't need a full profile; all you're interested in is
0 commit comments