I was running my Python longest common subsequence algorithm on an especially largely input set, storing the resulting LCS lengths in a two-dimensional numpy array. I noticed it was slowing down over time; around a third of the way through, it slowed to a crawl, then crashed, printing the enigmatic error message “pnc=: N”, with no newline afterward (my program printed one more line of output before stopping). It also appeared to release a good deal of allocated memory at this point. Does anyone have any idea what this means?
EDIT: The part of the code that crashed is:
#m and n are both around 12,000
lengths = np.empty((m+1, n+1), dtype=np.uint)
lengths[0,:] = 0
lengths[1:,0] = 0
if m > 0 and n > 0:
for i in xrange(1, m + 1):
for j in xrange(1, n + 1):
#eqTest is a function comparing two sequence elements, like cmp
eq = eqTest(a[i-1], b[j-1])
if eq:
lengths[i,j] = lengths[i-1,j-1] + 1
elif lengths[i-1,j] >= lengths[i,j-1]:
lengths[i,j] = lengths[i-1,j]
else:
lengths[i,j] = lengths[i,j-1]
I’m not sure what caused it to slow down or use more resources over time, since the entire LCS length array is allocated at the beginning and then populated. The equality test I’m using is hard to describe as it’s partly written in C, but it’s effectively:
def eqTest(l1, l2):
words1 = l1.split()
words2 = l2.split()
if len(words1) == len(words2):
for i in xrange(len(words1)):
#MATCHERS is a list of around 10 compiled regular expressions
for m in MATCHERS:
if m.match(s1) is not None and m.match(s2) is not None:
break
else:
result = False
break
else:
result = True
else:
result = False
return result
If “then crashed” you mean that the programme terminated, then “It also appeared to release a good deal of allocated memory at this point.” is an effect of the operating system reclaiming the memory allocated to the process.
The cause, from your description is probably that your programme exceeded the operating system limit for process size (which leads to a crash on Linux, at least).
As to anything more, it would help to see your code. You should always post your code.