'Determine maximal number of "parallel execution agents" in the parallel STL

Is there a way to know a maximal number of parallel execution agents (not sure what the term is) in the parallel STL algorithms?

The reason I need this information is to pre-allocate memory needed by the function.

I.e. I want to parallelize the following code without allocating too much/too little memory:

template<std::ranges::range Rng>
void foo(int n, Rng& rng)
{
    const std::size_t required_dynamic_size_per_call = something_manually_calculated(n);
    std::pmr::synchronized_pool_resource rsc(std::pmr::pool_options{??? * required_dynamic_size_per_call, required_dynamic_size_per_call} );
    
    std::for_each(std::execution::par, std::begin(rng), std::end(rng), [&](auto i)
    {
        some_heavy_computation(&rsc, i);
    });
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source