definition:
|
masterLoop :: CConfig -> [Handle] -> [Handle] -> String -> String
-> [(String,[String])] -> [String] -> IO (Maybe String)
masterLoop cc _ [] _ _ [] [] = do
debugMessage (debugLevel cc) 2 "Master loop: terminated"
return Nothing
masterLoop cc _ (b:busyWorker) ananame mainModule [] [] = do
debugMessage dl 2 "Master loop: waiting for worker result"
inputHandle <- hWaitForInputs (b:busyWorker) waitTime
if inputHandle/=0
then return (Just "No input from any worker received")
else do
let handle = b
input <- hGetLine handle
debugMessage dl 2 ("Master loop: got message: "++input)
let Task ananame2 moduleName2 = read input
if ananame == ananame2 && moduleName2 == mainModule
then return Nothing
else return (Just "Received analysis does not match requested analysis")
where dl = debugLevel cc
masterLoop cc idleWorker busyWorker ananame mainModule
modulesToDo@(_:_) [] = do
debugMessage dl 3 ("Master loop: modules to do: " ++ show modulesToDo)
let modulesToDo2 = filter ((not . null) . snd) modulesToDo
waitList = map fst (filter (null . snd) modulesToDo)
if null waitList
then do
debugMessage dl 2 "Master loop: waiting for workers to finish"
inputHandle <- hWaitForInputs busyWorker waitTime
if inputHandle<0
then return (Just "No input from any worker received")
else do
let handle = busyWorker !! inputHandle
input <- hGetLine handle
debugMessage dl 2 ("Master loop: got message: " ++ input)
let Task ananame2 moduleName2 = read input
if ananame==ananame2
then do
let modulesToDo3 = reduceDependencies modulesToDo2 [moduleName2]
busyWorker2= deleteIndex inputHandle busyWorker
masterLoop cc (handle:idleWorker) busyWorker2 ananame
mainModule modulesToDo3 waitList
else
return
(Just "Received analysis does not match requested analysis type")
else masterLoop cc idleWorker busyWorker ananame mainModule modulesToDo2
waitList
where dl = debugLevel cc
masterLoop cc (handle:idleWorker) busyWorker ananame mainModule modulesToDo
(modName:waitList) = do
debugMessage dl 2 "Master loop: worker available, send task to a worker..."
let newTask = show (Task ananame modName)
hPutStrLn handle newTask
hFlush handle
debugMessage dl 2 ("Master loop: send message: "++newTask)
masterLoop cc idleWorker (handle:busyWorker) ananame mainModule
modulesToDo waitList
where dl = debugLevel cc
masterLoop cc [] busyWorker ananame mainModule modulesToDo
waits@(modName:waitList) = do
debugMessage dl 2 $ "Waiting for worker to analyze modules: "++show waits
inputHandle <- hWaitForInputs busyWorker waitTime
if inputHandle < 0
then return (Just "No input from any worker received")
else do
let handle = busyWorker !! inputHandle
input <- hGetLine handle
debugMessage dl 2 ("Master loop: got message: "++input)
let Task _ finishedmodule = read input
newTask = show (Task ananame modName)
hPutStrLn handle newTask
hFlush handle
debugMessage dl 2 ("Master loop: send message: "++newTask)
let modulesToDo2 = reduceDependencies modulesToDo [finishedmodule]
masterLoop cc [] busyWorker ananame mainModule modulesToDo2 waitList
where dl = debugLevel cc
|
iotype:
|
{(_,_,{[]},_,_,{[]},{[]}) |-> _ || (_,_,{:},_,_,{[]},{[]}) |-> _ || (_,_,_,_,_,{:},{[]}) |-> _ || (_,{:},_,_,_,_,{:}) |-> _ || (_,{[]},_,_,_,_,{:}) |-> _}
|