'import ccall unsafe' and parallelism

Christian Höner zu Siederdissen choener at tbi.univie.ac.at
Thu Aug 14 15:54:12 UTC 2014


Greetings everybody,

I happen to be a bit confused with regards to unsafe foreign imports and
parallelism.

Assume the following C function:

foreign import ccall unsafe "cfun"
  cfun :: CInt -> IO ()

Now, cfun does some work:

go xs = unsafePerformIO $ do
  forM_ xs $ cfun
  return $ somethingUnhealthy

And I'd like to parallelize this:

parMap rdeepseq go [costly,costly]

However, due to the way ghc handles unsafe imports, namely block
everything else whenever 'cfun' is called, I happen to have only one
active 'go'. Lets assume 'cfun' is cheap and would suffer from 'ccall
safe' more than I'd be willing to pay.

Is there any fix possible?

Viele Gruesse,
Christian

PS: The real problem happens to use a bunch of different judy arrays,
each of which lives in its on thread; 300 judy arrays, 300 threads, each
up to 20 million inserts. But I think the basic problem can be reduced
to "how to parallelize 'ccall unsafe's.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20140814/d4622042/attachment.sig>


More information about the Glasgow-haskell-users mailing list