in reply to Iteration speed

Perhaps you can generate your residues and sort them so that you can use part of the work from the previous residue pair.

Individual writes are probably not helping.

I suggest you profile your program with a small data set and see where the problems really are.