Parallel algorithm for calculating the weights