Welcome to the inaugural ICHEC Coding Competition!!

ICHEC or the Irish Centre for High-End Computing is fully committed to supporting science and industry by the promoting use of advanced computational techniques. Today's research and innovation is heavily powered through numerical simulation, where advanced programming techniques are invaluable. Looking into the future, scientists and engineers with these skills will be in high demand.

By proposing this contest, we expect to attract the brightest young people (namely you, dear contender) and expose them to some basic High Performance Computing (HPC) programming techniques which can be applied throughout the whole scientific and engineering landscape. We have set an image processing challenge because it is both visual and fun, but ultimately, the codes are very similar to the ones seen across other domains of numerical simulation.

We hope you have as much fun solving the tasks below as we had putting it together!

The ICHEC Coding competition is open to all primary and secondary level students based in Ireland. The competition is divided into two phases. The first phase will introduce programming and lead students to think about optimised or parallel solutions. Students that are successful during the first phase will be invited to an event during Science Week to complete a challenge on ICHEC's new supercomputer. We're afraid that the number of entries to the second phase will be limited so please submit your code bundle as early as possible and make it clear how much of the challenge you were about to complete.

Getting help is encouraged and advisable. Your local CoderDojo will certainly be able to assist. We have also created a mailing list which will be used to broadcast important updates about the contest.

The top 50 entrants to the first phase of the competition will each receive a specially designed T-shirt.

Many Core Challenge: The top 50 from the first phase will then be invited to the new Supercomputer naming ceremony during Science Week 2013 and a challenge to port code to the Intel Xeon Phi or NVIDIA Tesla architecture will be set. Details of this challenge will be implemented in the coming weeks. After the challenge is complete the winner of the coding competition will be announced.

### ICHEC Project: Computer-aided design of controllable interfaces for nanoelectronics

For this coding competition, you will be asked to recreate some of the following effects using your own code.

Original
Grayscale
Blurred
Mirrored
Mangled

The original image above was taken from a real study by Dr. Damien Thompson from the Tyndall National Institute (Cork, Ireland). The image is snapshot from calculations run on ICHEC supercomputers (Stokes and Stoney). The tiche030b project performed Multi-scale, supra-nanoscale simulations to design of controllable interfaces for nanoelectronics. Supercomputing provided a rapid, reliable means of deciphering the atom-scale mechanisms by which organic molecules self- assemble on CMOS-integratable substrates. The tiche030b project set out to optimise the organic-substrate interface for developing new methods of functionalising graphene sheets and gold nanoparticles. This is crucial for the design of next-generation transistors and interconnects, which will provide components for the production of miniaturised, low-power, high-memory electronic devices for applications such as ultrasensitive medical diagnostics, environmental monitoring and perhaps petascale computing. Research papers published from this project can be found here.

ICHEC has put together a C++ code and input bundle to create the grayscale and blur transformations above starting with an 8-bit PPM colour image. As it is, it opens a PPM image, generates the corresponding grayscale PGM image, along with the corresponding blurred version of both. The code should be reasonably readable, but it has not been particularly optimised for performance.

The challenge is three fold, to create two additional transformations: mirror and mangled, followed by making the code run as fast as possible. Details of the three tasks are described further below and also in the README file of the bundle. The image used to test the performance of your submission can be downloaded by clicking on the original image above or here.

This code package is designed for Linux systems using the GCC compiler. It should compile in most environments, provided a decent C++ compiler is available, but we cannot provide instructions for every system. On a non-UNIX like system, where the function gettimeofday may not be available, we recommend compiling with OpenMP support activated. The rest of this page assumes a Linux system with a recent version of GCC (including C++ language support). Details of how to compile the code, execute the program, generate the documentation and create the file for submission are all in the README file. Some background information can be found further down the page

To generate a new coloured PPM image and a new grayscale PGM image, corresponding to the initial one transformed as if a mirror had been inserted vertically in its middle as shown here:

