Exercise 2 - Compiling, running, debugging and more ...

General Information


Some things will be very important in this discipline and especially in your career in computing. You must know how to compile bem a program, to execute it in a practical and automated way, to debug it, to know which part of it is slower and to have notions of parallelization.

Before you start

This lab is based on GNU tools which are already installed on Linux but which can be installed on Windows and Macs as well.

You must answer these questions:

  1. How to specify the optimizations that a compiler should use in a program?
  2. Which optimizations are important for the processor you are using?
  3. What is the difference between a Makefile and a script?
  4. What is "debugging a program"?
  5. How to run GDB?
  6. How to use a graphical environment with GDB?
  7. How to find the part that is most executed in a program?
  8. How to use gprof?
  9. How to make a program take advantage of scalable multiprocessing?

In the end, you should be able to use these tools and also differentiate performance gain alternatives obtained by algorithms and also by tools.


One of the first MP3 compressors / decompressors created is called dist10, you should find a file named dist10.tar.gz on the internet and download it (in the tests below, focus only on the files inside the folder lsf / encoder). For testing, use a large .wav file, such as this (you can use others if you want).

Now follow the activities below, writing down the information and decisions you will need to make to make your report at the end.

To do the next activity you must understand the applications configure e make.

Compile the program without any extra options for extra compilation. How long does it take to encode the file? See if the value changes using, separately, each of the optimizations -O0, -O1, -O2 -O3 (capital letter O followed by a number). Which one gave the best time? There are other optimizations that you can apply to the current processor, see the gcc by category optimizations -mtune and see which ones apply to your processor. What are they for? Has the weather improved?

Now it's time to try to understand the program a little (but not entirely). Use GDB to debug your program. Often, the GDB text mode interface makes debugging difficult, I recommend that you use a graphical viewer for GDB. A good viewer is DDD (just run ddd on the command line). Some interesting GDB commands that you should know how to use: breakpoint, watchpoint, print, display, run, set args and help. Use GDB to run some parts of the program and try to understand the flow of information in it. Remember that the focus is to better understand the use of GDB.

Where does your program spend the most time? use gprof to find out (see the gprof manual or tutorials 1 and / or 2). Indicate the two functions that spend the most time on your program in the report.

Challenge: If you have to parallelize some part of the code, which part would you choose? How to scale parallelize the code? I suggest using OpenMP, see a brief presentation, a tutorialthe official website, use by GCC e GNU implementation of for. About the time of the parallel program. Was the result expected? Comment.

How to further improve the performance of this program?


Submit a report only 1 page, describing the activity performed, the input files and the computers used. The report must contain a table and / or graph with the performance comparison. Analyze and comment on the result.