Safe Haskell | None |
---|
LogicGrowsOnTrees.Parallel.Main
Contents
Description
This module provides a framework for creating a program that explores a tree in parallel. There are two families of functions that are available. The first is more general and allows you to construct your tree using arguments given on the command-line; they are described in the section linked to by LogicGrowsOnTrees.Parallel.Main. If you do not need run-time information via a command-line argument to construct the tree, then you may prefer the simpler family of functions which are described in the section linked to by LogicGrowsOnTrees.Parallel.Main.
All of this functionality is adapter independent, so if you want to use a different back end you only need to change the driver argument and recompile.
- data Driver result_monad shared_configuration supervisor_configuration m n exploration_mode = forall controller_monad . (RequestQueueMonad (controller_monad exploration_mode), ExplorationModeFor (controller_monad exploration_mode) ~ exploration_mode) => Driver ((Serialize (ProgressFor exploration_mode), MonadIO result_monad) => DriverParameters shared_configuration supervisor_configuration m n exploration_mode controller_monad -> result_monad ())
- data DriverParameters shared_configuration supervisor_configuration m n exploration_mode controller_monad = DriverParameters {
- shared_configuration_term :: Term shared_configuration
- supervisor_configuration_term :: Term supervisor_configuration
- program_info :: TermInfo
- initializeGlobalState :: shared_configuration -> IO ()
- getStartingProgress :: shared_configuration -> supervisor_configuration -> IO (ProgressFor exploration_mode)
- notifyTerminated :: shared_configuration -> supervisor_configuration -> RunOutcomeFor exploration_mode -> IO ()
- constructExplorationMode :: shared_configuration -> ExplorationMode exploration_mode
- constructTree :: shared_configuration -> TreeT m (ResultFor exploration_mode)
- purity :: Purity m n
- constructController :: shared_configuration -> supervisor_configuration -> controller_monad exploration_mode ()
- data RunOutcome progress final_result = RunOutcome {
- runStatistics :: RunStatistics
- runTerminationReason :: TerminationReason progress final_result
- type RunOutcomeFor exploration_mode = RunOutcome (ProgressFor exploration_mode) (FinalResultFor exploration_mode)
- data RunStatistics = RunStatistics {
- runStartTime :: !UTCTime
- runEndTime :: !UTCTime
- runWallTime :: !NominalDiffTime
- runSupervisorOccupation :: !Float
- runSupervisorMonadOccupation :: !Float
- runNumberOfCalls :: !Int
- runAverageTimePerCall :: !Float
- runWorkerCountStatistics :: !(FunctionOfTimeStatistics Int)
- runWorkerOccupation :: !Float
- runWorkerWaitTimes :: !(FunctionOfTimeStatistics NominalDiffTime)
- runStealWaitTimes :: !IndependentMeasurementsStatistics
- runWaitingWorkerStatistics :: !(FunctionOfTimeStatistics Int)
- runAvailableWorkloadStatistics :: !(FunctionOfTimeStatistics Int)
- runInstantaneousWorkloadRequestRateStatistics :: !(FunctionOfTimeStatistics Float)
- runInstantaneousWorkloadStealTimeStatistics :: !(FunctionOfTimeStatistics Float)
- data TerminationReason progress final_result
- type TerminationReasonFor exploration_mode = TerminationReason (ProgressFor exploration_mode) (FinalResultFor exploration_mode)
- mainForExploreTree :: (Monoid result, Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (AllMode result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) result -> IO ()) -> (tree_configuration -> Tree result) -> result_monad ()
- mainForExploreTreeIO :: (Monoid result, Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (AllMode result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) result -> IO ()) -> (tree_configuration -> TreeIO result) -> result_monad ()
- mainForExploreTreeImpure :: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (AllMode result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) result -> IO ()) -> (tree_configuration -> TreeT m result) -> result_monad ()
- mainForExploreTreeUntilFirst :: (Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (FirstMode result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) -> (tree_configuration -> Tree result) -> result_monad ()
- mainForExploreTreeIOUntilFirst :: (Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (FirstMode result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) -> (tree_configuration -> TreeIO result) -> result_monad ()
- mainForExploreTreeImpureUntilFirst :: (Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (FirstMode result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) -> (tree_configuration -> TreeT m result) -> result_monad ()
- mainForExploreTreeUntilFoundUsingPull :: (Monoid result, Serialize result, MonadIO result_monad) => (tree_configuration -> result -> Bool) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (FoundModeUsingPull result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> (tree_configuration -> Tree result) -> result_monad ()
- mainForExploreTreeIOUntilFoundUsingPull :: (Monoid result, Serialize result, MonadIO result_monad) => (tree_configuration -> result -> Bool) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (FoundModeUsingPull result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> (tree_configuration -> TreeIO result) -> result_monad ()
- mainForExploreTreeImpureUntilFoundUsingPull :: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (tree_configuration -> result -> Bool) -> (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (FoundModeUsingPull result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> (tree_configuration -> TreeT m result) -> result_monad ()
- mainForExploreTreeUntilFoundUsingPush :: (Monoid result, Serialize result, MonadIO result_monad) => (tree_configuration -> result -> Bool) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (FoundModeUsingPush result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> (tree_configuration -> Tree result) -> result_monad ()
- mainForExploreTreeIOUntilFoundUsingPush :: (Monoid result, Serialize result, MonadIO result_monad) => (tree_configuration -> result -> Bool) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (FoundModeUsingPush result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> (tree_configuration -> TreeIO result) -> result_monad ()
- mainForExploreTreeImpureUntilFoundUsingPush :: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (tree_configuration -> result -> Bool) -> (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (FoundModeUsingPush result) -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> (tree_configuration -> TreeT m result) -> result_monad ()
- genericMain :: (MonadIO result_monad, ResultFor exploration_mode ~ result, Serialize (ProgressFor exploration_mode)) => (tree_configuration -> ExplorationMode exploration_mode) -> Purity m n -> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m n exploration_mode -> Term tree_configuration -> TermInfo -> (tree_configuration -> RunOutcomeFor exploration_mode -> IO ()) -> (tree_configuration -> TreeT m result) -> result_monad ()
- simpleMainForExploreTree :: (Monoid result, Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (AllMode result) -> (RunOutcome (Progress result) result -> IO ()) -> Tree result -> result_monad ()
- simpleMainForExploreTreeIO :: (Monoid result, Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (AllMode result) -> (RunOutcome (Progress result) result -> IO ()) -> TreeIO result -> result_monad ()
- simpleMainForExploreTreeImpure :: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (AllMode result) -> (RunOutcome (Progress result) result -> IO ()) -> TreeT m result -> result_monad ()
- simpleMainForExploreTreeUntilFirst :: (Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (FirstMode result) -> (RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) -> Tree result -> result_monad ()
- simpleMainForExploreTreeIOUntilFirst :: (Serialize result, MonadIO result_monad) => Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (FirstMode result) -> (RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) -> TreeIO result -> result_monad ()
- simpleMainForExploreTreeImpureUntilFirst :: (Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (FirstMode result) -> (RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) -> TreeT m result -> result_monad ()
- simpleMainForExploreTreeUntilFoundUsingPull :: (Monoid result, Serialize result, MonadIO result_monad) => (result -> Bool) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (FoundModeUsingPull result) -> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> Tree result -> result_monad ()
- simpleMainForExploreTreeIOUntilFoundUsingPull :: (Monoid result, Serialize result, MonadIO result_monad) => (result -> Bool) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (FoundModeUsingPull result) -> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> TreeIO result -> result_monad ()
- simpleMainForExploreTreeImpureUntilFoundUsingPull :: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (result -> Bool) -> (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (FoundModeUsingPull result) -> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> TreeT m result -> result_monad ()
- simpleMainForExploreTreeUntilFoundUsingPush :: (Monoid result, Serialize result, MonadIO result_monad) => (result -> Bool) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (FoundModeUsingPush result) -> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> Tree result -> result_monad ()
- simpleMainForExploreTreeIOUntilFoundUsingPush :: (Monoid result, Serialize result, MonadIO result_monad) => (result -> Bool) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (FoundModeUsingPush result) -> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> TreeIO result -> result_monad ()
- simpleMainForExploreTreeImpureUntilFoundUsingPush :: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) => (result -> Bool) -> (forall β. m β -> IO β) -> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (FoundModeUsingPush result) -> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) -> TreeT m result -> result_monad ()
- extractRunOutcomeFromSupervisorOutcome :: Show worker_id => SupervisorOutcome fv ip worker_id -> RunOutcome ip fv
- mainMan :: [ManBlock]
- mainParser :: Term α -> TermInfo -> IO α
Types
Driver types
data Driver result_monad shared_configuration supervisor_configuration m n exploration_mode Source
The Driver
is the core type that abstracts the various adapters behind a
common interface that can be invoked by the main functions; it specifies a
function that is called to start the run with a set of parameters specified
in DriverParameters
.
(Unfortunately in haddock the type signature below can be difficult to read
because it puts all of the type on a single line; the type is essentially
just a map from DriverParameters
to result_monad ()
, but involving a
bunch of type variables and some constraints on them. It might be easier to
click the link to go to the source.)
Note that the controller_monad
type parameter is within an existential
type; this is because the user of the driver should not need to know what it
is.
Constructors
forall controller_monad . (RequestQueueMonad (controller_monad exploration_mode), ExplorationModeFor (controller_monad exploration_mode) ~ exploration_mode) => Driver ((Serialize (ProgressFor exploration_mode), MonadIO result_monad) => DriverParameters shared_configuration supervisor_configuration m n exploration_mode controller_monad -> result_monad ()) |
data DriverParameters shared_configuration supervisor_configuration m n exploration_mode controller_monad Source
The DriverParameters
type specifies the information that is given to the
driver in the main functions.
Constructors
DriverParameters | |
Fields
|
Outcome types
data RunOutcome progress final_result Source
A type that represents the outcome of a run.
Constructors
RunOutcome | |
Fields
|
Instances
(Eq progress, Eq final_result) => Eq (RunOutcome progress final_result) | |
(Show progress, Show final_result) => Show (RunOutcome progress final_result) |
type RunOutcomeFor exploration_mode = RunOutcome (ProgressFor exploration_mode) (FinalResultFor exploration_mode)Source
A convenient type alias for the type of RunOutcome
associated with the given exploration mode.
data RunStatistics Source
Statistics gathered about the run.
Constructors
RunStatistics | |
Fields
|
Instances
data TerminationReason progress final_result Source
A type that represents the reason why a run terminated.
Constructors
Aborted progress | the run was aborted with the given progress |
Completed final_result | the run completed with the given final result |
Failure progress String | the run failed with the given progress for the given reason |
Instances
(Eq progress, Eq final_result) => Eq (TerminationReason progress final_result) | |
(Show progress, Show final_result) => Show (TerminationReason progress final_result) |
type TerminationReasonFor exploration_mode = TerminationReason (ProgressFor exploration_mode) (FinalResultFor exploration_mode)Source
A convenient type alias for the type of TerminationReason
associated with the given exploration mode.
Main functions
The functions in this section all provide a main function that starts up the system that explores a tree in parallel using the given tree (constructed possibly using information supplied on the command line) and the given adapter provided via the driver argument.
All of the functionality of this module can be accessed through genericMain
,
but we nonetheless also provide specialized versions of these functions for all
of the supported tree purities and exploration modes. This is done for two
reasons: first, in order to make the types more concrete to hopefully improve
usability, and second, because often the type of the tree is generalized so it
could be one of several types, and using a specialized function automatically
specializes the type rather than requiring a type annotation. The convention is
mainForExploreTreeXY
where X
is empty for pure trees, IO
for trees with
side-effects in the IO
monad, and Impure
for trees with side-effects in some
general monad, and Y
specifies the exploration mode, which is empty for
AllMode
(sum over all results), UntilFirst
for FirstMode
(stop when first
result found), UntilFoundUsingPull
for FoundModeUsingPull
(sum all results
until a condition has been met, only sending results to the supervisor upon
request) and UntilFoundUsingPush
for FoundModeUsingPush
(sum all results
until a condition has been met, pushing all found results immediately to the
supervisor).
If you do not need to use command-line arguments to construct the tree and don't care about what the name of the program is on the help screen then you might be interested in the simpler version of these functions in the following section (follow LogicGrowsOnTrees.Parallel.Main).
Sum over all results
The functions in this section are for when you want to sum over all the results in (the leaves of) the tree.
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (AllMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) result -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> Tree result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given pure tree in parallel; the results in the leaves will be
summed up using the Monoid
instance.
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (AllMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) result -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeIO result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given IO tree in parallel; the results in the leaves will be
summed up using the Monoid
instance.
mainForExploreTreeImpureSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (AllMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) result -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeT m result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given impure tree in parallel; the results in all of the leaves
will be summed up using the Monoid
instance.
Stop at first result
The functions in this section are for when you want to stop as soon as you have found a result.
There are two ways in which a system running in this mode can terminate normally:
- A solution is found, in which case a
Just
-wrapped value is returned with both the found solution and the currentCheckpoint
, the latter allowing one to resume the search to look for more solutions later. - The whole tree has been explored, in which case
Nothing
is returned.
mainForExploreTreeUntilFirstSource
Arguments
:: (Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (FirstMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> Tree result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given pure tree in parallel, stopping if a solution is found.
mainForExploreTreeIOUntilFirstSource
Arguments
:: (Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (FirstMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeIO result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given IO tree in parallel, stopping if a solution is found.
mainForExploreTreeImpureUntilFirstSource
Arguments
:: (Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (FirstMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeT m result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given impure tree in parallel, stopping if a solution is found.
Stop when sum of results found
The functions in this section are for when you want sum the results as you find them until the sum matches a condition. There are two versions of this mode, based on whether one wants to regularly poll the workers for results or whether one wants workers to immediately push every result to the supervisor as soon as it is found.
Pull
In this mode, partial results are left on the workers until they receive either a workload steal request or a progress update request. The advantage of this approach is that it minimizes communication costs as partial results are sent on an occasional basis rather than as soon as they are found. The downside of this approach is that one has to poll the workers on a regular basis using a global process update, and between polls it might be the case that the sum of all results in the system meets the condition but this will not be found out until the next poll, which wastes time equal to the amount of time between polls. If you would rather have the system immediately terminate as soon as it has found the desired results (at the price of paying an additional cost as each workload is found in sending it to the supervisor), then follow LogicGrowsOnTrees.Parallel.Main to see the description of push mode.
There are three ways in which a system running in this mode can terminate:
- A worker finds another result and now its (new) local sum meet the
condition; in this case the sum of the worker's local sum and the
supervisor's local sum is returned along with the current checkpoint
(which allows the search to be resumed later to find more results), all
wrapped in a
Right
. - The supervisor, having just received some new results from a worker, has its (new) local sum meet the condition; this has essentially the same effect as 1.
- The tree has been fully explored, in which case the full sum is returned
in a
Left
.
WARNING: If you use this mode then you need to enable checkpointing when the program is run; if you do not do this, then you might end up in a situation where the sum of results over the entire system meets the condition but the system does not realize this because the results have not been gathered together and summed at the supervisor.
mainForExploreTreeUntilFoundUsingPullSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (tree_configuration -> result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (FoundModeUsingPull result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> Tree result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given pure tree in parallel until the sum of results meets the given condition.
mainForExploreTreeIOUntilFoundUsingPullSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (tree_configuration -> result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (FoundModeUsingPull result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeIO result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given IO tree in parallel until the sum of results meets the given condition.
mainForExploreTreeImpureUntilFoundUsingPullSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (tree_configuration -> result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (FoundModeUsingPull result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeT m result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given impure tree in parallel until the sum of results meets the given condition.
Push
In this mode, whenever a result is found it is immediately sent to the supervisor. The advantage of this approach is that the system finds out immediately when all the results found so far have met the condition, rather than waiting for a progress update to occur that gathers them together. The downside of this approach is that it costs some time for a worker to send a result to the supervisor, so if the condition will not be met until a large number of results have been found then it be better let the workers accumulate results locally and to poll them on a regular basis; to do this, follow LogicGrowsOnTrees.Parallel.Main to see the description of pull mode.
There are three ways in which a system running in this mode can terminate:
- The supervisor, having just received a new result from a worker, finds
that its current sum meets the condition function, in which case it
returns the sum as well as the current checkpoint (which allows the
search to be resumed later to find more results) wrapped in a
Right
. - The tree has been fully explored, in which case the full sum is returned
in a
Left
.
(Note that, unlike the pull version, a partial result will not be returned upon success as the Supervisor has access to all results and so it will never be in the position of only having a partial result upon success.)
mainForExploreTreeUntilFoundUsingPushSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (tree_configuration -> result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration Identity IO (FoundModeUsingPush result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> Tree result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given pure tree in parallel until the sum of results meets the given condition.
mainForExploreTreeIOUntilFoundUsingPushSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (tree_configuration -> result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration IO IO (FoundModeUsingPush result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeIO result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given IO tree in parallel until the sum of results meets the given condition.
mainForExploreTreeImpureUntilFoundUsingPushSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (tree_configuration -> result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m m (FoundModeUsingPush result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeT m result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
Explore the given impure tree in parallel until the sum of results meets the given condition.
Generic main function
Arguments
:: (MonadIO result_monad, ResultFor exploration_mode ~ result, Serialize (ProgressFor exploration_mode)) | |
=> (tree_configuration -> ExplorationMode exploration_mode) | a function that constructs the exploration mode given the tree configuration; note that the constructor that this function returns is restricted by the value of the exploration_mode type variable |
-> Purity m n | the purity of the tree |
-> Driver result_monad (SharedConfiguration tree_configuration) SupervisorConfiguration m n exploration_mode | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> Term tree_configuration | a term with any configuration information needed to construct the tree |
-> TermInfo | information about the program; should look something like the following: defTI { termDoc = "count the number of n-queens solutions for a given board size" } |
-> (tree_configuration -> RunOutcomeFor exploration_mode -> IO ()) | a callback that will be invoked with the outcome of the run and the
tree configuration information; note that if the run was |
-> (tree_configuration -> TreeT m result) | the function that constructs the tree given the tree configuration information |
-> result_monad () |
This is just like the previous functions, except that it is generalized over all tree purities and exploration modes. (In fact, the specialized functions are just wrappers around this function.)
Simple main functions
The functions in this section provide simpler version of the functions in the preceding section (follow LogicGrowsOnTrees.Parallel.Main) for the case where you do not need to use command-line arguments to construct the tree and don't care about what the name of the program is on the help screen; the naming convention follows the same convention as that in the previous section.
Sum over all results
The functions in this section are for when you want to sum over all the results in (the leaves of) the tree.
simpleMainForExploreTreeSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (AllMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) result -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> Tree result | the tree to explore |
-> result_monad () |
Explore the given pure tree in parallel; the results
in the leaves will be summed up using the Monoid
instance.
simpleMainForExploreTreeIOSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (AllMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) result -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeIO result | the tree to explore in IO |
-> result_monad () |
Explore the given IO tree in parallel;
the results in the leaves will be summed up using the Monoid
instance.
simpleMainForExploreTreeImpureSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (AllMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) result -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeT m result | the (impure) tree to explore |
-> result_monad () |
Explore the given impure tree in parallel; the
results in all of the leaves will be summed up using the Monoid
instance.
Stop at first result
For more details, follow this link: LogicGrowsOnTrees.Parallel.Main
simpleMainForExploreTreeUntilFirstSource
Arguments
:: (Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (FirstMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> Tree result | the tree to explore |
-> result_monad () |
Explore the given pure tree in parallel, stopping if a solution is found.
simpleMainForExploreTreeIOUntilFirstSource
Arguments
:: (Serialize result, MonadIO result_monad) | |
=> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (FirstMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeIO result | the tree to explore in IO |
-> result_monad () |
Explore the given tree in parallel in IO, stopping if a solution is found.
simpleMainForExploreTreeImpureUntilFirstSource
Arguments
:: (Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (FirstMode result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome Checkpoint (Maybe (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeT m result | the impure tree to explore |
-> result_monad () |
Explore the given impure tree in parallel, stopping if a solution is found.
Stop when sum of results found
For more details, follow this link: LogicGrowsOnTrees.Parallel.Main
Pull
For more details, follow this link: LogicGrowsOnTrees.Parallel.Main
simpleMainForExploreTreeUntilFoundUsingPullSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (FoundModeUsingPull result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> Tree result | the tree to explore |
-> result_monad () |
Explore the given pure tree in parallel until the sum of results meets the given condition.
simpleMainForExploreTreeIOUntilFoundUsingPullSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (FoundModeUsingPull result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeIO result | the tree to explore in IO |
-> result_monad () |
Explore the given IO tree in parallel until the sum of results meets the given condition.
simpleMainForExploreTreeImpureUntilFoundUsingPullSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (FoundModeUsingPull result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeT m result | the impure tree to explore |
-> result_monad () |
Explore the given impure tree in parallel until the sum of results meets the given condition.
Push
For more details, follow this link: LogicGrowsOnTrees.Parallel.Main
simpleMainForExploreTreeUntilFoundUsingPushSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration Identity IO (FoundModeUsingPush result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> Tree result | the tree to explore |
-> result_monad () |
Explore the given pure tree in parallel until the sum of results meets the given condition.
simpleMainForExploreTreeIOUntilFoundUsingPushSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad) | |
=> (result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration IO IO (FoundModeUsingPush result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeIO result | the tree to explore in IO |
-> result_monad () |
Explore the given IO tree in parallel until the sum of results meets the given condition.
simpleMainForExploreTreeImpureUntilFoundUsingPushSource
Arguments
:: (Monoid result, Serialize result, MonadIO result_monad, Functor m, MonadIO m) | |
=> (result -> Bool) | a condition function that signals when we have found all of the result that we wanted |
-> (forall β. m β -> IO β) | a function that runs an |
-> Driver result_monad (SharedConfiguration ()) SupervisorConfiguration m m (FoundModeUsingPush result) | the driver for the desired adapter (note that all drivers can be specialized to this type) |
-> (RunOutcome (Progress result) (Either result (Progress result)) -> IO ()) | a callback that will be invoked with the outcome of the run; note
that if the run was |
-> TreeT m result | the impure tree to explore |
-> result_monad () |
Explore the given impure tree in parallel until the sum of results meets the given condition.
Utility functions
extractRunOutcomeFromSupervisorOutcome :: Show worker_id => SupervisorOutcome fv ip worker_id -> RunOutcome ip fvSource
Converts a SupervisorOutcome
to a RunOutcome
.
The additional entries in the manual explaining log format strings and
statistics. If you are not using the Main term info then you should add
mainMan
to your term information as otherwise the documentation will be
incomplete; in particular when using execChoice
you will want to use this
for each of the modes that corresponds to the supervisor (as logging and
statistics are only on the supervisor).
mainParser :: Term α -> TermInfo -> IO αSource
Parse the command line options using the given term and term info (the latter of which has the program name added to it); if successful return the result, otherwise throw an exception.