Changed precision to double and added cython function which uses much less memory
BF: added lock to stop race conditions with openmp