Book Image

Julia 1.0 High Performance - Second Edition

By : Avik Sengupta
Book Image

Julia 1.0 High Performance - Second Edition

By: Avik Sengupta

Overview of this book

Julia is a high-level, high-performance dynamic programming language for numerical computing. If you want to understand how to avoid bottlenecks and design your programs for the highest possible performance, then this book is for you. The book starts with how Julia uses type information to achieve its performance goals, and how to use multiple dispatches to help the compiler emit high-performance machine code. After that, you will learn how to analyze Julia programs and identify issues with time and memory consumption. We teach you how to use Julia's typing facilities accurately to write high-performance code and describe how the Julia compiler uses type information to create fast machine code. Moving ahead, you'll master design constraints and learn how to use the power of the GPU in your Julia code and compile Julia code directly to the GPU. Then, you'll learn how tasks and asynchronous IO help you create responsive programs and how to use shared memory multithreading in Julia. Toward the end, you will get a flavor of Julia's distributed computing capabilities and how to run Julia programs on a large distributed cluster. By the end of this book, you will have the ability to build large-scale, high-performance Julia applications, design systems with a focus on speed, and improve the performance of existing programs.
Table of Contents (19 chapters)
Title Page
Dedication
Foreword
Licences

Broadcasting

I hope that in your explorations of Julia, you have come across array broadcasting. This is the ability to perform an operation on each element of an array, rather than on the array as a whole, such as computing the square root of every element of a vector, as shown in the following code:

julia> a=collect(1:4);

julia> sqrt.(a)
4-element Array{Float64,1}:
1.0
1.4142135623730951
1.7320508075688772
2.0

More generally, it allows operations between arrays of different shapes, such as adding a vector to every column in a matrix, as follows:

julia> b=reshape(1:8, 4, 2)
4×2 reshape(::UnitRange{Int64}, 4, 2) with eltype Int64:
1 5
2 6
3 7
4 8

julia> b .+ a
4×2 Array{Int64,2}:
2 6
4 8
6 10
8 12

For the most part, broadcasting is a great syntactic feature in Julia, which makes it very easy and consistent to work with multidimensional arrays. In particular, unlike...