Jim’s first Heisenbug
Back to a theme of problem solving. In this case – the interesting part is the problem – not how I found it…
I was in college, working with ‘Real Hessenberg Matrices’ – which are generally sparse matrices. So it was reasonable to read in the values from punched cards. As I recall, some of them were 500×500.
I wrote a bunch of code to calculate eigenvalues (the real task was comparing different algorithms – optimized an not with various compilers, and counting instructions, to evaluate what order things really were, and at what point the size was overwhelmed by the order.) The program would work – and then not work. And it failed in the ugliest way imaginable.
The problem turned out to be in the routine (which I was given by my advisor) to load the sparse matrices.
The values came in four to a card (yes – punched cards). The Read statement that read them was something like:
READ (5) i1, j1, x(i1,j1), i2, j2, x(i2, j2), i3, j3, x(i3, j3), i4, j4, x(i4, j4)
5 FORMAT (i2, i2, f7.2, i2, i2, f7.2, i2, i2, f7.2, i2, i2, f7.2))
This said (cleverly) read in the coordinates, and then the value, for four elements of the matrix. So a typical card looked like:
01 01 12345.22 01 07 12346.00 99 99 12344.11 50 50 12341.12
This loaded X(1,1), X(1,7), x(99,99), x(50,50)
It drove me crazy for way too long. Turned out that there were not a multiple of four elements in the sparse matrix. The last card only had two sets of values on it:
01 01 12345.22 01 07 12346.0
Cleverly, the READ statement put the value 0.0 at location 0, 0 of the NxN matrix. That location was somewhere in my code… It would work for awhile – and would work on any matrix with a multiple of four data elements.
The fix was trivial (because my thesis was almost done and I was tired of school). I replaced the last data card (above) with:
01 01 12345.22 01 07 12346.0 01 07 12346.0 01 07 12346.0
Yes – repeating the last value two times…
Next installment – the infinite loop that ate my entire budget of $150 of computer time at the UCSF data center.
Jim on December 12th 2008 in Problem Solving, Technologies
Leave a Reply
You must be logged in to post a comment.