new parallel residuals function
need to work on const correctness everywhere