23
1 Introduction Use-cases Demo Benchmarks! Conclusion Lua For Science! ...you monster Leo Antunes HPAC January 2014 Leo Antunes Lua

Lua For Science! ...you monster

Embed Size (px)

Citation preview

Page 1: Lua For Science! ...you monster

1

IntroductionUse-cases

DemoBenchmarks!Conclusion

LuaFor Science!

...you monster

Leo Antunes

HPAC

January 2014

Leo Antunes Lua

Page 2: Lua For Science! ...you monster

2

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

What is Lua?

I Interpreted language

I ”Teenage”: developed in the early 90s in Brasil (yay!)

I Reference implementation interpreted; also JITed, LLVM

I How many Python users out there?

Leo Antunes Lua

Page 3: Lua For Science! ...you monster

3

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

The Language

I Dynamically typedI Imperative, but multi-paradigm(ish):

I Functional: currying, higher-order functions(however: side-effects!)

I Object-oriented: some syntactic sugar, but mostly bare-bones(everything can be made into an object)

I Implemented in pure ANSI C (extremely portable)I Types:

I Usual: numbers, strings, bools, functions and nil

I Higher-level: tables, tables and - did I mention - tables?I Object orientation through tables: metatables (cf. Python)

I Nothing very new, so we’ll focus on API

Leo Antunes Lua

Page 4: Lua For Science! ...you monster

4

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

The Language

I Dynamically typedI Imperative, but multi-paradigm(ish):

I Functional: currying, higher-order functions(however: side-effects!)

I Object-oriented: some syntactic sugar, but mostly bare-bones(everything can be made into an object)

I Implemented in pure ANSI C (extremely portable)I Types:

I Usual: numbers, strings, bools, functions and nilI Higher-level: tables, tables and - did I mention - tables?

I Object orientation through tables: metatables (cf. Python)

I Nothing very new, so we’ll focus on API

Leo Antunes Lua

Page 5: Lua For Science! ...you monster

5

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

The Language

I Dynamically typedI Imperative, but multi-paradigm(ish):

I Functional: currying, higher-order functions(however: side-effects!)

I Object-oriented: some syntactic sugar, but mostly bare-bones(everything can be made into an object)

I Implemented in pure ANSI C (extremely portable)I Types:

I Usual: numbers, strings, bools, functions and nilI Higher-level: tables, tables and - did I mention - tables?I Object orientation through tables: metatables (cf. Python)

I Nothing very new, so we’ll focus on API

Leo Antunes Lua

Page 6: Lua For Science! ...you monster

6

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

A Bit of Syntax (not our focus, but...)

-- some examples

function factorial(n)

local x = 1

for i = 2,n do

x = x * i

end

return x

end

some_table = {

name="whatever",

func=factorial

}

some_table.func(3) --> 6

I No () for single argument(allows currying like Haskel’s)

I Can return multiple results(no packing/unpacking)

I Table indices start at 1(convention; no actual arrays)

I Scoping: globals per default(cf. Python; real closures)

I No named arguments(but can pass table)

Leo Antunes Lua

Page 7: Lua For Science! ...you monster

7

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

A Bit of Syntax (not our focus, but...)

-- some examples

function factorial(n)

local x = 1

for i = 2,n do

x = x * i

end

return x

end

some_table = {

name="whatever",

func=factorial

}

some_table.func(3) --> 6

I No () for single argument(allows currying like Haskel’s)

I Can return multiple results(no packing/unpacking)

I Table indices start at 1(convention; no actual arrays)

I Scoping: globals per default(cf. Python; real closures)

I No named arguments(but can pass table)

Leo Antunes Lua

Page 8: Lua For Science! ...you monster

8

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

A Bit of Syntax (not our focus, but...)

-- some examples

function factorial(n)

local x = 1

for i = 2,n do

x = x * i

end

return x

end

some_table = {

name="whatever",

func=factorial

}

some_table.func(3) --> 6

I No () for single argument(allows currying like Haskel’s)

I Can return multiple results(no packing/unpacking)

I Table indices start at 1(convention; no actual arrays)

I Scoping: globals per default(cf. Python; real closures)

I No named arguments(but can pass table)

Leo Antunes Lua

Page 9: Lua For Science! ...you monster

9

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

A Bit of Syntax (not our focus, but...)

-- some examples

function factorial(n)

local x = 1

for i = 2,n do

x = x * i

end

return x

end

some_table = {

name="whatever",

func=factorial

}

some_table.func(3) --> 6

I No () for single argument(allows currying like Haskel’s)

I Can return multiple results(no packing/unpacking)

I Table indices start at 1(convention; no actual arrays)

I Scoping: globals per default(cf. Python; real closures)

I No named arguments(but can pass table)

Leo Antunes Lua

Page 10: Lua For Science! ...you monster

10

IntroductionUse-cases

DemoBenchmarks!Conclusion

What is Lua?The LanguageA Bit of Syntax

A Bit of Syntax (not our focus, but...)

-- some examples

function factorial(n)

local x = 1

for i = 2,n do

x = x * i

end

return x

end

some_table = {

name="whatever",

func=factorial

}

some_table.func(3) --> 6

I No () for single argument(allows currying like Haskel’s)

I Can return multiple results(no packing/unpacking)

I Table indices start at 1(convention; no actual arrays)

I Scoping: globals per default(cf. Python; real closures)

I No named arguments(but can pass table)

Leo Antunes Lua

Page 11: Lua For Science! ...you monster

11

