The Julia Programming Language: a Fresh Approach to Technical Computing

The Julia Programming Language: a Fresh Approach to Technical Computing

Introduction Julia features Concluding remarks The Julia Programming Language: A fresh approach to technical computing Tim Schoof 1/20 Introduction Julia features Concluding remarks Sharelatex1 A I Online LTEX editor A I Complete modern LTEX environment =) no installation needed I Collaborative real-time editing =) no version conflicts I Eternal history =) Go back to any point in time I Bibliography search, comments, chat, github integration, and more 1 sharelatex.com 2/20 Introduction Julia features Concluding remarks Zotero2 I Organize your bibliography I Share downloaded papers with the group I Download pdf and meta-data with a single click I Full text search in meta-data and pdfs 2 https://www.zotero.org/ 3/20 Introduction Julia features Concluding remarks History I Work started 2009 at UC Santa Barbara and MIT (by Stefan Karpinski, Viral Shah, Jeff Bezanson, Alan Edelman) I First public release 2012 I Julia Computing founded in 2015 (by inventors + Deepak Vinchhi and Keno Fischer) I 2017 Julia Computing raises $4.6M in seed funding 4/20 Introduction Julia features Concluding remarks Example 1: Calculate π with Monte Carlo I Choose M random points within a square (uniformly distributed) I Count points within enclosed circle, e.g., N I It follows N A π(d=2)2 ≈ = M A d2 N =) π ≈ 4 M I In picture π ≈ 3:15 5/20 Introduction Julia features Concluding remarks Example 1: Calculate π in C++ 1 #include <random> #include <iostream> 3 std::mt19937_64 rng; 5 std::uniform_real_distribution<double> distUReal; 7 using namespace std; 9 double calc_pi(int M) { int sum = 0; 11 double x; double y; 13 for (int i = 0; i < M; ++i) { 15 x = distUReal(rng); y = distUReal(rng); 17 sum += x*x + y*y < 1; } 19 return 4.0 * sum / M; } 21 int main() 23 { int M = pow(10,9); 25 cout << calc_pi(M) << endl; } 6/20 Introduction Julia features Concluding remarks Example 1: Calculate π in C++ #include <random> 2 #include <iostream> 4 std::mt19937_64 rng; std::uniform_real_distribution<double> distUReal; 6 using namespace std; 8 double calc_pi(int M) { 10 int sum = 0; I characterdouble count:x; 432 12 double y; I run time:for 19(int s i = 0; i < M; ++i) 14 { x = distUReal(rng); 16 y = distUReal(rng); sum += x*x + y*y < 1; 18 } return 4.0 * sum / M; 20 } 22 int main() { 24 int M = pow(10,9); cout << calc_pi(M) << endl; 26 } 6/20 Introduction Julia features Concluding remarks Example 1: Calculate π in Python from random import random 2 def calc_pi(M): 4 return 4*sum(random()**2 + random()**2 < 1 for i in range(M)) / M 6 print(calc_pi(10**9)) Much shorter due to high level code: I no type declarations necessary I predefined functions: sum,… I range based for loops: for elem in <iterable> I generator expressions: (f(elem) for elem in <iterable>) 7/20 Introduction Julia features Concluding remarks Example 1: Calculate π in Python from random import random 2 def calc_pi(M): 4 return 4*sum(random()**2 + random()**2 < 1 for i in range(M)) / M 6 print(calc_pi(10**9)) I character count: 135 I run time: 280 s Much shorter due to high level code: I no type declarations necessary I predefined functions: sum,… I range based for loops: for elem in <iterable> I generator expressions: (f(elem) for elem in <iterable>) 7/20 Introduction Julia features Concluding remarks Example 1: Calculate π in Julia calc_pi(M) = 4*sum(rand()^2 + rand()^2 < 1 for i=1:M) / M 2 println(calc_pi(10^9)) Even shorter syntax: I many important functions imported by default I inline function definitions: f(x) = 2x I ranges: start:stop and start:step:stop 8/20 Introduction Julia features Concluding remarks Example 1: Calculate π in Julia calc_pi(M) = 4*sum(rand()^2 + rand()^2 < 1 for i=1:M) / M 2 println(calc_pi(10^9)) I character count: 83 EvenI run shorter time: 7 syntax: s I many important functions imported by default I inline function definitions: f(x) = 2x I ranges: start:stop and start:step:stop 8/20 Introduction Julia features Concluding remarks Example 2: Micro benchmarks 9/20 Introduction Julia features Concluding remarks Example 2: Micro benchmarks 10/20 Introduction Julia features Concluding remarks Example 3: Celeste project I Locate and characterize light sources in the universe I Sloan Digital Sky Survey I 178 TB image data I 188 million stars and galaxies I 1.54 PFLOPS peak performance I 9300 nodes I 1.3 million threads on 650,000 KNL cores I <15 min runtime I Julia first language since C/C++/Fortran reaching >1PFLOPS 11/20 I only inferable Julia code is fast I type-unstable code has Python like performance (or even slower due to missing optimizations) I see also performance tips in manual! (https://docs.julialang.org/en/latest/manual/performance-tips/) I Aggrassive specialization on argument types I Language design focused on speed I avoids hard to optimize language features e.g., dictionary semantics for objects and scopes I machine integers (overflow!) I driven by LLVM’s possibilities from the start I “Type-stable” standard library Introduction Julia features Concluding remarks How is that possible? I Just-In-Time (JIT) compilation to native machine code 12/20 4 julia> @time f(1) # first call with an Int 0.001466 seconds (244 allocations: 17.041 KiB) 6 2 julia> @time f(1) # second call with an Int 8 0.000003 seconds (4 allocations: 160 bytes) 2 10 julia> @time f(2) # Only the type matters, not the value 12 0.000003 seconds (4 allocations: 160 bytes) 4 14 julia> @time f(1.0) # First call with a Float64 16 0.004278 seconds (215 allocations: 13.104 KiB) 2.0 18 julia> @time f(1.0) 20 0.000003 seconds (5 allocations: 176 bytes) 2.0 22 julia> @time f(2.0) 24 0.000003 seconds (5 allocations: 176 bytes) 4.0 Introduction Julia features Concluding remarks Just-in-time (JIT) Compilation A new function is compiled on first use for each combination of argument types3: julia> f(x) = 2x 2 f (generic function with 1 method) 3 except for functions and types by default 13/20 11 julia> @time f(2) # Only the type matters, not the value 0.000003 seconds (4 allocations: 160 bytes) 13 4 15 julia> @time f(1.0) # First call with a Float64 0.004278 seconds (215 allocations: 13.104 KiB) 17 2.0 19 julia> @time f(1.0) 0.000003 seconds (5 allocations: 176 bytes) 21 2.0 23 julia> @time f(2.0) 0.000003 seconds (5 allocations: 176 bytes) 25 4.0 Introduction Julia features Concluding remarks Just-in-time (JIT) Compilation A new function is compiled on first use for each combination of argument types3: 1 julia> f(x) = 2x f (generic function with 1 method) 3 julia> @time f(1) # first call with an Int 5 0.001466 seconds (244 allocations: 17.041 KiB) 2 7 julia> @time f(1) # second call with an Int 0.000003 seconds (4 allocations: 160 bytes) 9 2 3 except for functions and types by default 13/20 15 julia> @time f(1.0) # First call with a Float64 0.004278 seconds (215 allocations: 13.104 KiB) 17 2.0 19 julia> @time f(1.0) 0.000003 seconds (5 allocations: 176 bytes) 21 2.0 23 julia> @time f(2.0) 0.000003 seconds (5 allocations: 176 bytes) 25 4.0 Introduction Julia features Concluding remarks Just-in-time (JIT) Compilation A new function is compiled on first use for each combination of argument types3: 1 julia> f(x) = 2x f (generic function with 1 method) 3 julia> @time f(1) # first call with an Int 5 0.001466 seconds (244 allocations: 17.041 KiB) 2 7 julia> @time f(1) # second call with an Int 0.000003 seconds (4 allocations: 160 bytes) 9 2 11 julia> @time f(2) # Only the type matters, not the value 0.000003 seconds (4 allocations: 160 bytes) 13 4 3 except for functions and types by default 13/20 Introduction Julia features Concluding remarks Just-in-time (JIT) Compilation A new function is compiled on first use for each combination of argument types3: 1 julia> f(x) = 2x f (generic function with 1 method) 3 julia> @time f(1) # first call with an Int 5 0.001466 seconds (244 allocations: 17.041 KiB) 2 7 julia> @time f(1) # second call with an Int 0.000003 seconds (4 allocations: 160 bytes) 9 2 11 julia> @time f(2) # Only the type matters, not the value 0.000003 seconds (4 allocations: 160 bytes) 13 4 15 julia> @time f(1.0) # First call with a Float64 0.004278 seconds (215 allocations: 13.104 KiB) 17 2.0 19 julia> @time f(1.0) 0.000003 seconds (5 allocations: 176 bytes) 21 2.0 23 julia> @time f(2.0) 0.000003 seconds (5 allocations: 176 bytes) 25 4.0 3 except for functions and types by default 13/20 Introduction Julia features Concluding remarks Machine code Julia compiles to native machine code very similar to C++ 1 julia> @code_native f(1) .text 3 Filename: REPL[1] pushq %rbp 5 movq %rsp, %rbp Source line: 1 7 leaq (%rdi,%rdi), %rax popq %rbp 9 retq nopw (%rax,%rax) 11 julia> @code_native f(1.0) 13 .text Filename: REPL[1] 15 pushq %rbp movq %rsp, %rbp 17 Source line: 1 vaddsd %xmm0, %xmm0, %xmm0 19 popq %rbp retq 21 nopw (%rax,%rax) 14/20 I only inferable Julia code is fast I type-unstable code has Python like performance (or even slower due to missing optimizations) I see also performance tips in manual! (https://docs.julialang.org/en/latest/manual/performance-tips/) I Language design focused on speed I avoids hard to optimize language features e.g., dictionary semantics for objects and scopes I machine integers (overflow!) I driven by LLVM’s possibilities from the start I “Type-stable” standard library Introduction Julia features Concluding remarks How is that possible? I Just-In-Time (JIT) compilation to native machine code I Aggrassive specialization on argument types 15/20 I only inferable Julia code is fast I type-unstable code has Python like performance (or even slower due to missing optimizations) I see also performance

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    55 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us