HIGH_CARD_PARFOR is a MATLAB directory which uses the parfor statement to compute in parallel the statistics for a card game in which you are required to guess the location of the highest card.
The rules for this game are as follows. You are given a deck of DECK_SIZE cards.
Your goal is to select the high card. For convenience, we can assume the cards are a permutation of the integers from 1 to DECK_SIZE, but in fact the user mustn't see such values or else it's obvious which is the largest card. (For a truly difficult problem, we'd have to work harder to disguise the range of values and the likely distribution!)
Your choice is made under the following rules: You may turn over one card at a time. When a card is turned over, you may declare that to be your choice, or else turn over another card. If you have not chosen a card by the end, then your choice is the final card.
If you have no idea what to do, and simply decide in advance to pick a card "at random", that is, for example, you decide to pick the 15th card before having seen any cards, then your probability of winning is 1/DECK_SIZE.
The question is, can you do better than that?
A good strategy is as follows: always look at the first SKIP_NUM cards without choosing them. Then choose the very next card you encounter that is larger than the cards you skipped.
Now the question is, is there an optimal value of SKIP_NUM for a given DECK_SIZE? One way to find an approximate answer is to choose DECK_SIZE, and then, for each value of SKIP_NUM, play 1000 games, and keep track of how often you are right.
This program demonstrates how such a computation can be done in parallel using the PARFOR command.
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
HIGH_CARD_PARFOR is available in a MATLAB version.
COLLATZ_PARFOR, a MATLAB program which seeks the maximum Collatz sequence between 1 and N, running in parallel using MATLAB's "PARFOR" feature.
HEATED_PLATE_PARFOR, a MATLAB program which solves the steady (time independent) heat equation in a 2D rectangular region, using MATLAB's parfor facility to run in parallel.
HELLO_PARFOR, a MATLAB program which prints out "Hello, world!" multiple times, using MATLAB's parfor command for parallel execution.
MATLAB_PARALLEL, MATLAB programs which illustrate "local" parallel programming on a single computer with MATLAB's Parallel Computing Toolbox.
MATLAB_RANDOM_PARALLEL, MATLAB programs which illustrate the use of Matlab's random number generator (RNG) functions when using parallel features such as parfor or spmd.
MATRIX_ASSEMBLE_PARFOR, a MATLAB program which demonstrates the parfor parallel programming feature by assembling the Hilbert matrix in a parallel loop.
MD_PARFOR, a MATLAB program which carries out a molecular dynamics simulation, running in parallel using MATLAB's "PARFOR" feature.
ODE_SWEEP_PARFOR, a MATLAB program which demonstrates how the PARFOR command can be used to parallelize the computation of a grid of solutions to a parameterized system of ODE's.
PRIME_PARFOR, a MATLAB program which counts the number of primes between 1 and N; running in parallel using MATLAB's "PARFOR" feature.
QUAD_PARFOR, a MATLAB program which estimates an integral using quadrature; running in parallel using MATLAB's "PARFOR" feature.
SATISFY_PARFOR, a MATLAB program which demonstrates, for a particular circuit, an exhaustive search for solutions of the circuit satisfiability problem, running in parallel using MATLAB's "PARFOR" feature.
SPARSE_PARFOR, a MATLAB library which demonstrates how a sparse matrix can be constructed by evaluating individual blocks in parallel with the parfor command, and then assembled (on a single processor) using the sparse() command.
The User's Guide for the Parallel Computing Toolbox is available at http://www.mathworks.com/access/helpdesk/help/pdf_doc/distcomp/distcomp.pdf
HIGH_CARD_POOL executes the function locally and interactively.
HIGH_CARD_BATCH executes the function locally and noninteractively.
HIGH_CARD_FSU executes the function on the FSU HPC cluster, noninteractively.
You can go up one level to the MATLAB source codes.