3
import Picosat
import Control.Applicative

main :: IO ()
main = do
  dimacsList1 <- (read <$> getLine) :: IO [[Integer]]
  dimacsList2 <- (read <$> getLine) :: IO [[Integer]]

  res1 <- solve dimacsList1
  res2 <- solve dimacsList2

  putStrLn $ (show res1) ++ "  " ++ (show res2)

Question: How can I change the above example to run the two sat calls in parallel, i.e., using concurrency? I am interested in performance, if there are different options.

(Just to check: As I understand it, the ST monad is orthogonal and cannot be used in conjunction with parallelization/concurrency. The ST monad confused me a bit in the beginning, is is one of the reasons I ask the question.)

mrsteve
  • 4,082
  • 1
  • 26
  • 63
  • `ST` is `IO` with the allowed effects limited to mutation of variables created within that `ST` session. If there's any effect other than mutation going on, like concurrency, it's not a place `ST` can be used. – Carl May 25 '14 at 16:36
  • 1
    You might like to browse [Simon Marlow's great new book](http://chimera.labs.oreilly.com/books/1230000000929) – jberryman May 25 '14 at 16:44

1 Answers1

3

The easiest approach is to use the async library. Something like this, maybe.

[res1, res2] <- mapConcurrently solve [dimacsList1, dimacsList2]
Carl
  • 26,500
  • 4
  • 65
  • 86