Parallel Computing Toolkit — Examples Interval MinimumPreparationMake sure you have at least two kernels available. Auxiliary Data TypesThis example makes use of a number of ad hoc data types that are defined in this section. Domain/Range PairsPriority QueueWe need to queue pairs of {domain rectangle, range interval}, sorted by the decreasing lower bound of the range. We can use PCT's priority queue. Note: For this example the Parallel/Queue directory of PCT must be installed on all remote machines. The copyright of the queue packages allows you to do that even if PCT itself is not licensed on the remote machines. Client-side access Interval ArithmeticMerge Domain IntervalsOne-dimensional case, slow. Interval Driver LoopBag for Remote Result StorageWe choose the fastest queue implementation; the order in which items are stored is not important. Remote Priority QueuesHere are the priority queues on the remote kernels. SynchronizationThe idea is to do all in one call: update minmax, look at the global queue size, and get an interval and the current minmax value. Atomic update Driver CodeThis procedure will be run on each remote kernel. Sequential TestWe define an example function and run the driver code sequentially on the master kernel for testing. Go for ItThis section contains several test examples. Optionally you may enable tracing to see how the computation is synchronized. When you do so, you should use larger tolerance values to avoid too much output. 1D Example 1 (With Annotations)Define the function whose minimum should be found. Define the rectangle or interval over which the search should be performed. Choose a search tolerance. The smaller it is, the longer it will take to find the minimum. A few initial splits of the domain are used to initialize the queue. Initialize the queue by entering the rectangles into it. Initialize the shared variables and start the driver code on all remote kernels. Before it finishes, the driver will print statistics about its performance. Here is the minimum found. We collect all intervals in which the minimum may lie. Here is the interval containing the minimum and the list of domain intervals where it lies. 1D Example 2Here are a few initial splits to prime the queue. 2DHere are a few initial splits to prime the queue. 2D (Janos Pinter)Here are a few initial splits to prime the queue. Wood (4D)Here are a few initial splits to prime the queue. PerformanceDefine Performance[] from the Performance Measurement and Calibration example notebook. Set up an example function as before, then adjust the desired tolerance. Run it. Here is the remote processor utilization in %. |