A Practical Guide to Parallelization in Economics∗ Jesús Fernández-Villaverdey David Zarruk Valenciaz April 22, 2018 Abstract This guide provides a practical introduction to parallel computing in economics. After a brief introduction to the basic ideas of parallelization, we show how to paral- lelize a prototypical application in economics using, on CPUs, Julia, Matlab, R, Python, C++–OpenMP, Rcpp–OpenMP, and C++–MPI, and, on GPUs, CUDA and OpenACC. We provide code that the user can download and fork, present comparative results, and explain the strengths and weaknesses of each approach. We conclude with some additional remarks about alternative approaches. Key words: Computational Methods, Parallel Computing, Programming Languages. JEL classifications: C63, C68, E37. ∗The pdf file of the paper includes several embedded links of interest. The Github repository of the code used in the paper is: https://github.com/davidzarruk/Parallel_Computing. We thank many cohorts of students at the University of Pennsylvania who have endured earlier drafts of the slides behind this guide and pointed out ways to improve them. yUniversity of Pennsylvania. Email:
[email protected] zUniversity of Pennsylvania. Email:
[email protected] 1 Contents 1 Introduction4 2 Why Parallel?7 3 What Is Parallel Programming? 10 4 When Do We Parallelize? 12 4.1 An application where parallelization works: Value function iteration..... 13 4.2 An application where parallelization struggles: A random walk Metropolis- Hastings...................................... 15 4.3 The road ahead.................................. 18 5 A Life-Cycle Model 18 6 Different Computers 23 7 Parallelization Schemes on CPUs 25 7.1 Julia - Parallel for ............................... 26 7.2 Julia - MapReduce ................................