The following code is from Armstrong's Erlang textbook:

pythag(N) -> [ {A,B,C} || A <- lists:seq(1,N), B <- lists:seq(1,N), C <- lists:seq(1,N), A + B + C =< N, A * A + B * B =:= C * C ]. 

When calling pythag (N), erlang uses 100% of only one core out of 4 available, with the obvious possibility of parallelization (especially necessary when N> 100). So it should be? How to make this example processed in parallel?

    1 answer 1

    This is not done in parallel due to the lack of shared memory between processes, i.e. only one process can "eat" the head of the list, the other process will have its own list. This could be solved by thinning the lists or by noting that all the functions in this chain are clean. The mechanism of "clean" functions in the erlang is not, and in parallel to process thinned lists - spawn new processes, only this way.