Relative Content

Tag Archive for pythonnumbamontecarlo

Numba parallelization doesn’t help performance in Monte-Carlo simulation?

This is a follow-up question to a question I asked before, but I think I should start over. I am trying to implement a Monte-Carlo simulation of pi, and I am using numba to improve performance. Since each iteration of the loop is independent of the others, I thought I could get better performance with parallel=True and numba.prange. I tried it and got that for small values of n, the parallelization isn’t worth it. I tried an improved version where I use parallelization after a certain threshold for n is crossed, but I found it performs worse than my previous attempts most of the time. I now have a compression of 3 versions of the algorithm: a regular one without parallelization, a parallel version using numba.prange and an “improved” hybrid version that uses parallelization after a specified threshold for n is crossed: