The Community for Technology Leaders


Pages: pp. 6-9

Abstract—In this issue's column, the reviewed books offering guidelines for using Matlab and an introduction to graphics processing units.

Keywords—Scientific programming, Matlab, graphics processing units, CUDA environments, parallel computing, scientific computing

No Room for Filler: Large Content, Small Book


Richard K. Johnson, The Elements of Matlab Style, Cambridge Univ. Press, 2011, ISBN: 978-0-521-73258-1, 169 pp.

Programming was once described to me as being similar to an art form, where a programmer sitting in front of a computer with a problem was likened to an artist with a blank canvas and an idea for a painting. Just as there are many ways to fill the canvas with paint, there are as many ways to write a valid program to solve a problem. However, in spite of the inherent flexibility in programming, there are some base guidelines that should be followed. The guidelines strive to ensure that code will be readable, easy to maintain, trustworthy, and improvable. Richard K. Johnson's The Elements of Matlab Style collects these guidelines into a single book.


This is a complete, well-organized book detailing guidelines for programming in Matlab. It targets both new and experienced Matlab users. The first four chapters are easily accessible, while the last three require programming knowledge beyond what a beginner might have. Regardless of the programming expertise, this is a great reference for any bookshelf.

You might think that a book of guidelines would contain only ways to use Matlab's commands and capabilities to produce well-written code. Although this book contains tips to accomplish that, a look at the table of contents reveals that this book contains information valuable to programmers of all languages. The largest chapter addresses designing code, but other chapters address formatting code, naming identifiers, organizing files, developing code, and—my favorite—creating documentation. The reach of the book's guidelines is outstanding; every base is covered. The documentation chapter not only explains what you should document in code, but also when, how, where, and why.


The Elements of Matlab Style begins with a short introduction and first chapter that explain why guidelines on programming style are necessary. Among other reasons, the most important from my perspective is to increase code readability. In particular, I found the guideline entitled "Help the Reader" especially powerful. It encourages you to use the guidelines to help the people who read your code understand it, even if you're the one reading your code. On many occasions, I've returned to some code that I wrote, only to struggle with why I had written the code that I did.

Chapter 2 discusses how to use spacing within code to increase readability. I'm a big proponent of spacing within lines and aligning between lines of code; such guidelines are generally used to enhance the code's aesthetics. Chapter 3 discusses conventions for naming identifier types, as well as when to use lower- and uppercase letters. Several things struck me while I read this chapter, including the explanations on why conventions are used. For example, the author explains that beginning a variable with a capital indicates a structure in other languages. The chapter contains a lot of other information as well, including naming conventions of variables, functions, constants, and structures.

As mentioned earlier, Chapter 4 covers documentation. I particularly appreciated the guidelines encouraging end-of-loop comments and the use of header comments. As might be expected, the largest chapter in this book lists programming guidelines. Chapter 5 discusses well-structured Matlab code and also contains many tools of the trade. Two good examples of this are the guidelines to avoid using global variables and to not directly compare floating-point variables with equality.

The book's last two chapters deal with file and directory structure and how to approach actually writing Matlab code. I particularly enjoyed the discussion on how to integrate help pages within the standard Matlab help menu. The development chapter is devoted to various approaches to creating Matlab code that allows for ease-of-use by others and can be generalized to other related problems. The guideline to write code that doesn't require user input during execution was something I didn't agree with years ago, but have come to appreciate since.


This book excels in the use of Matlab code snippets to illustrate the guidelines; it's generally tough to explain in a sentence format the guidelines described in this book. The book's organization is another positive. Not only are the chapters explicitly titled, but the subheadings within each chapter further divide the guidelines into specific categories. The amount of material in this small book is amazing. Regardless of programming experience, everyone will learn something new from this book. There were many commands that I learned from reading this book (such as the publish command).

A minor deficiency of this book is that chapter subsections aren't listed in the table of contents. I'd also appreciate an accompanying website with Matlab code to illustrate most of the book's guidelines.

Richard K. Johnson obviously draws on years of experience in writing Matlab code. Many of these guidelines I had to learn on my own; I wish I'd had the opportunity to read this book years ago. In the future, I'll encourage my students to read the first four chapters of this book. This is an excellent reference book and anyone interested in programming would be wise to follow its advice.

