A case study

In the following exercise you are going to optimize a Matlab code. The code is very inefficient and it is possible to speed it up quite substantially. The speedup you will get depends on your proficiency in using Matlab. The version of Matlab and what computer you are using are important factors as well. Here are some times to give you an idea of what is possible (the tests were made on a linux-computer in the student lab):


Original code
My optimized code
First problem
12.5s
0.2s
Second problem
199.6s
2.7s

The code is a simplified part of a finite element code for solving an integral equation. To give you more things to try I have made the original code slower, so some optimizations are easy to find, but others are hard. Since you need some large data files I have put everything you need locally in the file system (not on www, in other words). Look in the directory ~thomas/HPC/case_study on the student system. You run the two tests by typing main in Matlab. The main-routine also compares your results with the correct ones. If you get an error message saying something like "Large error in test 2" there is a bug in your program.

You should optimize the routine by removing unnecessary recomputing of quantities, reformulating some linear algebra operations etc. You should not try to change the algorithm, solving the integral equation in a different way. In a real code one should always try to use the fastest algorithm of course, but this assignment is an exercise in code optimization and not in algorithm development.

A hint: do not try to understand what the code does, just look at it as a set of fairly arbitrary Matlab-statements.


Back