How can I arrange to only use @threads if the number of iteration is higher than minimum?

If it is dominated by threading or scheduling overhead, then Polyester should help.
Also, as stated,

@batch minbatch=min_iter for i in ...

should work and do what you want. It won’t thread if less than min_iter iterations, and it will make sure each thread has at least min_iter iterations (so if the total number of iterations = 2.9min_iter, it’ll use 2 threads). This slower ramp up should also help / let you avoid using more threads than is profitable.

3 Likes