Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Julia Language

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for thirdwing thirdwing
December 06, 2012

Introduction to Julia Language

Avatar for thirdwing

thirdwing

December 06, 2012

Other Decks in Technology

Transcript

  1. Introduction to Julia Language Kou Qiang Sun Yat-sen University December

    6, 2012 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 1 / 33
  2. Outline Outline 1 Overview 2 Features Performance Parallelism Cloud Computing

    3 LLVM and Clang 4 Comparison between R and Julia Advantages and Disadvantages The State of Statistics in Julia 5 Installation and Usage 6 An Example 7 Other Projects Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 2 / 33
  3. Overview Syntax function mandel(z) c = z maxiter = 80

    for n = 1: maxiter if abs(z) > 2 return n-1 end z = z^2 + c end return maxiter end Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 5 / 33
  4. Features Performance Features 1 Overview 2 Features Performance Parallelism Cloud

    Computing 3 LLVM and Clang 4 Comparison between R and Julia Advantages and Disadvantages The State of Statistics in Julia 5 Installation and Usage 6 An Example 7 Other Projects Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 6 / 33
  5. Features Performance Performance benchmark times relative to C++ (smaller is

    better) Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 7 / 33
  6. Features Performance R > fun1r = function () { +

    m = matrix (0, 1000 , 1000) + s = 0 + for(i in 1:1000) + { + for(j in 1:1000) + { + m[i, j] = runif (1) + s = s + m[i, j] + } + } + } > system.time(fun1r ()) user system elapsed 8.113 0.006 8.120 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 8 / 33
  7. Features Performance Julia julia > function fun1j () m =

    zeros (1000 , 1000) s = 0 for i = 1:1000 for j = 1:1000 m[i, j] = rand () s = s + m[i, j] end end end julia > @elapsed fun1j () 0.22739791870117188 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 9 / 33
  8. Features Performance R > fun1optr = function () { +

    m = matrix(runif (1000 * 1000) , 1000 , 1000) + sum(m) + } > system.time(fun1optr ()) user system elapsed 0.132 0.003 0.136 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 10 / 33
  9. Features Performance Julia julia > function fun1optj () m =

    rand (1000 , 1000) sum(m) end julia > @elapsed fun1optj () 0.010874032974243164 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 11 / 33
  10. Features Performance Julia julia > 1//2 1//2 julia > 11//22

    1//2 julia > 987//654 + 12//34 * 56//78 84917//48178 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 12 / 33
  11. Features Parallelism Features 1 Overview 2 Features Performance Parallelism Cloud

    Computing 3 LLVM and Clang 4 Comparison between R and Julia Advantages and Disadvantages The State of Statistics in Julia 5 Installation and Usage 6 An Example 7 Other Projects Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 13 / 33
  12. Features Parallelism Parallelism $ ./ julia -p 2 M =

    {rand (1000 ,1000) | i=1:10} pmap(svd , M) nheads = @parallel (+) for i=1:100000000 randbit () end Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 14 / 33
  13. Features Cloud Computing Features 1 Overview 2 Features Performance Parallelism

    Cloud Computing 3 LLVM and Clang 4 Comparison between R and Julia Advantages and Disadvantages The State of Statistics in Julia 5 Installation and Usage 6 An Example 7 Other Projects Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 15 / 33
  14. Features Cloud Computing Cloud Computing http://julia.forio.com/ Kou Qiang (Sun Yat-sen

    University) Introduction to Julia Language December 6, 2012 16 / 33
  15. LLVM and Clang LLVM and Clang LLVM: Low Level Virtual

    Machine Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 17 / 33
  16. LLVM and Clang LLVM and Clang LLVM: Low Level Virtual

    Machine Clang: an “LLVM native” C/C++/Objective-C compiler Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 17 / 33
  17. LLVM and Clang LLVM and Clang LLVM: Low Level Virtual

    Machine Clang: an “LLVM native” C/C++/Objective-C compiler JIT compilation: Just-in-time compilation Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 17 / 33
  18. Comparison between R and Julia Advantages and Disadvantages Comparison between

    R and Julia 1 Overview 2 Features Performance Parallelism Cloud Computing 3 LLVM and Clang 4 Comparison between R and Julia Advantages and Disadvantages The State of Statistics in Julia 5 Installation and Usage 6 An Example 7 Other Projects Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 18 / 33
  19. Comparison between R and Julia Advantages and Disadvantages Advantages A

    JIT Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 19 / 33
  20. Comparison between R and Julia Advantages and Disadvantages Advantages A

    JIT A richer type system Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 19 / 33
  21. Comparison between R and Julia Advantages and Disadvantages Advantages A

    JIT A richer type system Multiple dispatch Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 19 / 33
  22. Comparison between R and Julia Advantages and Disadvantages Advantages A

    JIT A richer type system Multiple dispatch Parallelism Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 19 / 33
  23. Comparison between R and Julia Advantages and Disadvantages Advantages A

    JIT A richer type system Multiple dispatch Parallelism A cleaner model for accessing libraries of compiled code Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 19 / 33
  24. Comparison between R and Julia Advantages and Disadvantages Advantages A

    JIT A richer type system Multiple dispatch Parallelism A cleaner model for accessing libraries of compiled code Memory-mapped I/O Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 19 / 33
  25. Comparison between R and Julia Advantages and Disadvantages Disadvantages Default

    arguments of functions and named actual arguments in function calls Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 20 / 33
  26. Comparison between R and Julia Advantages and Disadvantages Disadvantages Default

    arguments of functions and named actual arguments in function calls The R package system and CRAN Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 20 / 33
  27. Comparison between R and Julia Advantages and Disadvantages Disadvantages Default

    arguments of functions and named actual arguments in function calls The R package system and CRAN Graphics Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 20 / 33
  28. Comparison between R and Julia The State of Statistics in

    Julia Comparison between R and Julia 1 Overview 2 Features Performance Parallelism Cloud Computing 3 LLVM and Clang 4 Comparison between R and Julia Advantages and Disadvantages The State of Statistics in Julia 5 Installation and Usage 6 An Example 7 Other Projects Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 21 / 33
  29. Comparison between R and Julia The State of Statistics in

    Julia The State of Statistics in Julia DataFrames Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 22 / 33
  30. Comparison between R and Julia The State of Statistics in

    Julia The State of Statistics in Julia DataFrames Distributions Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 22 / 33
  31. Comparison between R and Julia The State of Statistics in

    Julia The State of Statistics in Julia DataFrames Distributions Optim Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 22 / 33
  32. Comparison between R and Julia The State of Statistics in

    Julia The State of Statistics in Julia DataFrames Distributions Optim MCMC Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 22 / 33
  33. Comparison between R and Julia The State of Statistics in

    Julia The State of Statistics in Julia DataFrames Distributions Optim MCMC NHST: null hypothesis significance testing Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 22 / 33
  34. Comparison between R and Julia The State of Statistics in

    Julia The State of Statistics in Julia DataFrames Distributions Optim MCMC NHST: null hypothesis significance testing Clustering: k-means clustering Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 22 / 33
  35. Installation and Usage Installation and Usage Kou Qiang (Sun Yat-sen

    University) Introduction to Julia Language December 6, 2012 23 / 33
  36. An Example Rosenbrock Function Optimization f (x, y) = (1

    − x)2 + 100(y − x2)2 A global minimum at (x, y) = (1, 1) where f (x, y) = 0 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 24 / 33
  37. An Example Rosenbrock Function Optimization load (" src/Optim.jl") using Optim

    function rosenbrock (x:: Vector) (1.0 -x[1]) ^2+100.0*( x[2]-x[1]^2) ^2 end function rosenbrock_gradient (x:: Vector) [ -2.0*(1.0 -x[1]) -400.0*(x[2]-x[1]^2)*x[1] ,200.0*(x[2]-x[1]^2)] end function rosenbrock_hessian (x:: Vector) h = zeros (2, 2) h[1 ,1]=2.0 -400.0*x [2]+1200.0* x[1]^2 h[1 ,2]= -400.0*x[1] h[2 ,1]= -400.0*x[1] h[2 ,2]=200.0 h end Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 25 / 33
  38. An Example Rosenbrock Function Optimization problem = Dict () problem

    [:f] = rosenbrock problem [:g] = rosenbrock_gradient problem [:h] = rosenbrock_hessian problem [: initial_x] = [0.0 , 0.0] problem [: solution] = [1.0 , 1.0] algorithms = [" naive_gradient_descent ", " gradient_descent ", "newton", "bfgs", "l-bfgs", "nelder -mead", "sa"] Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 26 / 33
  39. An Example Rosenbrock Function Optimization for algorithm = algorithms results

    = optimize(problem [:f], problem [:g], problem [:h], problem [: initial_x], algorithm , 10e-8, true) print(results) end Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 27 / 33
  40. Other Projects GraphChi: Disk-based large-scale graph computation “Big Data -

    small machine” Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 28 / 33
  41. Other Projects GraphChi: Disk-based large-scale graph computation “Big Data -

    small machine” Implemented in plain C++ and open-source Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 28 / 33
  42. Other Projects GraphChi: Disk-based large-scale graph computation “Big Data -

    small machine” Implemented in plain C++ and open-source Support: ALS, SGD, bias-SGD, SVD, NMF, SVD++ Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 28 / 33
  43. Other Projects GraphChi: Disk-based large-scale graph computation A Mac Mini

    with 8 GB of RAM and 256 GB SSD drive http://code.google.com/p/graphchi/ Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 29 / 33
  44. Other Projects CUDA Device FLOPS Price(RMB) Intel Core i7-980 XE

    107.6G 2500∼3500 nVIDIA Geforce GTX 690 about 6T 6500∼8000 nVIDIA Geforce GT 430 91.564G 250∼450 nVIDIA Tesla C2050 1.03T 6000∼8500 Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 30 / 33
  45. Other Projects PyCUDA import pycuda.autoinit import pycuda.driver as drv import

    numpy from pycuda.compiler import SourceModule mod = SourceModule (""" __global__ void multiply_them ( float *dest , float *a, float *b) { const int i = threadIdx .x; dest[i] = a[i] * b[i]; } """) multiply_them = mod. get_function (" multiply_them ") a = numpy.random.randn (400).astype(numpy.float32) b = numpy.random.randn (400).astype(numpy.float32) dest = numpy. zeros_like (a) multiply_them ( drv.Out(dest), drv.In(a), drv.In(b), block =(400 ,1 ,1) , grid =(1 ,1)) print dest -a*b Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 32 / 33
  46. Thanks Thanks Thank you for your time! Kou Qiang (Sun

    Yat-sen University) Introduction to Julia Language December 6, 2012 33 / 33