Started in 2009 by Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and Alan Edelman
Launched in 2012 as free and open source software
Version 1.0 released in 2018
Computer languages mostly fall into two categories:
Compiled languages
Interpreted languages
Source code compiled at run time
Built-in multiple dispatch : functions apply different methods at run time based on the type of the operands
Optional type declaration
Julia website
The official Julia manual
Online training material
The Julia YouTube channel
The Julia Wikibook
A blog aggregator for Julia
Discourse forum
[julia] tag on Stack Overflow
Slack#julialang hashtag on Twitter
SubredditGitter channel
#julia IRC channel on Freenode
julia-emacs](https://github.com/JuliaEditorSupport/julia-emacs) with [julia-repl
ESS
EIN
for Jupyter notebooks
A Julia IDE](https://junolab.org/) built on [Atom
Project Jupyter has a Julia kernel
C-c cancel
C-d quit
C-l clear console
C-u kill from the start of line
C-k kill until the end of line
C-a go to start of line
C-e go to end of line
C-f move forward one character
C-b move backward one character
M-f move forward one word
M-b move backward one word
C-d delete forward one character
C-h delete backward one character
M-d delete forward one word
M-Backspace delete backward one word
C-p previous command
C-n next command
C-r backward search
C-s forward search
(env) pkg> add <package> # install <package>
(env) pkg> rm <package> # uninstall <package>
(env) pkg> up <package> # upgrade <package>
(env) pkg> st # check which packages are installed
(env) pkg> up # upgrade all packages
By default, installed in ~/.julia
> using <package>
> typeof(2)
> typeof(2.0)
> typeof("hello")
> typeof(true)
Indexing starts at 1
, not 0
> a = [1 2; 3 4]
> a[1, 1]
> a[1, :]
> for i in 1:10
println(i)
end
> for i in 1:3, j = 1:2
println(i * j)
end
> a = 2
> b = 2.0
> if a == b
println("It's true")
else
println("It's false")
end
# Terse format
> a == b ? println("It's true") : println("It's false")
> function addTwo(a)
a + 2
end
> addTwo(3)
# Terse format
> addtwo = a -> a + 2
# With default argument
> function name(a = "unknown")
println("My name is $a.")
end
> name("Julia")
> name()
Fun: plots in the command line!
> using UnicodePlots
> UnicodePlots.histogram(randn(1000), nbins=40)
This can be useful in remote sessions
Nicer looking plots
> using Plots, Distributions, StatsPlots
> gr() # Using the GR framework as backend
> x = 1:10; y = rand(10, 2);
> p1 = Plots.histogram(randn(1000), nbins=40)
> p2 = plot(Normal(0, 1))
> p3 = scatter(x, y)
> p4 = plot(x, y)
> plot(p1, p2, p3, p4)
The Plots
site has demos
Set the environment variable:
$ export JULIA_NUM_THREADS=n
Or launch a julia session with:
$ JULIA_NUM_THREADS=n julia
See how many threads are used in a julia session:
> Threads.nthreads()
Non parallel code
> for i = 1:10
println("Iteration $i ran on thread $(Threads.threadid())")
end
Parallel code
> Threads.@threads for i = 1:10
println("Iteration $i ran on thread $(Threads.threadid())")
end
Let’s do a simple loop with 10,000,000 iterations
Non parallel code
> @time for i = 1:10000000
i ^ i
end
Parallel code
> @time Threads.@threads for i = 1:10000000
i ^ i
end
# Look for available julia modules
$ module spider julia
# See modules required to load julia 1.3
$ module spider julia/1.3.0
# Load required gcc module and julia module
$ module load gcc/7.3.0 julia/1.3.0
#!/bin/bash
#SBATCH --job-name=julialoop # job name
#SBATCH --time=00:00:30 # max walltime 30s
#SBATCH --cpus-per-task=32 # number of cores
#SBATCH --mem=100 # max memory (in MB)
#SBATCH --output=julialoop%j.out # output file name
#SBATCH --error=julialoop%j.err # errors file name
echo Running non parallel loop on $SLURM_CPUS_PER_TASK cores
JULIA_NUM_THREADS=$SLURM_CPUS_PER_TASK julia loop.jl
echo Running parallel loop on $SLURM_CPUS_PER_TASK cores
JULIA_NUM_THREADS=$SLURM_CPUS_PER_TASK julia ploop.jl
$ sbatch job_julialoop.sh
$ sq
PD : pending R : running
Running non parallel loop on 32 cores
0.810377 seconds
Running parallel loop on 32 cores
0.093013 seconds (31.92 k allocations: 1.785 MiB)