IntroductionUse-cases

DemoBenchmarks!Conclusion

BackgroundGeneral Pros/ConsWhat about science?

Use-cases

That’s all nice and good, but what is it for?

Application LuaembedableC Library

extensible

I Same stack-API on both cases (interpreter is thin-wrapper for lib)

I Focus: simplicity and performance over features(remember tables?)

I What seemed like limitations are now elegance

I Can wrap lib in C module or use Alien/FFI (cf. ctypes)

Leo Antunes Lua

Page 12: Lua For Science! ...you monster

12

IntroductionUse-cases

DemoBenchmarks!Conclusion

BackgroundGeneral Pros/ConsWhat about science?

Use-cases

That’s all nice and good, but what is it for?

Application LuaembedableC Library

extensible

I Same stack-API on both cases (interpreter is thin-wrapper for lib)

I Focus: simplicity and performance over features(remember tables?)

I What seemed like limitations are now elegance

I Can wrap lib in C module or use Alien/FFI (cf. ctypes)

Leo Antunes Lua

Page 13: Lua For Science! ...you monster

13

IntroductionUse-cases

DemoBenchmarks!Conclusion

BackgroundGeneral Pros/ConsWhat about science?

Use-cases

That’s all nice and good, but what is it for?

Application LuaembedableC Library

extensible

I Same stack-API on both cases (interpreter is thin-wrapper for lib)

I Focus: simplicity and performance over features(remember tables?)

I What seemed like limitations are now elegance

I Can wrap lib in C module or use Alien/FFI (cf. ctypes)

Leo Antunes Lua

Page 14: Lua For Science! ...you monster

14

IntroductionUse-cases

DemoBenchmarks!Conclusion

BackgroundGeneral Pros/ConsWhat about science?

General Pros/Cons...or: when should I use Lua instead of X?

I Not-so-rapid prototyping:

7 Boilerplate for OO7 Standard library is paltry7 LuaRocks still a bit lacking3 But: performance!

I Embedding:

3 Very easy with C (cf. Python), theoretically easy with all3 Handle configuration, customization, abstraction (DSLs)

I As Glue Language:

3 Also very easy to extend (remember: same API)3 ”Selective” Rapid Prototyping

Leo Antunes Lua

Page 15: Lua For Science! ...you monster

15

IntroductionUse-cases

DemoBenchmarks!Conclusion

BackgroundGeneral Pros/ConsWhat about science?

What about science?

I Lua Libraries:

3 Numerical: NumLua (FFTW, BLAS, LAPACK)3 Plotting: PLPlot, GNUPlot7 MPI: very basic wrapper7 Many missing, e.g.: Linear Programing

I Parallelization

7 No threads from Lua’s side (ANSI C; no actual GIL)3 But of course: C code can multithread3 Elegant and easy coroutines3 Easy to implement message-passing multi-threading in C

I Misc:

7 Only one number type: double; So: no boolean ops3 debug.debug(): interactive breakpoint for Lua code

Leo Antunes Lua

Page 16: Lua For Science! ...you monster

16

IntroductionUse-cases

DemoBenchmarks!Conclusion

BackgroundGeneral Pros/ConsWhat about science?

What about science?

I Lua Libraries:

3 Numerical: NumLua (FFTW, BLAS, LAPACK)3 Plotting: PLPlot, GNUPlot7 MPI: very basic wrapper7 Many missing, e.g.: Linear Programing

I Parallelization

7 No threads from Lua’s side (ANSI C; no actual GIL)3 But of course: C code can multithread3 Elegant and easy coroutines3 Easy to implement message-passing multi-threading in C

I Misc:

7 Only one number type: double; So: no boolean ops3 debug.debug(): interactive breakpoint for Lua code

Leo Antunes Lua

Page 17: Lua For Science! ...you monster

17

IntroductionUse-cases

DemoBenchmarks!Conclusion

I Up til now: tough sell

I Where it shines: performance (later) and simplicity forembedding/extending

Leo Antunes Lua

Page 18: Lua For Science! ...you monster

18

IntroductionUse-cases

DemoBenchmarks!Conclusion

I Up til now: tough sell

I Where it shines: performance (later) and simplicity forembedding/extending

Leo Antunes Lua

Page 19: Lua For Science! ...you monster

19

IntroductionUse-cases

DemoBenchmarks!Conclusion

Subject allocator

Lua Program1

Lua as DSL2

C/C++ module4

C++ lib

3

5

Leo Antunes Lua

Page 20: Lua For Science! ...you monster

20

IntroductionUse-cases

DemoBenchmarks!Conclusion

Figure : from http://attractivechaos.github.io/plb (independent)

Leo Antunes Lua

Page 21: Lua For Science! ...you monster

21

IntroductionUse-cases

DemoBenchmarks!Conclusion

Conclusion

I Lua is cool!

I Will I use it again? Probably.

I Should you use it? Definitely! For science? Maybe...

I Is it a silver bullet? No. But I don’t think that exists anyway

Leo Antunes Lua

Page 22: Lua For Science! ...you monster

22

IntroductionUse-cases

DemoBenchmarks!Conclusion

Conclusion

I Lua is cool!

I Will I use it again? Probably.

I Should you use it? Definitely! For science? Maybe...

I Is it a silver bullet? No. But I don’t think that exists anyway

Leo Antunes Lua

Page 23: Lua For Science! ...you monster

23

IntroductionUse-cases

DemoBenchmarks!Conclusion

Thanks!Questions?

Leo Antunes Lua