Parallel algorithms for generalized N-body problem in high dimensions and their applications for bayesian inference and image analysis