<<

CSE341T/CSE549T Homework 0 Assigned: 08/25/2014 Due Date: 09/08/2014

This document contains important information that you will need to complete and turn in every assign- ment for CSE 341.

1 Overview

Each homework consists of a written portion and the coding portion. The written portion should be turned in in class on the day the homework is due. The coding portion should be checked into your repository before class on the due date. This handout explains the coding mechanics. The coding portion of this course will be managed accordingly:

• all code will be written in Plus, a parallel version of ++ • all code will be graded by an auto-grader • all code will distributed and submitted exclusively via svn • you will need to use the command line to check out, complete, and submit your code

This document will explain a little bit more about each of these aspects of the course. However, rather than giving you an isolated, abstract tutorial on using the command line, the rest of this document will simply be written in the context of using the command line.

2 Cilk Plus

Intel R CilkTM Plus (see also http://cilkplus.org) is a parallel extension to C++ that we will use to explore the serial and parallel running times of algorithms in the context of multicore and manycore processors. Cilk Plus supports a handful of new keywords (most importantly: cilk spawn and cilk sync) that provide a simple yet surprisingly powerful model for parallel programming.

2.1 Compiling and Running Cilk Plus Programs

Your code will only compile on a machine that has an the appropriate compiler installed. At this point, we have installed the Cilk Plus compiler on the machines in the linux lab in Lopata 400. You can physically go into the lab (which we recommend), or remotely ssh into shell.cec.wustl.edu, which is likely to be shared by multiple people, so we don’t recommend doing timing related tasks using this method. One could also remotely ssh into one of the machines in the linux lab, which we will describe how in Section4. Because Cilk Plus is not (yet!) a standard , it is not supported by common integrated development environments (IDEs) such as . This is why you will need to become familiar

1 with the command line for this class. That said, using the command line is an important rite of passage for anyone who claims to be a computer scientist, so if you haven’t done it yet, it is about time! Once you are on one of the machines in linux lab, in order to compile and run a Cilk Plus program, you will need to update your environment variables to include the version of gcc that supports Cilk Plus as well as the Cilk Plus dynamic runtime libraries. You only have to take the following steps once, and you’ll be set.

1. Determine what shell is running when you log into cec. Do this by typing: > echo $SHELL at the command line. If you see something ending in tcsh (e.g., /usr/bin/tcsh), goto Step 2. If you see something ending in bash (e.g., /usr/bin/bash), goto Step 3. If you see neither of these, seek help. 2. Add the following line to a file called .cshrc.mine source /cluster/engine/cilk/setup-cilk.csh

3. Add the following line to a file called .bashrc source /cluster/engine/cilk/setup-cilk.sh

3 SVN

We will use subversion (see also http://subversion.apache.org) to distribute assignments. Each assignment will have a written portion and a coding portion. The written portion is to be submitted in hard copy in class on the day the assignment is due. The coding portion is to be submitted via svn before class on the day the assignment is due.

3.1 Your SVN Repository

Each student in the class will be given their own svn repository, which is accessible only by you, the instruc- tor, the TAs, and a few technical support folks in the department. As is standard in the CSE Department, your repository name will be of the form wustlkey. When you are prompted for a username and password in order to access this account, you should provide your wustlkey username and associated password, not your cec username and password! The most recent checked in version of your repository can always be viewed (by those with permission!) on the web at the URL (depending on which class you are registered to: https://shell.cec.wustl.edu:8443/cse341_fl14/svn/wustlkey/, or https://shell.cec.wustl.edu:8443/cse549_fl14/svn/wustlkey/.

This is the version of your code and assignment that the instructor and TAs will see when they grade your assignment. After you submit your homework via svn, it is a very good idea to check out this URL and make sure that everything looks up to date. It is your responsibility to make sure that you submit your homework both punctually and successfully. One of the two is not sufficient.

2 3.2 SVN Checkout

The first step is to check out your subversion directory. To achieve this you need to use the svn checkout command (or svn co, for short) in the following steps:

1. Create a directory (we’ll call it cse341) on one of the departmental cec unix machines (e.g., grid.cec.wustl.edu and shell.cec.wustl.edu) for cse341: yourhome> mkdir cse341

2. Enter said directory yourhome> cd cse341

3. checkout your repository yourhome/cse341> svn co https://shell.cec.wustl.edu:8443/cse341_fl14/ svn/wustlkey/

This will create a directory inside cse341 called wustlkey. If you go into this directory: yourhome/cse341> cd wustlkey and look at what’s inside: yourhome/cse341/wustlkey> ls hw00 you will see the directory hw00. This directory contains the files needed to complete the coding portion of the this assignment.

Aside: to return to the directory 1 higher up, simply type: yourhome/cse341/wustlkey> cd ..

, where the .. means the parent directory.

3.3 SVN Commit

Its a good idea to commit your code at regular intervals. Svn can be a backup for you as well as a way to turn in your assignment. For example, when you finish coding up a distinct portion of the assignment, you might commit a working version of your code with the comment: yourhome/cse341/wustlkey/hw01> svn commit -m ’’naive version working’’

When youre completely finished, make sure to commit again: yourhome/cse341/wustlkey/hw01> svn commit m ’’finished HW1’’

Note that the -m flag allows you to specify a commit message. Alternatively, you can set the environ- ment variable SVN EDITOR to specify a default editor (e.g., /usr/bin/vim and /usr/bin/emacs):

3 yourhome/cse341/wustlkey/hw01> export SVN EDITOR=/usr/bin/vim (if you use bash), or yourhome/cse341/wustlkey/hw01> setenv SVN EDITOR=/usr/bin/vim (if you use tcsh).

Then, when you commit without the flag, svn will bring up a buffer using your default editor, which al- lows you to write a longer commit message.

3.4 SVN Add

If you create any new files inside an svn managed directory, they will not be automatically added to your svn repository. This is a good thing, since it keeps your repository from being filled with executables, .o, and ˜ files that you might generate while running and editing your code. That means, if you ever create a new file that you want to submit, you will need to explicitly add and commit it to your repository. We mention this capability for completeness only. In this course, it is not be expected that you will be creating new files in order to finish assignments. Unless you are told explicitly otherwise, you should really not need to use this command for this course.

3.5 SVN Status

Another handy command to know is svn status which tells you the status of the files that svn is tracking. Let’s say you have edited the file student solution.cpp and compiled the program (which causes an executable named fib to be created). If you check the status of your repository at this point: yourhome/cse341/wustlkey/hw01> svn status ? fib M student solution.cpp

, which means that the file fib is not been tracked by svn at the moment and that student solution.cpp has been modified.

3.6 SVN Revert

Sometimes, it’s handy to be able to discard your changes. Since svn is a version control system, it actually stores all the older versions of code that you committed in the past. If you modify a file and want to discard the changes and not commit them, you can use the revert command to restore the file back to the most re- cently committed version: yourhome/cse341/wustlkey/hw01> svn status ? fib M student solution.cpp yourhome/cse341/wustlkey/hw01> svn revert student solution.cpp yourhome/cse341/wustlkey/hw01> svn status

4 ? fib

3.7 SVN Update

At the beginning of the semester, your repository will contain only hw00. As the semester progresses, we will add new homework directories to your repository. In order to see the newly added directories, you will need to perform an svn update: yourhome/cse341/wustlkey> ls hw01 yourhome/cse341/wustlkey> svn update yourhome/cse341/wustlkey> ls hw01 hw02 yourhome/cse341> 

3.8 SVN Help

We encourage you to explore other functionalities supported by svn. To see what other commands are supported, use svn help. Moreover, you can see the help message for a specific command. For example, to understand the output of svn status in more details, consult svn using svn help status.

4 VPN

If you are not on the engineering school network when you are doing your homework, you will find that you cannot log into the machines in the linux lab (lop400-.cec.wustl.edu, where can be any number between 01–30). In order to do so, either you must first log into shell.cec.wustl.edu and then from there ssh into lop400-. Or you can use our virtual private network. This section will explain the use of VPN.

1. If you don’t have it already, download Cisco VPN Client (instructions from EIT here https: //engineering.wustl.edu/eit/vpn.aspx — if you have issues with EIT’s provided in- staller, try getting Cisco’s AnyConnect Client from a 3rd party website, or contacting EIT.

2. In the VPN client, enter cecvpn.seas.wustl.edu as the server address.

3. When prompted by the VPN client, enter your cec username and password.

4. You should now be connected to the VPN network and can log directly into one of the lop400- machines.

5 5 The Auto-Grader

Your code will be graded by an auto-grader. You will be explicitly told which methods to complete / modify. The auto-grader will make a copy of the specific file containing those methods from your repository, and compile it with the rest of the provided code. Thus, you should not in any way modify any of the other parts of the provided code, except for the body of the methods that we asked you to modify / complete, without checking with an instructor first. Your code will also be tested on new inputs that you will not be given access to.

Things not to do: If you do any of the following, you are likely to break the auto-grading and cause the auto-grader to either fail to compile your code, or misinterpret your output, and you will not receive credit for your work.

• Rename methods: if we ask you to complete the method qsort(), the auto-grader will look for a method called qsort(). Renaming it will cause the compilation to fail when the auto-grader tests your code.

• Change the signature of methods: similarly, changing the function signature, such as its input type or return type, will cause the auto-grader to fail to compiler your code.

• Modify helper code: we will give you a lot of helper code for each assignment. If you modify / add to the helper code and subsequently invoke the modified / added methods from the method that we ask you to complete, your code will fail to compile during auto-grading, because the auto-grader will test your code with the original helper code.

• Litter your code with print statements: yes, a few print statements can be a very helpful thing, while you are coding and debugging. Extra printed statements not anticipated by auto-grade can cause the auto-grader to misinterpret your result. Too many print statements can also cause the program to run slowly, leading to time-out during the auto-grading process. If you want to include print statements in your code for debugging purposes, it’s a good practice to put them inside a debug flag that can be turned on and off:

#define DEBUG MODE 1 #if DEBUG MODE print something here #endif

And you should turn off the debugging flag (i.e., define the DEBUG MODE to be 0) before you submit your code. This trick (using #define) is also effective for timing purpose, because when you set the DEBUG MODE to 0, the statements surrounded by the if DEBUG MODE and endif will not be compiled into your executable, which allows you to get more accurate timing. If you instead tested a Boolean variable,

6 even when the variable is set to false, the if statement that tests the Boolean variable will be executed and slow down your code.

Important! Ten million print statements will really annoy any instructor or TA who decides to run your code. It can also bring down the machine that the auto-grader is running on. True Story: in another CSE class shall remain un-named, one student who shall also remain un- named forgot to remove debug print statements. When the said code was run, it created an output file on the order of terabytes in size, which took down the entire file system and brought the machine to a screeching halt. Let’s just say ... this story didn’t end well for the student.

Please be mindful about the fact that your code is tested by an auto-grader and be careful with what you modify in the code that you plan to submit. When in doubt, ask ahead of time whether a change you are making is acceptable.

6 The Task to Complete for Homework 0

Now, we are ready to get to the specific task that you need to complete for this particular assignment. The task is simple, and designed to ensure that you have your coding environment set up and that you learn how to use the various tools that we will use in this class. Once you have obtained your code base via svn, you will see hw00 directory under the directory named with your WUSTL key. Inside the hw00 directory. you should see three files: Makefile, main.cpp, and student solution.cpp. The file student solution.cpp contains the methods that you should modify. For this assignment, complete the following steps:

• Compile your code by typing make. You should see a compiling error. Fix the compiling error, and compile again.

• Once your code compiles, you should see a binary called fib created. Run the code (with make run or .\fib), and it should print results of computing Fibonacci 1–10 and a statement that says “Cilkview reports ‘Entries to parallel region’ = 0.” Cilkview is a tool that we will be using in this class. It measures and reports various data re- lating to parallel computation, and you will learn in class how to interpret the data. Type make cilkview (or equivalently, cilkview ./fib) to run the executable under Cilkview, and modify the entries to par region in student solution.cpp to return the value of “Entries to parallel regions” reported by Cilkview. The reported value on “Entries to parallel region” basically counts how many “top-level” function invocations that contains parallel computation that Cilkview encounters during execution. Think about why Cilkview reported the particular value you see.

• Commit your changes to student solution.cpp to the repository.

7