-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple zero-configuration backend for Cloud Haskell -- -- Simple backend based on the TCP transport which offers node discovery -- based on UDP multicast. This is a zero-configuration backend designed -- to get you going with Cloud Haskell quickly without imposing any -- structure on your application. @package distributed-process-simplelocalnet @version 0.3.1 -- | Multicast utilities module Control.Distributed.Process.Backend.SimpleLocalnet.Internal.Multicast -- | Given a hostname and a port number, initialize the multicast system. -- -- Note: it is important that you never send messages larger than the -- maximum message size; if you do, all subsequent communication will -- probably fail. -- -- Returns a reader and a writer. -- -- NOTE: By rights the two functions should be "locally" polymorphic in -- a, but this requires impredicative types. initMulticast :: forall a. Binary a => HostName -> PortNumber -> Int -> IO (IO (a, SockAddr), a -> IO ()) -- | Simple backend based on the TCP transport which offers node discovery -- based on UDP multicast. This is a zero-configuration backend designed -- to get you going with Cloud Haskell quickly without imposing any -- structure on your application. -- -- To simplify getting started we provide special support for -- master and slave nodes (see startSlave and -- startMaster). Use of these functions is completely optional; -- you can use the local backend without making use of the predefined -- master and slave nodes. -- --
-- import System.Environment (getArgs) -- import Control.Distributed.Process -- import Control.Distributed.Process.Node (initRemoteTable) -- import Control.Distributed.Process.Backend.SimpleLocalnet -- -- master :: Backend -> [NodeId] -> Process () -- master backend slaves = do -- -- Do something interesting with the slaves -- liftIO . putStrLn $ "Slaves: " ++ show slaves -- -- Terminate the slaves when the master terminates (this is optional) -- terminateAllSlaves backend -- -- main :: IO () -- main = do -- args <- getArgs -- -- case args of -- ["master", host, port] -> do -- backend <- initializeBackend host port initRemoteTable -- startMaster backend (master backend) -- ["slave", host, port] -> do -- backend <- initializeBackend host port initRemoteTable -- startSlave backend ---- --
-- ghc -threaded example.hs ---- -- Fire up some slave nodes (for the example, we run them on a single -- machine): -- --
-- ./example slave localhost 8080 & -- ./example slave localhost 8081 & -- ./example slave localhost 8082 & -- ./example slave localhost 8083 & ---- -- And start the master node: -- --
-- ./example master localhost 8084 ---- -- which should then output: -- --
-- Slaves: [nid://localhost:8083:0,nid://localhost:8082:0,nid://localhost:8081:0,nid://localhost:8080:0] ---- -- at which point the slaves should exit. -- -- To run the example on multiple machines, you could run -- --
-- ./example slave 198.51.100.1 8080 & -- ./example slave 198.51.100.2 8080 & -- ./example slave 198.51.100.3 8080 & -- ./example slave 198.51.100.4 8080 & ---- -- on four different machines (with IP addresses 198.51.100.1..4), and -- run the master on a fifth node (or on any of the four machines that -- run the slave nodes). -- -- It is important that every node has a unique (hostname, port number) -- pair, and that the hostname you use to initialize the node can be -- resolved by peer nodes. In other words, if you start a node and pass -- hostname localhost then peer nodes won't be able to reach it -- because localhost will resolve to a different IP address for -- them. -- --