A blog about writing efficient codes for numerical computation

297 views
Skip to first unread message

Dahua

unread,
Jul 6, 2013, 9:29:52 AM7/6/13
to juli...@googlegroups.com
I am considering a blog post about writing fast codes to do numerical computation in Julia.

The structure is to first establish basic guidelines and then provide some examples to demonstrate how to implement them in practice.

Tentative list of guidelines:

Basics:
  • de-vectorization
  • cache friendliness (locality of computation)
  • pre-allocation (avoid allocating arrays within loop body)
  • pre-computation (compute values to be used repeatedly)
  • merge computation in a loop
Advanced:
  • identify opportunities to use BLAS
  • explore equivalent formulas (through algebraic transformation) that can be computed more efficiently
  • avoid overflow or underflow (e.g. use log-scale in probability-related computation)
Any thoughts?

Milktrader

unread,
Jul 6, 2013, 7:29:13 PM7/6/13
to juli...@googlegroups.com
+1

Viral Shah

unread,
Jul 6, 2013, 9:16:41 PM7/6/13
to juli...@googlegroups.com
Please do!

-viral

Miles Lubin

unread,
Jul 6, 2013, 9:23:18 PM7/6/13
to juli...@googlegroups.com
This sounds great!


On Saturday, July 6, 2013 9:29:52 AM UTC-4, Dahua wrote:

Ben Ward

unread,
Jul 6, 2013, 11:43:07 PM7/6/13
to juli...@googlegroups.com
This would be great for someone like me - who needs to do computation but like many people in life-sciences may have only done a module or two or in my case is self taught. The result is I know how to solve problems I come across, but not necessarily in the most efficient or intelligently written way.

Glen Hertz

unread,
Jul 7, 2013, 12:19:10 AM7/7/13
to juli...@googlegroups.com
+1  ...and all without touching Fortran or C!

I really like your code for summing the rows of a matrix so it is cache friendly.  It is easy to understand and 5x faster.


On Saturday, July 6, 2013 9:29:52 AM UTC-4, Dahua wrote:
Message has been deleted

Jonne Guyt

unread,
Jul 7, 2013, 4:33:23 AM7/7/13
to juli...@googlegroups.com
This would be really helpful. I have translated my multinomial (and mixed logit) into Julia (from Matlab) but haven't seen the speed-ups I was expecting / hoping for.

Stefan Karpinski

unread,
Jul 7, 2013, 10:36:16 AM7/7/13
to Julia Dev
This will be tremendous, Dahua. Interestingly, a lot of this stuff is not actually that Julia-specific, but is what "the pros" do in C/Fortran. In most high-level languages, the *only* chance of writing fast code is to vectorize as much as possible and then rely on someone else already having done this work for the code that implements vectorized operations. The unusual combination here that in Julia you're writing high-level code yet it makes sense to apply low-level optimization approaches.

Dahua

unread,
Jul 7, 2013, 2:11:46 PM7/7/13
to juli...@googlegroups.com
Great point, Stefan. This is one of the reasons why I love Julia.

John Myles White

unread,
Jul 7, 2013, 5:19:41 PM7/7/13
to juli...@googlegroups.com
It would be nice to have an example of where things are slow. The multinomial sampler code still needs improvement.

-- John

John Myles White

unread,
Jul 7, 2013, 5:33:25 PM7/7/13
to juli...@googlegroups.com
This sounds great, Dahua. One guideline I hope you'll suggest is to always define an in-place version of a function as the core case for vector-input functions, then define a pure function that combines memory allocation with in-place computation in terms of the mutating base-case.

 -- John

Glen Hertz

unread,
Jul 8, 2013, 12:20:45 AM7/8/13
to juli...@googlegroups.com
Hi,

By the way, I wish we had names for mutating operators (eg +!, .*!, etc).  Are there standard function names for the mutating versions of the non-mutating operators (eg add! is a mutating +, etc)? 

Glen

Viral Shah

unread,
Jul 8, 2013, 10:12:02 AM7/8/13
to juli...@googlegroups.com
Along with the blog entry, I think that it is also worth capturing this in the Performance Tips section of the manual.


-viral
Reply all
Reply to author
Forward
0 new messages