Your SlideShare is downloading. ×
Introduction to julia language
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Introduction to julia language

808
views

Published on

Slides for Journal Club in SYSU

Slides for Journal Club in SYSU

Published in: Education, Technology

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
808
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
26
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

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 The blog of Douglas Bates http://dmbates.blogspot.com/2012/04/r-programmer-looks-at-julia.html Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 3 / 33
  • 4. Overview The Homepage http://julialang.org/ Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 4 / 33
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. Features Cloud Computing Cloud Computing http://julia.forio.com/ Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 16 / 33
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. 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
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. Installation and Usage Installation and Usage Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 23 / 33
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. 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
  • 42. 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
  • 43. 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
  • 44. 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
  • 45. 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
  • 46. 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
  • 47. Other Projects PyCUDA http://documen.tician.de/pycuda/ Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 31 / 33
  • 48. 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
  • 49. Thanks Thanks Thank you for your time! Kou Qiang (Sun Yat-sen University) Introduction to Julia Language December 6, 2012 33 / 33