_
_ _ _(_)_ |
(_) | (_) (_) | A fresh approach to technical computing
_ _ _| |_ __ _ |
| | | | | | |/ _` | | http://julialang.org
| | |_| | | | (_| | | [email protected]
_/ |\__'_|_|_|\__'_| |
|__/ |
Julia is a high-level, high-performance dynamic language for technical computing, with syntax that is familiar to users of other technical computing environments. It provides a sophisticated compiler, distributed parallel execution, numerical accuracy, and an extensive mathematical function library. The library, mostly written in Julia itself, also integrates mature, best-of-breed C and Fortran libraries for linear algebra, random number generation, FFTs, and string processing. More libraries continue to be added over time. Julia programs are organized around defining functions, and overloading them for different combinations of argument types (which can also be user-defined). For a more in-depth discussion of the rationale and advantages of Julia over other systems, see the following highlights or read the introduction in the manual.
Julia's LLVM-based JIT compiler combined with the language's design allow it to approach and often match the performance of C/C++. The following benchmarks are from a MacBook Pro with a 2.53GHz Intel Core 2 Duo CPU and 8GB of 1066MHz DDR3 RAM:
_______________________________________________________________________________
| |
| C++ (GCC) | Julia Python/NumPy Matlab Octave
| 4.2.1 -O3 | bd7c16a2 2.7.1/1.5.1 R2011a 3.4
_________________|_____________|_______________________________________________
| |
fib | .205 | 2.14 27.5 1351. 2531.
parse_int | .0901 | 1.60 6.55 897. 5580.
mandel | .269 | 5.87 30.3 61.6 844.
quicksort | .429 | 1.15 61.8 145. 3356.
pi_sum | 53.8 | 0.74 18.9 1.13 351.
rand_mat_stat | 7.05 | 4.29 44.0 13.1 62.1
_________________|_____________|_______________________________________________
Figure. C++: benchmark time (ms); others: benchmark time / C++ time.
Julia beats other high-level systems on all micro-benchmarks above and even beats C++ by 26% on the pi summation benchmark. Relative performance between languages on other systems is similar. These benchmarks, while not comprehensive, do test compiler performance on a range of common code patterns, such as function calls, string parsing, sorting, numerical loops, random number generation, and array operations. Julia is strong in an area that high-level languages have traditionally been weak: scalar arithmetic loops, such as that found in the pi summation benchmark. Moreover, Julia has a comprehensive approach to performance that allows it to eliminate overhead in all kinds of code and for all data types, not just double-precision scalar operations. This performance is due to a combination of LLVM optimizations, and the Julia compiler's ability to generate high-quality LLVM code.
To give a quick taste of what Julia looks like, here is the code used in the Mandelbrot and random matrix statistics benchmarks:
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
function randmatstat(t)
n = 5
v = zeros(t)
w = zeros(t)
for i = 1:t
a = randn(n,n)
b = randn(n,n)
c = randn(n,n)
d = randn(n,n)
P = [a b c d]
Q = [a b; c d]
v[i] = trace((P.'*P)^4)
w[i] = trace((Q.'*Q)^4)
end
std(v)/mean(v), std(w)/mean(w)
end
As you can see, the code is quite clear, and should feel familiar to anyone who has programmed in other mathematical languages. Although C++ beats Julia in the random matrix statistics benchmark by a factor of four, consider how much simpler this code is than the C++ implementation. There are more compiler optimizations planned that we hope will close this performance gap in the future. By design, Julia allows you to range from low-level loop and vector code, up to a high-level programming style, sacrificing some performance, but gaining the ability to express complex algorithms easily. This continuous spectrum of programming levels is a hallmark of the Julia approach to programming and is very much an intentional feature of the language.
Julia does not impose any particular style of parallelism on the user. Instead, it provides a number of key building blocks for distributed computation, making it flexible enough to support a number of styles of parallelism, and allowing users to add more. The following simple example demonstrates how to count the number of heads in a large number of coin tosses in parallel.
nheads = @parallel (+) for i=1:100000000
randbit()
end
This computation is automatically distributed across all available compute nodes, and the result, reduced by summation (+
), is returned at the calling node.
Although it is in the early stages, Julia already supports a fully remote cloud computing mode. Here is a screenshot of a web-based interactive Julia session, plotting an oscillating function and a Gaussian random walk:
There will eventually be full support for cloud-based operation, including data management, code editing, execution, debugging, collaboration, analysis, data exploration, and visualization. The goal is to allow people who work with big data to stop worrying about administering machines and data and get straight to the real problem: exporing their data and creating the algorithms that can solve the problems presented by their big data.
The core of the Julia implementation is licensed under the MIT license. Various libraries used by the Julia environment include their own licenses such as the GPL, LGPL, and BSD (therefore the environment, which consists of the language, user interfaces, and libraries, is under the GPL). Core functionality is included in a shared library, so users can easily and legally combine Julia with their own C/Fortran code or proprietary third-party libraries. Furthermore, Julia makes it simple to call external functions in C and Fortran shared libraries, without writing any wrapper code or even recompiling existing code. You can try calling external library functions directly from Julia's interactive prompt, playing with the interface and getting immediate feedback until you get it right. See LICENSE for the full terms of Julia's licensing.
## Resources- Homepage: http://julialang.org
- Discussion: [email protected]
- Source code: https://github.com/JuliaLang/julia
- Git clone URL: git://github.com/JuliaLang/julia.git (see below)
- Documentation: https://github.com/JuliaLang/julia/wiki
- GNU make — building dependencies.
- gcc, g++, gfortran — compiling and linking C, C++ and Fortran code.
- curl — to automatically download external libraries:
- LLVM — compiler infrastructure.
- fdlibm — a portable implementation of much of the system-dependent libm math library's functionality.
- MT — a fast Mersenne Twister pseudorandom number generator library.
- OpenBLAS — a fast, open, and maintained basic linear algebra subprograms (BLAS) library, based on Kazushige Goto's famous GotoBLAS.
- LAPACK — library of linear algebra routines for solving systems of simultaneous linear equations, least-squares solutions of linear systems of equations, eigenvalue problems, and singular value problems.
- ARPACK — a collection of subroutines designed to solve large, sparse eigenvalue problems.
- FFTW — library for computing fast Fourier transforms very quickly and efficiently.
- PCRE — Perl-compatible regular expressions library.
- GNU readline — library allowing shell-like line editing in the terminal, with history and familiar key bindings.
- D3 — javascript visualization library.
- GNU/Linux: x86/64 (64-bit); x86 (32-bit).
- Darwin/OS X: x86/64 (64-bit); x86 (32-bit) is untested but should work.
Julia's binary installs ship as platform-specific tarballs:
- GNU/Linux x86/64: https://github.com/downloads/JuliaLang/julia/julia-08b1e294ed-Linux-x86_64.tar.gz
- Darwin/OS X x86/64: https://github.com/downloads/JuliaLang/julia/julia-08b1e294ed-Darwin-x86_64.tar.gz
- GNU/Linux x86: https://github.com/downloads/JuliaLang/julia/julia-618b93c22c-Linux-i686.tar.gz
Download the appropriate tarball and untar it somewhere; for example, if you are on an OS X (Darwin) x86/64 system, do the following:
curl -OLk https://github.com/downloads/JuliaLang/julia/julia-08b1e294ed-Darwin-x86_64.tar.gz
tar zxvf julia-08b1e294ed-Darwin-x86_64.tar.gz
You can either run the julia
executable using its full path in the directory created above, or add that directory to your executable path so that you can run the julia program from anywhere:
export PATH="$(pwd)/julia:$PATH"
Now you should be able to run julia like this:
julia
If everything works correctly, you will see a Julia banner and an interactive prompt into which you can enter expressions for evaluation. You can read about getting started in the manual.
## Source Download & CompilationFirst, acquire the source code either by cloning the git repository (requires git to be installed):
git clone git://github.com/JuliaLang/julia.git
or, if you don't have git installed, by using curl and tar to fetch and unpack the source:
mkdir julia && curl -Lk https://github.com/JuliaLang/julia/tarball/master | tar -zxf- -C julia --strip-components 1
Next, enter the julia/
directory and run make
to build the julia
executable.
When compiled the first time, it will automatically download and build its external dependencies.
This takes a while, but only has to be done once.
Note: the build process will not work if any of the build directory's parent directories have spaces in their names (this is due to a limitation in GNU make).
Once it is built, you can either run the julia
executable using its full path in the directory created above, or add that directory to your executable path so that you can run the julia program from anywhere:
export PATH="$(pwd)/julia:$PATH"
Now you should be able to run julia like this:
julia
If everything works correctly, you will see a Julia banner and an interactive prompt into which you can enter expressions for evaluation. You can read about getting started in the manual.
## Platform-Specific NotesOn some Linux distributions (for instance Ubuntu 11.10) you may need to change how the readline library is linked. If you get a build error involving readline, try changing the value of USE_SYSTEM_READLINE
in Make.inc
to 1
.
On Ubuntu, you may also need to install the package libncurses5-dev
.
attic/ old, now-unused code
contrib/ emacs and textmate support for julia
examples/ example julia programs
external/ external dependencies
install/ used for creating binary installs
j/ source code for julia's standard library
lib/ shared libraries loaded by julia's standard libraries
src/ source for julia language core
test/ unit and function tests for julia itself
ui/ source for various front ends
Add the following line to ~/.emacs
(require 'julia-mode "JULIA_PATH/contrib/julia-mode.el")
where JULIA_PATH
is the location of the top-level julia directory.
Copy (or symlink) the TextMate Julia bundle into the TextMate application support directory:
cp -r JULIA_PATH/contrib/Julia.tmbundle ~/Library/Application\ Support/TextMate/Bundles/
where JULIA_PATH
is the location of the top-level julia directory.
Now select from the menu in TextMate Bundles > Bundle Editor > Reload Bundles
.
Julia should appear as a file type and be automatically detected for files with the .j
extension.
Adjusting your terminal bindings is optional; everything will work fine without these key bindings.
For the best interactive session experience, however, make sure that your terminal emulator (Terminal
, iTerm
, xterm
, etc.) sends the ^H
sequence for Backspace
(delete key) and that the Shift-Enter
key combination sends a \n
newline character to distinguish it from just pressing Enter
, which sends a \r
carriage return character.
These bindings allow custom readline handlers to trap and correctly deal with these key sequences; other programs will continue behave normally with these bindings.
The first binding makes backspacing through text in the interactive session behave more intuitively.
The second binding allows Shift-Enter
to insert a newline without evaluating the current expression, even when the current expression is complete.
(Pressing an unmodified Enter
inserts a newline if the current expression is incomplete, evaluates the expression if it is complete, or shows an error if the syntax is irrecoverably invalid.)
On Linux systems, the Shift-Enter
binding can be set by placing the following line in the file .xmodmaprc
in your home directory:
keysym Return = Return Linefeed