Erlang: pmap with max number of processes
General


Use standard library as many as possible, usually it given better result therefore function partition can be easily rewritting with wrapper on lists:split/2 and it will be consider as perfomance improvement

split(List,Max)-&gt;
    L = length(List),
    split_by(List,L rem Max + L div Max,[]).

split_by([],_N,R)-&gt;lists:reverse(R);
split_by(List,N,R)-&gt;
    {Part,NewList} = lists:split(N,List),
    split_by(NewList,N,[Part|R]).



Idiomaticness


Add to head of list and reverse instead append. For explanation - SO question.
Tail recursion better for readability and may be faster, so function gather become:

gather([Pid|T], Ref,R) -&gt;
    receive
        {Pid, Ref, Ret} -&gt; gather(T, Ref,[Ret|R])
    end;
gather([], _,R) -&gt; lists:flatten(lists:reverse(R)).

List comprehensions instead lists:map/2:

Min = min(length(L), Max),
Pids = [spawn(
    fun() -&gt; do_f(S, Ref, F, SubL) end) || SubL &lt;- split(L, Min)],
...