Parallel Computing Toolkit — Examples Large CalculationsPreparationMake sure you have at least two kernels available. Infinite SearchIntroductionIf you want to verify that the polynomials i x i-1 for n=1,2,... are all irreducible (an open conjecture), factor the polynomials and then check that the length of the list of factors is 2, one factor being the overall numerical factor. This computation will continue forever. To stop it, abort the local evaluation by pressing . or choosing Kernel Abort Evaluation. After the abort, collect any waiting results, as follows. Here is the definition of the polynomial in x with degree n. Parallel SearchHere you make the definition known to all remote kernels. Now you can start the computation, requiring that it print each result as it continues. To stop the computation, abort it by choosing Kernel Abort Evaluation or pressing . . CleanupAfter the abort, you can either wait for the currently running calculations, or you can abort the remote kernels. Handling the AbortYou can use CheckAbort[] to handle the abort in your program and define the cleanup code in the abort handler. Instrumented VersionHere is a version of the code suitable for a longer calculation. It generates output only if it finds a reducible polynomial. To monitor its operation, it also prints progress reports. The results returned from the remote kernels include the number of factors and the time the factorization took for later analysis. SetupHere is a sequential test of the remote code. The Main LoopAnalysisThe results are stored as downvalues of the symbol results. Here we check whether any degree has more than one factor. Here we plot the time it took to factor the polynomials (meaningful only if all remote processors are similar). Batch ProcessingLarge calculations should be run in batch mode by using the Mathematica kernel alone without the front end. Here is a step-by-step guide for turning the interactive calculation described in the previous sections of this notebook into a batch program that can be run unattended and writes results to a file. Collect the CodePrepare a notebook or a section in a notebook, such as this one, that contains all code necessary to perform the calculation without human intervention. For smaller problems, you can put all definitions and initializations directly into consecutive input cells. For larger problems, you can develop packages for subproblems and then load these packages into this notebook with Needs["Package`"]. Note that all code cells are marked as initialization cells. Make sure that no other cells in the notebook (such as test examples) are marked as initialization cells. Set Up PCTSet up the remote machines to be used for the calculation. For this test, only one local kernel is used. You may also have to define $RemoteCommand. Start all remote kernels. Problem-Specific DefinitionsHere is the code to search for factors of the polynomials from the previous section. Start the CalculationAs in the previous section, this calculation does not terminate. The code here handles an external interrupt (^C) delivered to the running kernel. CleanupDepending on how the interrupt was delivered, this section might not be reached. Stop remote kernels. Test the CodeTo test the code in the previous subsection, restart the kernel if necessary, then evaluate the initialization of this notebook choosing the corresponding Kernel Evaluation menu command. If you handle interrupts in your code, you can check it with the Kernel Abort Evaluation menu command. Write the Package FileEvery time you save this notebook, a corresponding package (.m) file is written that contains all initialization cells. (If this does not happen, the notebook option AutoGeneratedPackage needs to be set to Automatic.) Run the Calculation with the Kernel AloneYou can start a Mathematica kernel and give it the package.m file as input. The details depend on the operating system you are using. See the information in the Documentation Center. |