Created
October 23, 2013 14:28
-
-
Save kgadek/7119881 to your computer and use it in GitHub Desktop.
Haskell MPI example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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