# Prerequisite test

The prerequisite test is now open and it closes on 17 April 2020, at noon. The test will make sure you can write C or C++ programs, and it will also check that you are comfortable with the idea of using Git and GitHub, logging to Linux computers through ssh, and developing and testing code there.

To pass the test, just follow the instructions on this page. The programming task is supposed to be very simple, you do not need to do anything clever, but please read the instructions carefully to make sure you do not miss any of the required steps.

In brief, you need to write a function that takes as input a bitmap image and the coordinates of a rectangle, and it has to calculate the average color of all pixels inside the rectangle.

We have already defined the following type for storing the result:

struct Result {
float avg[3];
};

You need to implement the following function:

Result calculate(int ny, int nx, const float *data,
int y0, int x0, int y1, int x1)

Here data is a color image with ny*nx pixels, and each pixel consists of three color components, red, green, and blue. In total, there are ny*nx*3 floating point numbers in the array data.

The color components are numbered 0 <= c < 3, x coordinates are numbered 0 <= x < nx, y coordinates are numbered 0 <= y < ny, and the value of this color component is stored in data[c + 3 * x + 3 * nx * y].

The parameters y0, x0, y1, and x1 indicate the location of the rectangle. The upper left corner of the rectangle is at coordinates (x0y0), and the lower right corner is at coordinates (x1-1y1-1). That is, the width of the rectangle is x1-x0 pixels and the height is y1-y0 pixels. The coordinates satisfy 0 <= y0 < y1 <= ny and 0 <= x0 < x1 <= nx.

In the result that you return, avg[c] has to contain the arithmetic mean of the color component c for all pixels inside the rectangle.

Even though the input and output are single-precision floating-point numbers, you must do all arithmetic with double-precision floating point numbers, and only round the final result back to single precision.

You can assume that there are at most 10 million pixels in the input image.

You do not need to worry about the performance. The most straightforward implementation that you can imagine should be certainly fast enough. We provide an automatic grading tool, and if the grading tool is happy with the performance, it is fine.

### Step 1: GitHub setup

First, create GitHub user account if you do not have one yet. Log on to GitHub. If you have multiple GitHub accounts, choose the one that you want to use for all of our course activities. In what follows, your-account refers to your own GitHub user account. If you open the page https://github.com/your-account in the web browser, it should show your GitHub profile, something similar to this.

In GitHub, use the import function to create a new private repository that contains the same files as https://github.com/cs-e4580-2020/prereq. Please select the following settings:

• Your old repository’s clone URL: https://github.com/cs-e4580-2020/prereq.git
• Your new repository details / Owner: your-account
• Your new repository details / Name: ppc-2020-prereq
• Your new repository details / Privacy: private

This should create a new private Git repository called ppc-2020-prereq. If you go to https://github.com/your-account/ppc-2020-prereq with a web browser, you should see the files there. And if you go to the same URL in the incognito mode without logging on to GitHub, you should not see anything, as the repository is private.

### Step 2: Write code on Maari computers

Next, use ssh to log on to one of the Maari Linux computers that we are using in this course. For example, to log on to computer dodo from your own personal computer, you would use something like this:

ssh your-aalto-user-name@kosh.aalto.fi
ssh dodo

On Maari computers, create a clone of your Git repository ppc-2020-prereq, e.g. in your home directory. To keep it simple, you can do it with HTTPS as follows:

git clone https://github.com/your-account/ppc-2020-prereq.git

But a better approach is to configure ssh key pair authentication and then clone the repository using ssh, as follows:

git clone git@github.com:your-account/ppc-2020-prereq.git

Either way, you should now have a new directory ppc-2020-prereq in your home directory, and this is the local working copy of the Git repository that you just created.

In the repository, you will find the file average.cc that you are supposed to edit. Please write your solution there. Do not edit any other files! Here is how you can open the right file for editing in nano, which is a very simple text editor, but any other means of editing the file is of course fine:

cd ppc-2020-prereq
nano average.cc

Once you are happy with your solution, you can try to run the grading tool to make sure your solution is correct — no worries if it does not work directly, you can try as many times as you want:

The grading tool will try to compile your code and run some tests and benchmarks. You should get a clear error message if something goes wrong. Fix your code if needed, and run the grading tool again.

Once your code works correctly, the grading tool will create a file submission-0.txt. Add both submission-0.txt and average.cc to Git, commit the change, and push to GitHub, e.g. as follows:

git commit
git push

Note that git commit will open a text editor for entering the commit message, unless you specify it on the command line. The default editor at the moment is Joe, but you can change it by adding e.g. the following lines to your ~/.profile file:

export EDITOR=nano
export VISUAL=nano

### Step 3: Submit your solution

If everything went well, open https://github.com/your-account/ppc-2020-prereq with a web browser, and double-check that both the right version of average.cc with your implementation there, as well as the file submission-0.txt that was created by the grading tool.

Currently nobody else can see your code. To let the course staff see your submission, please invite the GitHub user suomela as a collaborator to your private repository ppc-2020-prereq, following the instructions here — read access is sufficient.

Finally, go to the Assignments page in MyCourses, open the assignment PPC 2020 prerequisite test submission, and fill in the URL of your GitHub repository there. You only need to write there https://github.com/your-account/ppc-2020-prereq, and then you are done.

If at any point you realize you have made a mistake, you can always start from scratch. Just delete whatever is wrong and try again. You can resubmit to MyCourses, we will only look at your latest submission.

### What happens next?

Nothing happens immediately. If you solved the test before the first lecture, you can just wait and relax a bit.

We will process prerequisite test submissions in batches, starting a bit before the first lecture. We will announce in our Slack on channel #prereq whenever we process a batch.

Once we have processed your submission, you should receive an invitation by email from GitHub to join the GitHub organization cs-e4580-2020, and then you are ready to start to solve our exercises. Please see information on our workflow and especially Git information for more details.

### Questions?

Please use the channel #prereq in our Slack chat if you have any questions about the prerequisite test.