Skip to content

Instantly share code, notes, and snippets.

@kgadek
Created October 23, 2013 14:28
Show Gist options
  • Save kgadek/7119881 to your computer and use it in GitHub Desktop.
Save kgadek/7119881 to your computer and use it in GitHub Desktop.
Haskell MPI example
-- Below is a small but complete MPI program. Process 1 sends the message "Hello World"
-- to process 0, which in turn receives the message and prints it to standard output.
-- All other processes, if there are any, do nothing.
-- -- http://hackage.haskell.org/package/haskell-mpi
module Main where
import Control.Parallel.MPI.Simple (mpiWorld, commWorld, unitTag, send, recv)
main :: IO ()
main = mpiWorld $ \size rank ->
if size < 2
then putStrLn "At least two processes are needed"
else case rank of
0 -> do (msg, _status) <- recv commWorld 1 unitTag
putStrLn msg
1 -> send commWorld 0 unitTag "Hello World"
_ -> return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment