!da/      (c) Alexey Kuleshevich 2018-2019BSD3%Alexey Kuleshevich <lehins@yandex.ru> experimental non-portableSafeX_gD scheduler1Computation strategy to use when scheduling work. schedulerSequential computation schedulerKSchedule workers to run on specific capabilities. Specifying an empty list  [] or using : will result in utilization of all available capabilities. schedulerRSpecify the number of workers that will be handling all the jobs. Difference from 0 is that workers can jump between cores. Using  02 will result in using all available capabilities. scheduler8Parallel computation using all available cores. Same as  0 scheduler8Parallel computation using all available cores. Same as  [] schedulerAFigure out how many workers will this computation strategy create (c) Alexey Kuleshevich 2018-2019BSD3%Alexey Kuleshevich <lehins@yandex.ru> experimental non-portableNone$(  !"#$ (c) Alexey Kuleshevich 2018-2019BSD3%Alexey Kuleshevich <lehins@yandex.ru> experimental non-portableNone"#$X_g`c% schedulerrWhen a brother worker dies of some exception, all the other ones will be terminated asynchronously with this one.& schedulerVThis exception should normally be never seen in the wild and is for internal use only.' schedulerKOne of workers experienced an exception, main thread will receive the same (. scheduler#Main type for scheduling work. See  or / for ways to construct and use this data type. schedulerGet the number of workers. Will mainly depend on the computation strategy and/or number of capabilities you have. Related function is .  schedulerSchedule an action to be picked up and computed by a worker from a pool of jobs. Argument supplied to the job will be the id of the worker doing the job.  schedulerAs soon as possible try to terminate any computation that is being performed by all workers managed by this scheduler and collect whatever results have been computed, with supplied element guaranteed to being the last one. Important - With  strategy this will not stop other scheduled tasks from being computed, although it will make sure their results are discarded.  schedulerSame as  , but returning a single element list containing the supplied argument. This can be very useful for parallel search algorithms. Important - Same as with  , when  strategy is used, this will not prevent computation from continuing, but the scheduler will return only the result supplied to this function.  scheduler]Schedule an action to be picked up and computed by a worker from a pool of jobs. Similar to  +, except the job doesn't get the worker id.  schedulerSame as  , but only for a  that doesn't keep the results. schedulerSame as  , but only for a  that doesn't keep the results. scheduler Similar to   , but for a / that does not keep any results of computation. Important - In case of 2 computation strategy this function has no affect. scheduler|The most basic scheduler that simply runs the task instead of scheduling it. Early termination requests are simply ignored. schedulerWThis is generally a faster way to traverse while ignoring the result rather than using ). scheduler'Map an action over each element of the * t2 acccording to the supplied computation strategy. scheduler Just like , but restricted to +* and discards the results of computation. schedulerReplicate an action nJ times and schedule them acccording to the supplied computation strategy. scheduler Just like *, but discards the results of computation., scheduler Similarly to  C, but ignores the result of computation, thus having less overhead.- scheduler,Helper function to place required number of Retire instructions on the job queue.. schedulerKDecrease a counter by one and perform an action when it drops down to zero./ scheduleryRuns the worker until the job queue is exhausted, at which point it will execute the final task of retirement and return schedulerxInitialize a scheduler and submit jobs that will be computed sequentially or in parallelel, which is determined by the utation strategy.(Here are some cool properties about the :This function will block until all of the submitted jobs have finished or at least one of them resulted in an exception, which will be re-thrown at the callsite.VIt is totally fine for nested jobs to submit more jobs for the same or other schedulerIt is ok to initialize multiple schedulers at the same time, although that will likely result in suboptimal performance, unless workers are pinned to different capabilities.Warning: It is pretty dangerous to schedule jobs that do blocking 0, since it can easily lead to deadlock, if you are not careful. Consider this example. First execution works fine, since there are two scheduled workers, and one can unblock the other, but the second scenario immediately results in a deadlock.}withScheduler (ParOn [1,2]) $ \s -> newEmptyMVar >>= (\ mv -> scheduleWork s (readMVar mv) >> scheduleWork s (putMVar mv ()))[(),()]import System.Timeouttimeout 1000000 $ withScheduler (ParOn [1]) $ \s -> newEmptyMVar >>= (\ mv -> scheduleWork s (readMVar mv) >> scheduleWork s (putMVar mv ()))Nothing ImportantR: In order to get work done truly in parallel, program needs to be compiled with  -threaded GHC flag and executed with  +RTS -N -RTS to use all available cores. schedulerSame as ), but discards results of submitted jobs.1 scheduler5Specialized exception handler for the work scheduler./ schedulerAction to run upon retirement schedulerComputation strategy scheduler,Action that will be scheduling all the work. schedulerComputation strategy scheduler,Action that will be scheduling all the work.2 schedulerComputation strategy schedulerHow to schedule work schedulerHow to collect results schedulerAdjust results in some way scheduler,Action that will be scheduling all the work.     3      !"#$%&'()**+,-+./+01+.23456789:;<&scheduler-1.2.0-FwpQc2UlU1JLKag7Q1byc7Control.SchedulerControl.Scheduler.ComputationControl.Scheduler.QueueCompSeqParOnParNPar'PargetCompWorkers Scheduler numWorkersscheduleWorkId terminate terminateWith scheduleWork scheduleWork_scheduleWorkId_ terminate_trivialScheduler_ traverse_traverseConcurrentlytraverseConcurrently_replicateConcurrentlyreplicateConcurrently_ withSchedulerwithScheduler_$fExceptionWorkerException#$fExceptionWorkerTerminateException$fShowWorkerException$fShowWorkerTerminateExceptionJQueueJobRetireJob_mkJob newJQueue pushJQueue popJQueue readResultsWorkerTerminateExceptionWorkerExceptionbaseGHC.Exception.Type SomeException Data.FoldablemapM_Data.Traversable TraversableFoldable scheduleJobs_retireWorkersNdropCounterOnZero runWorkerghc-prim GHC.TypesIOhandleWorkerExceptionwithSchedulerInternal