Parting thoughts about Programming and Programming Languages
Class
- Most time spent writing code
- Working in teams of 5
- Code lifetime - 3 weeks
Industry
- Most time spent reading, understanding, maintaining code
- Working in teams of 100s
- Code lifetime - many years
1. Study the art of programming
- You are writing code to be maintained by people
- What makes some code easy to read, maintain, and improve?
2. Use the right tools for the job
- Be greedy
- Don't be afraid to try new tools
- You don't need a class to teach you a new tool
- Version control (git)
- Testing
- The right programming language
... awesome
... showing its age
- extremely slow if not vectorized
- closed source
- License costs money
- Limited innovation
- Limited integration
- Limited dev tools
- extremely limited ability to scale to large projects
- Functions are the only widely-used encapsulation method
- Everything tied to the path
- No package manager
Matlab is...
- Simple
- Mathematical
- Has amazing tools
- ode45
- fmincon
- simulink
- linear systems toolbox
Programming Languages
- Performant
- Flexible and Composable
- Free and Open
- Easy for a wide range of people to use (for homework)
- Easy for a wide range of people to understand
C++, Fortran
Python
Python, Matlab
Python, Matlab
C++, Fortran
C++, Fortran
Python
Fast
Easy
2011
2013
We love [Matlab, Lisp, Python, Ruby, Perl, Mathematica, and C]; they are wonderful and powerful. For the work we do — scientific computing, machine learning, data mining, large-scale linear algebra, distributed and parallel computing — each one is perfect for some aspects of the work and terrible for others. Each one is a trade-off.
We are greedy: we want more.
2012
Programming Languages
- Performant
- Flexible and Composable
- Free and Open
- Easy for a wide range of people to use (for homework)
- Easy for a wide range of people to understand
C++, Fortran
Python
Python, Matlab
Python, Matlab
C++, Fortran
C++, Fortran
Python
Fast
Easy
Speed: Just-in-time LLVM Compilation
Cool things that Julia can do
- Auto-differentiation
- CUDA
- Multithreading
- Distributed Computing, from single chip to a cluster
using CUDA
x_d = CUDA.fill(1.0f0, N) # a vector stored on the GPU filled with 1.0 (Float32)
y_d = CUDA.fill(2.0f0, N) # a vector stored on the GPU filled with 2.0
function add_broadcast!(y, x)
CUDA.@sync y .+= x
return
end
add_broadcast!(y_d, x_d)
numblocks = ceil(Int, length(y)/256)
CUDA.@sync begin
@cuda threads=256 blocks=numblocks gpu_add!(y, x)
end
Julia and other open-source languages are out there waiting!
Scientific computing is pretty good these days
How many have...
- Rewritten MATLAB or Python code in C?
- Written Python or MATLAB bindings for C code so that others can use it?
Julia solves the two language problem!!
Julia is
- as easy to read, write, maintain, and collaborate with as Python or MATLAB
- as fast as C
EASIER
FASTER
Be skeptical
Find out for yourself!
Also ~2011: Improving TCAS
ACAS X
POMDP Models
+
=
Optimization
Specification
POMDPs.jl - An interface for defining and solving MDPs and POMDPs in Julia
[Egorov, Sunberg, et al., 2017]
Why should I believe it's fast?
Julia - Speed
Celeste Project
1.54 Petaflops
Why should I believe it's easy to use?
Previous C++ framework: APPL
"At the moment, the three packages are independent. Maybe one day they will be merged in a single coherent framework."
How does it work?
Code: Multiple Dispatch,
Optional Type Indications,
First Class Arrays
+
=
Julia is
- as easy to read, write, maintain, and collaborate with as Python or MATLAB
- as fast as C
EASIER
FASTER
Compatibility with other languages: C
#include <julia.h>
JULIA_DEFINE_FAST_TLS() // only define this once, in an executable (not in a shared library) if you want fast code.
int main(int argc, char *argv[])
{
/* required: setup the Julia context */
jl_init();
/* run Julia commands */
jl_eval_string("print(sqrt(2.0))");
/* strongly recommended: notify Julia that the
program is about to terminate. this allows
Julia time to cleanup pending write requests
and run all finalizers
*/
jl_atexit_hook(0);
return 0;
}
x=ccall((:mean,"libmean"),Float64,(Float64,Float64),2.0,5.0)
println(x)
3.5
double mean(double a, double b) {
return (a+b) / 2;
}
Julia from C
C from Julia
Compatibility with other languages: Python
Questions?
zachary.sunberg@colorado.edu
Parting thoughts about Programming and Programming Languages
By Zachary Sunberg
Parting thoughts about Programming and Programming Languages
- 293