How to run MIT 6.172 OCW Code

4 minute read

Published:

Context

I noticed that the code provided with the open-sourced course 6.172 - Performance Engineering on MIT OpenCourseWare doesn’t compile and there aren’t very clear instructions on how to get the toolchain with the Cilk multithreading library and X11 graphics working for the projects. Hopefully, this guide helps answers those questions and lets people get started quickly!

Local devenv with Docker (the easy way)

The easiest way to get up and running code is to follow the setup instructions at https://github.com/peterg17/6.172. This repo includes a Dockerfile and only requires that you have Docker and an X11 client like XQuartz for MacOS. This has only been tested on MacOS.

If you want to run reliable benchmarks and avoid noisy neighbors to more of an extent than on your personal machine, you may want to use an ec2 instance for performance testing jobs.

EC2 instance setup (the slightly harder way)

To provision and setup an ec2 instance for development, you can follow these (hopefully detailed enough) steps:

  1. click launch instance on the ec2 landing page
  2. create a t2.micro (or size of your choice) instance with the “Ubuntu, 16.04 LTS, amd64” AMI.
    • you can always upgrade the instance type, but we are starting off very small to save $ and because our goal is to simply get the course code running :)
    • make sure to create a new keypair and save the .pem file to your local machine, you will use this to ssh in
    • make sure to click the “Allow SSH traffic” button in network settings
    • in the “configure storage” section, set the root volume to have 30 GB of storage, since that’s the max of the free tier

Dependencies

Now login to your newly created instance using the ssh command: ssh -i <keypair path> ubuntu@<instance IP> Where the instance IP is the IP address under “Public IPv4 address” in your ec2 instance config. For instance: ssh -i peter-test-keypair.pem ubuntu@55.222.77.111.

Note: you might get the following scary warning:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'peter-test-keypair.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "peter-test-keypair.pem": bad permissions
ubuntu@54.227.77.114: Permission denied (publickey).

In this case, you simply must run chmod 400 keypair.pem with your actual keypair name to change the permissions so that all users/groups can read the keypair.

First, we will get the source code for one of the projects. Here I am using project 2 because it uses all of the dependencies we need to display a fully functioning devenv: cilk, the rest of the clang toolchain, and X11 graphics.

  • Download zip to project 2:
    • curl -L -o project2.zip https://ocw.mit.edu/courses/6-172-performance-engineering-of-software-systems-fall-2018/e73f8fc30a609509b847f708815a72c0_MIT6_172F18-project2.zip
    • sudo apt-get install unzip
    • unzip project2.zip
    • you should now have the contents of the zip under a folder called MIT6_172F18-project2
  • Install clang toolchain w/ CILK
    • credit: the steps to get the clang toolchain w/ CILK is from https://github.com/mattfeng/batch-scrimmage/blob/master/awsbatch/Dockerfile, thanks!
    • cd MIT6_172F18-project2
    • sudo apt-get install make emacs
    • sudo apt-get install software-properties-common
    • sudo add-apt-repository -y ppa:wsmoses/tapir-toolchain
    • sudo apt-get update
    • sudo apt-get install -y tapirclang-5.0 libcilkrts5
    • sudo apt-get install -y build-essential clang
  • If you try running make now, you might notice the following error:
    ubuntu@ip-172-31-27-25:~/project2/MIT6_172F18-project2$ make
    clang -std=gnu99 -Wall -ftapir -O3 -DNDEBUG  -o intersection_event_list.o -c intersection_event_list.c
    clang: error: unknown argument: '-ftapir'
    

    This is because we are using the standard version of clang and not the one with cilk. You notice above that we install tapirclang-5.0 so we should modify the Makefile to use clang-5.0 instead of the clang in our path which on my machine is clang version 3.8.0-2ubuntu4.

  • Modify the following line of Makefile:
    • Instead of CXX = clang, use CXX = clang-5.0
    • Instead of CXXFLAGS = -std=gnu99 -Wall -ftapir, use CXXFLAGS = -std=gnu11 -Wall -fcilkplus

X11 graphics

  • If you try running make at this point, you might hit the following error:
    ././graphic_stuff.h:28:10: fatal error: 'X11/Xlib.h' file not found
    #include <X11/Xlib.h>
    

    This is because we need x11 sources and other tools which we can get with:

  • sudo apt-get install x11-apps
  • sudo apt-get install libx11-dev
  • sudo apt-get install xorg-dev