To generate a new coloured PPM image and a new grayscale PGM image, corresponding to the initial one transformed as if it had been mangled by squares of 10x10 pixels, rotated clockwise by a quarter more around from the previous one, as shown here:

To optimise both your code and the one provided for blurring images and generating grayscale versions for making them faster, without damaging too much their readability and cleanness.

When you feel ready to submit your code, fill the submission form called "SubmissionForm.txt" and type 'make ready'. If everything goes smoothly, this should create an archive file containing your sources, makefile and submission form, ready for sending.

If you have any problems with tasks outlined above we would be happy to help. Contact us on

Good luck!

Upon completion of the contest, we will grade the various contributions we receive. The marking will be as follows:

• For each of the two proposed exercise codes (mirroring, mangling) we will
• Check for correctness: your code will be compiled and run on our system, and the images produced will be compared to the reference ones.
• If correct, the code’s performance will be measured, using the large image provided here. Multi-threaded performance will be evaluated using 1, 2 and 12 threads (12 being the number of cores on our system), and only the best of the 3 times will be kept. The time retained will be the sum of the best time for processing the colour image and the best time for processing the grayscale image (allowing potentially a different number of threads used for the two).
• Then, if the performance reaches a threshold we consider sufficient, we will visually inspect your code for cleanness and readability.
In summary, to get marked, make it right, make it good enough, and make it clean.
• For codes with at least one of the two exercises valid, we will also evaluate the modified version of the grayscale and blur functions. The process for these ones will be performed the exact same way as for the mirroring and mangling functions (but of course for the grayscale function for which only one time is taken since no corresponding colour image is produced).
• Then the marking of each of the four correct codes will be:
• 50% of the mark for raw performance; and
• 50% of the mark for code cleanness and readability.
This marking is aimed for you to find the right balance of optimisation, without damaging too much the code’ readability.
• The final mark will be the weighted sum of the four individual marks. The weights are as follow:
• Grayscale: 1/8
• Blurring: 1/8
• Mirroring: 2/8
• Mangling: 4/8
The maximum mark being finally 100.

The following section has been compiled to give you the information needed to start you on your coding competition entry. If you have any queries not covered here, please feel free to contact us at:

The file formats that will be used in this coding competition are PBM, PPM & PGM. You can find more information on these image formats here

To convert a RGB image to a grayscale one requires us to use of the HDTV formula that is found on this page.

A Gaussian filter reduces noise or details within an image. The Gaussian filter used in our code bundle corresponds to the one found on the following wikipedia page.

To get started, we recommend using a computer running Linux or Mac OS X. If you have a Windows computer, you can try Linux without making any changes to Windows. You will need a USB memory stick with at least 2GB of free memory. We recommend using an empty 4GB stick if you have one. You might want to include some "persistent storage" on it (so you can save changes), which is an option in the installer.

To install ubuntu on the memory stick, follow this guide.

Then, to start ubuntu, follow these instructions (you might need to find out how to access the "boot menu", so that you can choose the USB drive when your computer is booting up).

Now that you have ubuntu, you will find many features similar to Windows. An important difference is the Terminal. You can access it from the Applications Menu (under Accessories), or you can use the "Ctrl + Alt + t" keyboard shortcut. This gives you access to the linux command line, which is a very powerful tool. Here, you can type commands which will be interpreted by a linux "shell" called BASH. You can find more information about the command line and bash online.

The next thing you will need is a text editor, so that you can write and change your "source code" and "scripts". Scripts are sequences of shell commands (i.e. Terminal or BASH commands) that are stored together in a file, making them easy to execute together. Source code is a sequence of lines of computer code, in some computer language, stored in a file. In the case of the C++ language, this code must be "built" into an executable file(s) that you can then execute from the shell. The README file in the competition source code package contains a description of the build process (the compile, link, execute workflow).

There are a wide selection of text editors available. Ubuntu comes with one called "gedit". Others include "kate", "leafpad", "gvim", etc. You can install them using the ubuntu software centre (see applications menu) and you can launch them from the applications menu, or from the command line (just type the word gedit and hit enter).

