You are on page 1of 13

A Seminar Report

on
Scientific Computation with Julia
In partial fulfillment of requirements for the degree of
Bachelor of Technology
In
Computer Science and Engineering

SUBMITTED BY:
Lokesh Sharma
14522

COMPUTER SCIENCE AND ENGINEERING DEPARTMENT


NATIONAL INSTITUTE OF TECHNOLOGY
HAMIRPUR 177005
MARCH 2017
Acknowledgement

First and foremost I would like to thank Ms. Garima Sharma and our institute for
providing me the platform and means to conduct research on this topic. While preparing this
topic the insightful articles by developers especially Evan Miller proved invaluable in my
research. They helped me understand whats lacking in todays scientific computation field
and made me aware of its various challenges. I would like to thank ARS Technica
magazine whose brilliant articles helped me understand the modern trends in scientific
community. I feel immense gratitude towards my classmates and online community of
developers who help me along the way.

1
Page Index

Abstract 4

1. Introduction 5

2. Background 5

3. Scientific Computation 6

4. Julia 7

4.1. Features 8

4.1.1 High-Performance JIT Compiler 8

4.1.2 Easy to learn and use 9

4.1.3 Designed for Parallelism and Cloud Computing 10

4.1.4 Free, Open Source and Library-Friendly 10

5. Conclusion 11

2
Figure Index

Fig 1. Code to divide 2 numbers in Fortran 6

Fig 2. Benchmark times relative to C 9

Fig 3. Comparing C and Julia for Belief Propagation Algorithm 9

Fig 4. Counting number of heads in parallel 10

3
Abstract

Computational Science is a rapidly growing multidisciplinary field that uses advanced


computing capabilities to understand and solve complex problems.

So far FORTRAN, C/C++, MATLAB and Python have been used to fulfil the needs of
scientific computing. But with the rising need of huge amount of data to be readily
computed, these languages are falling short to serve todays need. Distributed computing is
on the rise but these languages do not readily support them. Further, on has to make a
compromise between between readability and performance because theres no language
that provides both of them at the same time.

Now, Julia is a relatively new programming language which has become popular in the
scientific community in a very short time because of its great features. Julia provides
distributed parallel execution, numerical accuracy, and an extensive mathematical
function library. It is faster than other scripting languages, allowing one to have the rapid

development of Python/MATLAB/R while producing code that is as fast as C/Fortran.

4
Scientific Computation with Julia

1. INTRODUCTION
From a long time scientific computation community is looking for a language that is easy to
learn and use and at the same time has efficiency of C. Julia is such a language which
fulfills all requirements of todays scientific computation needs. Julia is a high-level,
high-performance dynamic programming language for numerical computing. It provides a
sophisticated compiler, distributed parallel execution, numerical accuracy, and an extensive
mathematical function library.

2. BACKGROUND
Todays scientific computation community is faced with many challenges. One of them is
the two language problem. Within a application where we want efficiency, we are usually
forced to write that code in low level language like C because it is fast where for the code
which is very complex we often employ use of a high level language which is easy to learn
and use. This gives rise to the two language problem. Evan Miller, a renowned statistician
beautifully puts it by saying that Normally I use one language to make something work,
and a second language to make it fast, and a third language to make it scream.[1] This
leads to problem for new developers as well as existing ones because working with two
languages isnt easy as the code gets more bulky and complex.
Another prominent problem is that developers have no choice but to code in languages
like Fortran and C to make their code efficient.[2] As you know these languages are
statically typed and hence converting mathematical formulas and algorithms to equivalent
code is much harder and often only professional developers are able to do so. This prevent
mainstream users and pioneers of the scientific computation world to contribute in the
software, hence making development slow and inefficient. Below is an image of Fortran
code. You can notice how hard it is to recognize what this code does. This code only
divides two numbers and you can imagine if this code is hard to understand what would
happen when one has to understand a complex algorithm written in the same language.

5
Fig 1. Code to divide 2 numbers in Fortran

Another challenge which is being faced is that of requirement of parallelism so


programs can run in distributed way so they can be used to run big data computations. Most
of the current scientific computation frameworks do not provide functionality to run the
code in a distributed way without much effort. In fact one has to move his/her whole
program to special stack like Hadoop in order to run it in a distributive way to make use of
parallelism and tackle big data computations.
Such challenges and many more intrigues us to wonder if such a language can be
created which can fulfill all these requirements. We require a language that is easy to use
and learn so that it can be used by the mainstream scientists. At the same time efficiency of
running time of the program is also of keen importance, hence it should match the speed of
low languages like C and Fortran. Further we need something through which our code can
be easily run in a distributed system and make use of parallelism. Julia seems to fulfill all
these requirements and standout as jewel in a scientific computation. Everyone is talking
about it and in a very short time it has gained the favor of many mainstream developers and
scientists. For instance, at MIT, USA a number of courses are being taught in Julia. AT IIT
Indore, it is being used to teach Linear Algebra. Similarly many other universities like
Stanford and Harvard are following this language in their academics.[3]

3. Scientific Computation
Computation is any type of calculation that follows a well-defined model understood and
expressed as an algorithm. And Scientific Computation is a rapidly growing

