31,19 €
Design and develop high performing programs with Julia
This book is for beginner and intermediate Julia programmers who are interested in high performance technical computing. You will have a basic familiarity with Julia syntax, and have written some small programs in the language.
Julia is a high performance, high-level dynamic language designed to address the requirements of high-level numerical and scientific computing. Julia brings solutions to the complexities faced by developers while developing elegant and high performing code.
Julia High Performance will take you on a journey to understand the performance characteristics of your Julia programs, and enables you to utilize the promise of near C levels of performance in Julia.
You will learn to analyze and measure the performance of Julia code, understand how to avoid bottlenecks, and design your program for the highest possible performance. In this book, you will also see how Julia uses type information to achieve its performance goals, and how to use multuple dispatch to help the compiler to emit high performance machine code. Numbers and their arrays are obviously the key structures in scientific computing – you will see how Julia's design makes them fast. The last chapter will give you a taste of Julia's distributed computing capabilities.
This is a hands-on manual that will give you good explanations about the important concepts related to Julia programming.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 146
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: April 2016
Production reference: 1220416
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-091-9
www.packtpub.com
Author
Avik Sengupta
Reviewer
QL ZHUO
Commissioning Editor
Priya Singh
Acquisition Editor
Reshma Raman
Content Development Editor
Onkar Wani
Technical Editor
Kunal Chaudhari
Copy Editor
Shruti Iyer
Project Coordinator
Bijal Patel
Proofreader
Safis Editing
Indexer
Rekha Nair
Graphics
Jason Monteiro
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
Avik Sengupta has worked on risk and trading systems in investment banking for many years, mostly using Java interspersed with snippets of the exotic R and K languages. This experience left him wondering whether there were better things out there. Avik's quest came to a happy conclusion with the appearance of Julia in 2012. He has been happily coding in Julia and contributing to it ever since.
This book was only possible because four intrepid computer scientists decided they wanted a better language six years ago. So, I would like to thank Alan, Jeff, Stefan, and Viral for giving Julia to the world. The world of scientific computing has changed drastically as a result.
Working in Julia over the last three years has been one of the most enjoyable experiences in my professional career. A large part of this joy is due to the people who inhabit this community. It is a collection of smart and engaged scientists and developers who have taught me far more than programming languages. A big "thank you" goes to the entire Julia community, which is responsible for all the buzz that Julia has received.
Many thanks are due to the reviewers who generously provided their time to improve this book. While all the deficiencies remain my own, this is now a much better product thanks to their efforts.
Writing a book turned out to need many more late nights than I would have thought necessary. So, I would like to give a big shout-out to Vaishali and Ahan for keeping me sane and well-fed during this process.
QL ZHUO (also known as KDr2 online) is an open source developer from China who has about 10 years experience with Linux, C, C++, Java, Python, and Perl development. He loves participating in and contributing to the open source community, which, of course, includes the Julia community. QL maintains a personal website at http://kdr2.com, and you can find out more about him there.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
When I first learned about Julia in early 2012, it was clear to me that this is a language that I've wanted for many years. The use of multiple dispatch made it very easy to express mathematical concepts, while the speed of the language made it feasible to express them in the Julia. I came for the elegance and stayed for the performance. On the other hand, some users come to Julia for the performance and stay for the elegance. Either way, in order to fully appreciate the power and beauty of the language, it needs to live up to its promise of high performance.
I hope this book will help Julia programmers at all levels to learn the design techniques and paradigms that produce fast Julia code. One of the nice things about Julia is that its performance characteristics are simple and easy to reason out. I hope this book will provide you with a framework to think about and analyze the performance of your own code.
Chapter 1, Julia is Fast, discuses some of the design underpinning the language and its focus on high performance.
Chapter 2, Analyzing Julia Performance, provides the tools and techniques you can use to measure and analyze the performance of your own programs.
Chapter 3, Types in Julia, describes the type system and discusses why writing type-stable code is crucial to high performance.
Chapter 4, Functions and Macros – Structuring Julia Code for High Performance, discusses techniques to use dispatch and code generation to structure high-performance programs.
Chapter 5, Fast Numbers, discusses the basic numeric types and why they are fast.
Chapter 6, Fast Arrays, describes ways to use multidimensional arrays in the fastest possible way.
Chapter 7, Beyond the Single Processor, provides an introduction to Julia's distributed computing facilities.
If you are reading this book, we assume you have installed Julia and written a few simple Julia programs and that you are familiar with Julia REPL. The basic Julia installation, available from http://julialang.org/downloads, is the only prerequisite for this book. We will demonstrate most of the techniques in the book using REPL, and we encourage your to follow along. Paste the commands on to REPL and inspect the output yourself.
This book is for beginner- and intermediate-level Julia developers who are interested in high-performance technical computing. We expect you to have a basic understanding of Julia's syntax and have written a few small Julia programs prior to reading this book.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/JuliaHighPerformance_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
In many ways, the history of programming languages has often been driven by, and certainly intertwined, with the needs of numerical and scientific computing. The first high-level programming language, Fortran, was created with scientific computing in mind, and continues to be important in the field even to this day. In recent years, the rise of data science as a specialty has brought additional focus to scientific computing, particularly for statistical uses. In this area, somewhat counterintuitively, both specialized languages such as R and general-purpose languages such as Python are in widespread use. The rise of Hadoop and Spark has spread the use of Java and Scala respectively among this community. In the midst of all this, Matlab has had a strong niche within engineering and communities, while Mathematica remains unparalleled for symbolic operations.
A new language for scientific computing therefore has a very high barrier to overcome. It's been only a few short years since the Julia language was introduced into the world. In this time, it's innovative features, which make it a dynamic language, based on multiple dispatch as its defining paradigm, has created growing niche within the numerical computing world. However, it's the claim of high performance that excited its early adopters the most.
This, then, is a book that celebrates writing high-performance programs. With Julia, this is not only possible, but also reasonably straightforward, within a low-overhead, dynamic language.
As a reader of this book, you have likely already written your first few Julia programs. We will assume that you have successfully installed Julia, and have a working programming environment available. We expect you are familiar with very basic Julia syntax, but we will discuss and review many of those concepts throughout the book as we introduce them.
It is a widely believed myth in programming language communities that high-performance languages and dynamic languages are completely disjoint sets. The perceived wisdom is that, if you want programmer productivity, you should use a dynamic language, such as Ruby, Python or R. On the other hand, if you want fast code execution, you should use a statically typed language such as C or Java.
There are always exceptions to this rule. However, for most mainstream programmers, this is a strongly held belief.
This usually manifests itself in what is known as the "two language" problem. This is something that is especially prominent in scientific computing. This is the situation where the performance-critical inner kernel is written in C, but is then wrapped and used from a dynamic, higher-level language. Code written in traditional, scientific computing environments such as R, Matlab or NumPy follows this paradigm.
Code written in this fashion is not without its drawbacks however. Even though it looks like this gets you the best of both worlds — fast computation, while allowing the programmer to use a high-level language — this is a path full of hidden dangers. For one, someone will have to write the low-level kernel. So, you need two different skillsets. If you are lucky to find the low level code in C for your project, you are fine. However, if you are doing anything new or original, or even slightly different from the norm, you will find yourself writing both C and a high-level language. This severely limits the number of contributors that your projects or research will get: to be really productive, they have to be familiar with two languages.
