Programming Parallel Computers 2020

Help with debugging

AddressSanitizer quick start

To enable AddressSanitizer, run make clean and make DEBUG=2.

Here is a quick tutorial of how to interpret the information that you get from AddressSanitizer. I am using a buggy implementation of MF1 as an example. Here are the relevant parts of the messages:

$ ./mf-test
...
... ERROR: AddressSanitizer: stack-buffer-overflow on ...
READ of size 4 at ...
    #0 0x4041c4 in ... mf.cc:32
    ...
    #5 0x401bd8 in ... mf-test ...
...
Address ... is located ... at offset 36 ...
...
  This frame has 2 object(s):
    [32, 36) 'in'
...

So the program crashed, because we were trying to read at an address that is outside the bounds of any array. Furthermore, it happened to be right after the end of array in, so probably we were simply trying to read beyond the end of array. This happened in the code at line 32 of mf.cc, which in my case contained:

float v = in[i + j * nx];

Now it is easy to figure out precisely what went wrong; it turns out that the index i was one too large in certain cases.