Question

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.
Was it helpful?

Solution

Please try this:

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top