6
multidisciplinary field that uses advanced computing capabilities to understand and solve
complex problems.
Data Science, Artificial Intelligence, Machine Learning, Computer Vision, Simulation
& Modelling are some of the examples of scientific computation. Computational science
fuses three distinct elements:
Algorithms (numerical and non-numerical) and modeling and simulation software
developed to solve science (e.g., biological, physical, and social), engineering, and
humanities problems
Computer and information science that develops and optimizes the advanced
system hardware, software, networking, and data management components needed
to solve computationally demanding problems
The computing infrastructure that supports both the science and engineering
problem solving and the developmental computer and information science
In practical use, it is typically the application of computer simulation and other forms
of computation from numerical analysis and theoretical computer science to solve problems
in various scientific disciplines.
The field is different from theory and laboratory experiment which are the traditional
forms of science and engineering. The scientific computing approach is to gain
understanding, mainly through the analysis of mathematical models implemented on
computers.
Scientists and engineers develop computer programs, application software, that model
systems being studied and run these programs with various sets of input parameters. In
some cases, these models require massive amounts of calculations (usually floating-point)
and are often executed on supercomputers or distributed computing platforms.
Numerical analysis is an important underpinning for techniques used in computational
science.

4. Julia
The Julia programming language fills the role of a perfect scientific computing language
having all the features the community is thriving for years to find in a single language all at

7
once. It is flexible dynamically typed language with performance comparable to traditional
statically typed languages.

4.1. Features
Following is a summary of features of the language:
Multiple dispatch: providing ability to define function behavior across many
combinations of argument types
Dynamic type system: types for documentation, optimization, and dispatch
Good performance, approaching that of statically-compiled languages like C
Built-in package manager
Lisp-like macros and other metaprogramming facilities
Call Python functions: use the PyCall package
Call C functions directly: no wrappers or special APIs
Powerful shell-like capabilities for managing other processes
Designed for parallelism and distributed computation
Coroutines: lightweight green threading
User-defined types are as fast and compact as built-ins
Automatic generation of efficient, specialized code for different argument types
Elegant and extensible conversions and promotions for numeric and other types
Efficient support for Unicode, including but not limited to UTF-8
MIT licensed: free and open source

Lets see some of its prominent features in detail.

4.1.1. High-Performance JIT Compiler


Julias LLVM-based just-in-time (JIT) compiler combined with the languages design allow
it to approach and often match the performance of C. To get a sense of relative performance
of Julia compared to other languages that can or could be used for numerical and scientific
computing, below is the result of a small set of micro-benchmarks written in a variety of
languages: C, Fortran, Julia, Python, Matlab/Octave, R, JavaScript, Java, Lua, Go, and
Mathematica.[4]

8
Fig 2. Benchmark times relative to C (smaller is better, C performance = 1.0)

4.1.2 Easy to learn and use


Scientific computing has traditionally required the highest performance, yet
domain experts have largely moved to slower dynamic languages because of their
ease of learning and use. With Julia one doesnt need make such a compromise.
One gets the efficiency of statically typed language while retaining the easiness of a
dynamically typed language. This avails the developers to work more complex code
easily and efficiently.

Fig 3. Comparing C and Julia code for Belief Propagation Algorithm

9
Above is example of implementation of belief propagation algorithm (used for
message passing in probability graphical models) in both C and Julia. It is quite evident
from looking at the Julia code what it is doing. It is transforming a vector with matrix A and
then normalizing it repeatedly. It would take a lot more effort to understand what the
equivalent C code is accomplishing.

4.1.3. Designed for Parallelism and Cloud Computing

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.

Fig 4. Counting the number of heads in parallel

This computation is automatically distributed across all available compute nodes, and the
result, reduced by summation (+), is returned at the calling node.

4.1.4. Free, Open Source and Library-Friendly

Certainly it goes without saying how beneficial a free and open source software is.
Unlike Matlab which is paid, Julia is free and open source meaning anyone can use
and modify it. 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). The language can be
built as a shared library, so users can combine Julia with their own C/Fortran code
or proprietary third-party libraries. Furthermore, Julia makes it simple to call

10
external functions in C and Fortran shared libraries, without writing any wrapper
code or even recompiling existing code.

5. Conclusion

Julia is created to cater the needs of modern scientific computation community. It is


emerging as a powerful language for scientific expression. Although it is just 5 years old,
its packages are evolving at a very high rate and many mainstream scientists and developers
have moved to the language. It is expected to replace languages like Matlab, Octave, R, etc.
and become the scientific computation language of the future.

A number of courses based on Differential Equations and Linear Algebra are now
being taught in Julia at MIT, USA. It also has found place in few courses provided at IIT
Indore.[3] Julia is further expected to become 2 or 3 times more fast than C in its future
releases. It is certain that with the advent of Julia, the field of scientific computation will
evolve faster than ever. It is proving a boon for mainstream scientists who require
computation to perform their tasks as this language provides the ease of scripting language
while not compromising the speed at the same time.

11
Bibliography

1. Evan Miller, Why Im Betting on Julia,


http://www.evanmiller.org/why-im-betting-on-julia.html
2. Lee Phillips, Scientific computings future: Can any coding language top a 1950s
behemoth?,
https://arstechnica.com/science/2014/05/scientific-computings-future-can-any-codin
g-language-top-a-1950s-behemoth/2/
3. Julia official website, Teaching Julia, https://julialang.org/teaching/
4. Ondej ertk, Julia Benchmaks,
https://github.com/JuliaLang/julia/tree/master/test/perf/micro

12

You might also like