David Szurley is an assistant professor of mathematics at Francis Marion University. He has nearly 15 years of experience with Matlab, and his current research focuses on applying nonlinear optimization algorithms to equations modeling fluid motion. Szurley has a PhD in mathematics from Clemson University. Contact him at

Teaching Yourself CUDA: Learn to Walk While You Run


John Sandres and Edward Kandrot, CUDA by Example: An Introduction to General-Purpose GPU Programming, 1st ed., Addison Wesley, 2010, ISBN: 978-0-13-138768-3, 290 pp.

You've probably heard and read everything about graphics processing units (GPUs) and how Nvidia's introduction of the CUDA environment a few years ago has unleashed the power of these massively parallel devices for general purpose computing. Some people still might fear that GPU programming could be a frustrating experience or come with a steep learning curve.

This book should assuage such fears. It's an excellent entry point to programming in CUDA that will have you quickly installing it and writing and running codes. Even if you're merely curious about GPUs and what they can do, how useful they could be in your work (or hobby), and are hesitant whether to embrace them or not, with this book you should be able to rather quickly answer these questions and discern whether you want to take your CUDA programming to the next level. I don't mean to imply that the authors rush you into it, but instead that they are really effective.

The book is written by two members of Nvidia's CUDA software team, and is an excellent companion to Nvidia's CUDA documentation. It focuses on CUDA C—as opposed to, say, CUDA Fortran (—and assumes only basic familiarity with C or C++ (it would probably be a bad idea to try to teach both C or C++ and CUDA). No knowledge of parallel programming or concepts is needed or assumed. There's one exception with respect to "prerequisites" other than some knowledge of C: the chapter on graphics interoperability (graphics rendering intertwined with general purpose computing) required knowledge of a graphics API such as OpenGL. Although knowledge of OpenGL might seem at odds with the idea of an introductory book on general purpose GPU programming, I think it's a good decision to include it as it will benefit many graphics programmers. Also, as the authors indicate, subsequent chapters don't depend on it, so there's no harm in skipping it.

If you browse the book's table of contents and chapter names such as "Advanced Atomistic" seem intimidating, don't worry. (On the other hand, if you're a more experienced programmer and can half-guess what such chapters will explain, you'll most likely still find valuable information). The authors provide a high-level description of how different aspects of GPUs and CUDA work, while at the same time walking you through specific code examples and teaching how to actually implement things. The code snippets are carefully chosen and to the point. All the source code is available from the book's webpage, which also lists errata (a feature that appears to be regularly updated). The code examples were developed on Linux and Windows platforms, but the authors state that they should work without modification on Mac OS X systems.

The book is extremely clear, and provides a most enjoyable read. It has the pedagogical style of a textbook, though it is one that you would use to teach yourself CUDA. If used as a textbook, the book will have to be supplemented with exercises, as there are none in the current edition. The tone is cheerful, with the right amount of casually dropped and humorous comments. Each chapter starts with an "Objectives" section and ends with a concise summary, driving home the key points without resorting to a "for dummies" style.

The last chapter briefly mentions a few CUDA tools, including versions of fast Fourier transform, basic linear algebra subroutines, debuggers, profilers, and wrappers to other languages such as PyCUDA. This chapter mostly serves as a pointer to those resources.

With the recent advances in GPU computing, there was a great need for a book of this scope, and it excels in its very precisely delimited goal. It's a must-have for anyone interested in an introduction to CUDA programming, or even anyone who's simply curious about it. And its price is simply unbeatable (as of this writing, $25 from Amazon).

About the Authors

Manuel Tiglio is an assistant professor in the Center for Scientific Computation and Mathematical Modeling and the Physics department at the University of Maryland, where he is a member of the Maryland Center for Fundamental Physics and a junior fellow of the joint NASA Goddard-UMD Joint Space Science Institute. For a long while his research has focused in computational general relativity and large-scale simulations of black holes, with broad interests in scientific computing and algorithms in general. Contact him at
53 ms
(Ver 3.x)