0
votes

Im doing a parallell sodukusolver but right now the program gives me an error. Im trying to spawn processes in parallel that test different possible solutions. Part of the code is below.

par_solve_refined(M) ->
  case solved(M) of
    true ->
      M;
    false ->
      %% split into chunks to control granularity
      Chunks = partition(2, guesses(M)),
      Parent = self(),
      %% here below the program gives an error: "syntax error before: ')'"
      foreach(fun(I) -> spawn(fun() -> Parent ! solve_one(I) end) end, Chunks),
      receive
        Solution -> Solution
      end
  end.        

partition(_, []) ->
   [];
partition(N, L) ->
   try case lists:split(N, L) of
        {Fst, Snd} -> [Fst|partition(N, Snd)]
       end
   catch
     error:badarg -> [L]
end.
2
"gives me an error" isn't a proper description. Please specify what error is printed and where. - Netch
I think you need a '.' after the end on the previous line. - Lee
Seems parenthesis after spawn( isn't closed. - Netch
@Netch Allright thanks, but that was not all... - patriques
The first fun shall also be closed with corresponding end. - Netch

2 Answers

0
votes

Please try this:

lists:foreach(fun(I) -> spawn(fun() -> Parent ! solve_one(I) end) end, Chunks)
0
votes

lists:foreach(Function, List) is probably the function you need.