This challenge requires that a C++ compiler and the make program are available on your system. You will need to make sure these are installed using the ubuntu software centre. Tip: You can just type 'sudo apt-get install make gcc' at the command line.

A good software developer always documents his/her code. To generate the html documentation of our code bundle, please type

% make doc

Provided the package 'doxygen' is available on your computer, this will generate a comprehensive documentation of the code, available on your web browser by opening the file 'doc/html/index.html'.

The C++ language is extremely popular and widely used. It is fairly easy to get started with the basics, but it takes years to become a real expert. C++ includes the entire C language, and adds a lot of other stuff to it. For this competition, we only use the C part of C++, with one or two convenient extras. In other words, if you know basic C, that is enough to complete the competition. You can find some useful information to get you started here.

Building an executable file (program) from C++ code involves 2 steps (here is the classic Hello World C++ file (main.cc) contents):

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

1. Compiling: A compiler program is used to translate the source code you have written into instructions for the computer processor. It is much more difficult to write programs using the processor instructions directly, so compiled languages like C++ were invented to simplify this task. It is usually necessary to "include" some other source code files, which describe how your program can interact with other programs. Here is an example command to compile and execute the Hello World program:
% g++ -O3 -c main.cc -o helloWorld
% ./helloWorld

2. Linking: A linker program is used to establish the links between your compiled program and the other programs on the computer. This allows us to use libraries of programs, which have already been written to perform functions that arise frequently. The interaction methods described in the "include" files (in step 1) must match the libraries being linked, and they are usually provided together. Linking would look like the following if the print function was in a separate file to the main. Just requiring two files to be compiled and then linked.
% g++ -O3 -c printHello.cc
% g++ -O3 -c main.cc
% g++ -O3 -o printHello main.o printHello.o
% ./printHello


These steps, and perhaps others, are repeated each time the program is built. The make program provides a convenient way of capturing this repetitive build process, by storing the steps in a file, allowing us to execute them with one command.

Please follow the instructions in the README to build and run the program. Then, you can change the code, re-build it, and run it again to see the effect of your changes.

To compile or re-compile the code after modifications, just type

% make

You can adjust at will the compiler options by modifying the 'CXXFLAGS' variable in the Makefile.

If you change the code incorrectly, it will either fail to build or fail to execute correctly. If it fails to build, you will be given some information about what went wrong. Be careful, this information is sometimes misleading, because the computer does not know what you meant, but only what you actually typed. If the code fails to execute correctly, you will see an error message, or a problem with the results.

If your code builds without problems, but does not do what you expect it to, then the code has "bugs" or mistakes in the logic. Debugging is the process of finding and fixing bugs. Often, it can be as simple as printing out some values to check if they are correct while the code is running. This method has many limitations though, and more advanced tools are available. You can find more information on debugging here.

Finally, when you want to submit your code you'll need to generate a solution package, type

% make ready

Most modern computers contain multi-core processors. These processors contain a number of processing units (cores), each of which can execute programs independently, but shares memory (RAM) with the other CPUs. One way to speed up an application, is to split it up into independent sub-programs, called "threads", and run them simultaneously on different cores. In many cases, it is not possible to have completely independent threads, because one of them may calculate a result that the others depend on. This "data dependency" can be resolved using the shared memory, where the threads can share data. Often, the threads are identical, except that they each operate on different chunks of data. OpenMP is designed to make this type of "multi-threaded programming" easier. To use it, the programmer provides a small amount of extra information to the compiler, explaining how the work can be divided, and what data needs to be shared. This information is inserted into the code in "#pragma" statements. Each thread is assigned a separate ID when the code is executed, allowing the programmer to dictate which data it will work on.

Many OpenMP tutorials, and other resources, are available online. We encourage you to try this as a way to improve your code's performance. When we evaluate your code's performance, we will take the best result from three tests, using 1, 2 and 12 threads respectively.