Code makes the world a better place

NCTU Observations and Reflections (2): First-Year Master's (Spring) — Coursework

Preface

This semester felt like the happiest semester I have had in the past two or three years. It was fulfilling: I took four courses, still participated in the Fine Arts Club, wrote quite a few posts, and found a research direction and topic. Studying CS really is a joyful thing. Broadly speaking, my M1 spring can be divided into three parts: coursework, the Fine Arts Club, and research. This post focuses on coursework.

Continue reading

Converting Pthreads to JavaScript with Emscripten and Performance Analysis

Introduction

Emscripten is a tool that compiles C/C++ to WebAssembly. Under the hood it goes through LLVM. It supports compiling Pthreads: it turns them into JavaScript Web Workers plus WebAssembly. It can even translate OpenGL to WebGL, allowing programs to run in a browser with performance close to native.

The focus of this post is exactly that: converting Pthreads into Web Workers + WebAssembly. I will take an example program and try the conversion in practice. Finding a good benchmark program is not easy, so I wrote a small parallel Pthread program to compute π as the test case.

I will first walk through how to use Emscripten to convert Pthreads to JS. While following the official documentation, I ran into several pitfalls; I also record them here so you don’t fall into the same holes. Then I will compare performance for (1) native C code, (2) Emscripten-generated JS/WASM, and (3) a Web Worker implementation written directly in JavaScript.

Continue reading

Installing and Running SPEC CPU 2006

Preface

SPEC CPU is a CPU benchmark suite created by The Standard Performance Evaluation Corporation (SPEC). Recent suites include SPEC CPU 2006 and SPEC CPU 2017. Because of its strong credibility, many research projects use it as an evaluation benchmark.

If you want to obtain this suite, you cannot find it freely on the Internet—you need to purchase it from SPEC, and it is expensive. In practice, if you need it, you often have to find a copy through your lab or collaborators. Recently I needed to reproduce a paper that uses SPEC CPU 2006/2017. Our lab happened to have the 2006 version, but there are many “gotchas” in the process, so I’m recording them here.

Continue reading