-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Concurrent over the network execution library -- -- net-concurrent is a simple haskell library for doing parallel -- computation on several computers using the network. There is a single -- master process and many slave processes. Communication is between the -- master and the slaves, for simplicity slaves never communicate with -- each other. Communication is done using NVars, network variables. The -- NVar api is very similar to MVar. These are stored in the master -- process and shared between all processes in the system. Slave nodes -- can read and write these NVar variables which results in network -- transactions with the master. @package net-concurrent @version 0.1.0 -- | The master process doesn't do any work except managing the slaves. The -- master process is handled entirely by the library in -- initMaster. module Control.Concurrent.Network.Master -- | The master process. Only returns when all slaves have closed -- connection. initMaster :: Int -> PortID -> IO () -- | Slave processes have a single connection towards the master for -- simplicity. Communication is done by using NVar variables -- similar to MVar in Concurrent. module Control.Concurrent.Network.Slave -- | the NC Context data NCContext NCC :: MVar Handle -> NCContext hdl :: NCContext -> MVar Handle -- | Initialises a slave process returning the NC context. initSlave :: HostName -> PortID -> IO NCContext -- | Returns the slave ID of the caller slaveID :: NCContext -> IO Int -- | Number of slaves numSlaves :: NCContext -> IO Int -- | Prints a message on master printMsg :: NCContext -> String -> IO () -- | General idea is having one dedicated master process and an arbitrary -- number of slave processes. module Control.Concurrent.Network.Process -- | Convinience function. It calls either initMaster or -- initSlave depending on whether we have -m on the command line -- or not. If -m is specified the following argument should be the number -- of slaves to wait for. -- -- Returns in the slave processes with the NC context. Does not return in -- the master process. initProcess :: IO NCContext -- | Network variables. Communication is done by using NVar -- variables similar to MVar in Concurrent. -- -- Every read and every write results in network transaction with the -- master process, so handle with care. -- -- This is done with a push style implementation so putNVar -- propagets the value to the master process, but other slaves won't get -- automatically notified about the change. The next takeNVar will -- result in the updated value. -- -- To save network bandwith and load on the master, it is possible to -- wait for an NVar to change value using pollWithOp. module Control.Concurrent.Network.NVar -- | Creates a new empty NVar on the master. Doesn't block the -- caller. newNVar :: NCContext -> String -> IO () -- | Puts a value into NVar specified by the name. If the -- NVar doesn't exist this blocks the caller until it's created -- potentially by an other slave. -- -- If the NVar already has a value this blocks the caller until -- an other slave calls takeNVar. -- -- If the NVar is empty this returns immediately after the -- network transactions. putNVar :: Binary a => NCContext -> String -> a -> IO () -- | Takes the latest value of NVar from the master. If the -- NVar doesn't exist this blocks the caller until it's created -- potentially by an other slave. -- -- If the NVar is empty this blocks the caller until an other -- slave calls putNVar. -- -- If the NVar has a value this returns immediately after the -- network transactions. takeNVar :: Binary a => NCContext -> String -> IO a -- | Tries to put a value into NVar specified by the name. If the -- NVar doesn't exist returns IO False. -- -- If the NVar already has a value returns IO -- False and leaves the value untouched. -- -- If the NVar is empty this sets it to the specified value and -- returns IO True. tryPutNVar :: Binary a => NCContext -> String -> a -> IO Bool -- | Takes the latest value of NVar from the master. If the -- NVar doesn't exist this blocks the caller until it's created -- potentially by an other slave. -- -- If the NVar is empty this blocks the caller until an other -- slave calls putNVar. -- -- If the NVar has a value this returns immediately after the -- network transactions. tryTakeNVar :: Binary a => NCContext -> String -> IO (Maybe a) -- | Like with MVars this takes an NVar put's the taken -- value back, and returns it. readNVar :: Binary a => NCContext -> String -> IO a -- | Polls while the given condition is true for NVar called -- name. As this call doesn't return while the condition is -- true, it's much more efficient than busy waiting in the slave -- generating network traffic. pollWithOp :: Binary a => NCContext -> String -> Equality -> a -> IO ()