Book Image

Scientific Computing with Scala

By : Vytautas Jancauskas
Book Image

Scientific Computing with Scala

By: Vytautas Jancauskas

Overview of this book

Scala is a statically typed, Java Virtual Machine (JVM)-based language with strong support for functional programming. There exist libraries for Scala that cover a range of common scientific computing tasks – from linear algebra and numerical algorithms to convenient and safe parallelization to powerful plotting facilities. Learning to use these to perform common scientific tasks will allow you to write programs that are both fast and easy to write and maintain. We will start by discussing the advantages of using Scala over other scientific computing platforms. You will discover Scala packages that provide the functionality you have come to expect when writing scientific software. We will explore using Scala's Breeze library for linear algebra, optimization, and signal processing. We will then proceed to the Saddle library for data analysis. If you have experience in R or with Python's popular pandas library you will learn how to translate those skills to Saddle. If you are new to data analysis, you will learn basic concepts of Saddle as well. Well will explore the numerical computing environment called ScalaLab. It comes bundled with a lot of scientific software readily available. We will use it for interactive computing, data analysis, and visualization. In the following chapters, we will explore using Scala's powerful parallel collections for safe and convenient parallel programming. Topics such as the Akka concurrency framework will be covered. Finally, you will learn about multivariate data visualization and how to produce professional-looking plots in Scala easily. After reading the book, you should have more than enough information on how to start using Scala as your scientific computing platform
Table of Contents (16 chapters)
Scientific Computing with Scala
About the Author
About the Reviewer

Programming with Scala threads

Scala's threading API uses Java threads. In fact, the wrapper is very thin and they work almost exactly the same way that Java threads do. This is probably the most straightforward way of carrying out parallelism in Scala if you are already familiar with threading APIs in other languages. However, Scala also extends the Java threading API in numerous ways that make it even more convenient to work with. We will look into those ways in this section.

A simple Scala thread example

Let's see a very simple example of programming with Scala threads. The following is the simplest example I could come up with; however, it is also the one that manages to illustrate the most basic uses of the old Java threading model. The following example runs three threads, each of which gets a specific message to print a standard output. The threads are then run in parallel, each printing its message and pausing for one second between printing statements. This will continue until you...