English
Tasks
Complete the task of the chosen difficulty level for your variant number.
Variants
Variant 1. Function integration
1. Initial level. Create a C++ console program with MPI that computes the integral MPI_Bcast, each rank sums its part, MPI_Reduce collects the sum, and rank 0 prints the result and the MPI_Wtime time.
2. Basic level. Create a C++ console program with MPI that, on rank 0, prompts for the function number (
3. Advanced level. Create a CMake project with a C++ MPI program integrate that computes the integral of a function by distributing steps among ranks, with options --func <name>, --range <a>:<b>, --steps <n>, --rule rect|trap|simpson, --csv <file>, and --help. The program computes the integral with three rules and writes the number of processes, the rule, the time, and the error to CSV. A script runs the program for 1–8 processes and prints a table of speedup and efficiency; invalid options produce a message on stderr and code 1.
Variant 2. Matrix multiplication
1. Initial level. Create a C++ console program with MPI that multiplies two random MPI_Bcast and the rows of MPI_Scatter, each rank multiplies its rows, and MPI_Gather collects
2. Basic level. Create a C++ console program with MPI that prompts for the matrix size MPI_Scatterv and MPI_Gatherv, verifies the result with sequential multiplication on rank 0, and prints the computation time and communication time separately along with their fractions.
3. Advanced level. Create a CMake project with a matmul program with options --size <n>, --algo rows|cannon, --repeat <k>, --csv <file>, and --help that implements row distribution and Cannon’s algorithm on a square process grid (MPI_Cart_create, MPI_Cart_shift, MPI_Sendrecv_replace), checks that the number of processes is a perfect square, and prints a “processes – algorithm – time – GFLOPS – communication fraction” table. Parameter errors produce code 1.
Variant 3. Odd–even sort
1. Initial level. Create a C++ console program with MPI in which each rank generates 100,000 random integers (the seed equals the rank), sorts them with std::sort, and then performs MPI_Sendrecv and merging), after which rank 0 gathers the array and checks that it is sorted.
2. Basic level. Create a C++ console program with MPI that prompts for the total count of numbers (from
3. Advanced level. Create a CMake project with an oddeven program with options --count <n>, --distribution uniform|sorted|reverse, --input <file>, --output <file>, and --help that reads numbers from a binary file (each rank reads its own part), sorts them with the odd–even method with early termination (MPI_Allreduce of a change flag), writes the result, and prints a timing table for 1–8 processes and three distributions. File errors produce code 2.
Variant 4. Monte Carlo estimation of π
1. Initial level. Create a C++ console program with MPI in which each rank generates std::mt19937_64 generator seeded with MPI_Reduce, prints the estimate of
2. Basic level. Create a C++ console program with MPI that prompts for the total number of points and a base seed, divides the points among ranks (the remainder goes to the first ranks), prints the estimate of
3. Advanced level. Create a CMake project with a C++ MPI program mcpi that estimates --points <n>, --seed <s>, --target <error>, and --help. The program doubles the number of points until the standard error (computed via MPI_Allreduce of sums and sums of squares) falls below the target, and prints a table of iterations and the efficiency for 1–16 processes. Unreachable precision within
Variant 5. 2D plate heat conduction
1. Initial level. Create a C++ console program with MPI that simulates heat conduction in a square plate of MPI_Sendrecv, and prints the mean temperature.
2. Basic level. Create a C++ console program with MPI that prompts for the plate size and the number of steps, uses a two-dimensional Cartesian topology (MPI_Dims_create, MPI_Cart_create, MPI_Cart_shift) and a derived type for columns, checks that the mean temperature matches the single-process result, and prints the time and the communication fraction.
3. Advanced level. Create a CMake project with a C++ MPI program heat2d that simulates heat conduction in a square plate with an explicit scheme, with the grid divided among processes and halo exchange, with options --size <n>, --steps <k>, --decomp strips|grid (strips or a Cartesian grid), --weak, --csv <file>, and --help. The program measures strong and weak scaling (in --weak mode, the size per process is constant) for 1–16 processes and writes the time, communication time, and efficiency to CSV. An invalid number of processes for the grid produces code 1.
Variant 6. Mandelbrot manager–worker
1. Initial level. Create a C++ console program with MPI that computes a 1200×800 Mandelbrot set (at most 1000 iterations): rank 0 hands out row numbers to workers one at a time, collects the results, and writes the image to mandel.pgm.
2. Basic level. Create a C++ console program with MPI that computes the Mandelbrot set and writes it to PGM. The program prompts for the resolution, the maximum number of iterations, and the number of rows per task (1–64), implements static row distribution and dynamic distribution (manager–worker), and prints for both the time, the number of rows of each worker, and the ratio of the times of the fastest and slowest workers.
3. Advanced level. Create a CMake project with a C++ MPI program mandelmw that computes the Mandelbrot set with the manager–worker scheme (the manager also computes rows between replies, MPI_Iprobe) with options --size <w>x<h>, --iter <n>, --chunk <k>, --mode static|cyclic|dynamic, --image <file.pgm>, --csv <file>, and --help. The program writes the image and prints a timing table for all modes and chunk sizes on 2–16 processes.
Variant 7. Distributed k-means
1. Initial level. Create a C++ console program with MPI in which each rank generates 200,000 random points in the plane around three centers, and the k-means algorithm (MPI_Allreduce at each iteration; rank 0 prints the centers found.
2. Basic level. Create a C++ console program with MPI that clusters points in the plane with the k-means algorithm. The program prompts for the number of points, MPI_Scatterv, runs iterations (cluster sums are combined with MPI_Allreduce) until the shift is below the threshold, and prints the centers, the number of points in the clusters, the number of iterations, and the time per iteration.
3. Advanced level. Create a CMake project with a kmeans program with options --input <file.csv>, --k <k>, --max-iter <n>, --tol <e>, --output <file.csv>, and --help that reads points from CSV (each rank reads its own share of the lines), writes the cluster labels, and prints a “processes – iterations – time per iteration – MPI_Allreduce fraction” table. Format errors produce the line number on stderr and code 2.
Variant 8. A histogram of large data
1. Initial level. Create a C++ console program with MPI in which rank 0 generates MPI_Scatter, each rank builds a histogram of 10 bins, and MPI_Reduce with MPI_SUM over an array of 10 counters collects the overall histogram.
2. Basic level. Create a C++ console program with MPI that prompts for the number of values and the number of bins, distributes the data with MPI_Scatterv, builds a histogram, checks that the sum of the counters equals the number of values, and prints the histogram as text bars and the time for different numbers of processes.
3. Advanced level. Create a CMake project with a histo program with options --input <file>, --bins <k>, --range <min>:<max>, --auto-range, and --help that reads a binary file of double numbers (each rank reads its own part via a file offset), finds the limits via MPI_Allreduce with --auto-range, and prints the histogram, the quartiles, and the time. A missing file produces code 2.
Variant 9. The Game of Life with nonblocking exchange
1. Initial level. Create a C++ console program with MPI that simulates the Game of Life on a MPI_Sendrecv, and prints the number of live cells after 100 generations.
2. Basic level. Create a C++ console program with MPI that simulates Conway’s Game of Life on a toroidal board divided into horizontal strips. The program prompts for the board size and the number of generations, exchanges halo rows with nonblocking MPI_Isend/MPI_Irecv, computes the interior rows during the exchange and the boundary rows after MPI_Waitall, and compares the time with a blocking version (MPI_Sendrecv).
3. Advanced level. Create a CMake project with a C++ MPI program lifempi that simulates Conway’s Game of Life with the board divided into strips and halo exchange, with options --size <n>, --gens <k>, --exchange blocking|overlap, --pattern <file.rle>, --snapshot <step>, and --help. The program loads a pattern from an RLE file, saves snapshots of the board to PGM (gathered on rank 0), and prints a timing table of both exchange methods for 1–16 processes.
Variant 10. Primes in a range
1. Initial level. Create a C++ console program with MPI that counts the primes from 2 to MPI_Reduce sums the counts; rank 0 prints the count and the time of each rank (MPI_Gather).
2. Basic level. Create a C++ console program with MPI that prompts for the range limits, compares block, cyclic (number
3. Advanced level. Create a CMake project with a primes program with options --range <a>:<b>, --method trial|sieve, --split block|cyclic|dynamic, --list <file>, and --help, where the sieve method is a segmented sieve of Eratosthenes (the base primes are broadcast with MPI_Bcast), and --list writes the numbers found (gathered with MPI_Gatherv). Print a timing table for all combinations.
Variant 11. Sample sort
1. Initial level. Create a C++ console program with MPI in which each rank sorts 200,000 random numbers, rank 0 gathers MPI_Bcast, after which the program prints how many numbers of each rank fall into each bucket.
2. Basic level. Create a C++ console program with MPI that sorts random numbers generated on each rank with the full sample sort algorithm: local sorting, choosing splitters from samples, exchanging counts with MPI_Alltoall, exchanging buckets with MPI_Alltoallv, local merging, and checking the ordering at rank boundaries. The program prints the bucket sizes, the imbalance factor, and the time.
3. Advanced level. Create a CMake project with a samplesort program with options --count <n>, --distribution uniform|normal|zipf, --oversampling <s>, and --help that compares sample sort with odd–even sort and with gathering on rank 0 followed by std::sort, and prints a table of time and imbalance for 1–16 processes. A failed ordering check produces code 4.
Variant 12. PageRank of a small web graph
1. Initial level. Create a C++ console program with MPI that computes PageRank (damping factor 0.85, 50 iterations) for a graph of 8 pages defined in the program: each rank updates the ranks of its pages, and MPI_Allgather gathers the vector on all processes; print the page ranks.
2. Basic level. Create a C++ console program with MPI that reads a graph from an edge list (the user enters the file name), distributes vertices among ranks taking the remainder into account (MPI_Allgatherv), runs iterations until the change is below MPI_Allreduce of the norm), and prints the 10 pages with the highest rank and the number of iterations.
3. Advanced level. Create a CMake project with a pagerank program with options --edges <file>, --damping <d>, --tol <e>, --top <k>, and --help that generates or reads a graph (up to
Variant 13. The n-body problem on a ring
1. Initial level. Create a C++ console program with MPI in which each rank has 500 bodies with random masses and coordinates, blocks of bodies are passed around a ring (MPI_Sendrecv)
2. Basic level. Create a C++ console program with MPI that prompts for the number of bodies and steps and simulates the motion of bodies under mutual gravitation with the Euler method: blocks of bodies are passed around a ring of ranks. The program checks conservation of the system’s momentum (MPI_Reduce) and prints the time per step and a comparison with a version in which all coordinates are gathered with MPI_Allgather.
3. Advanced level. Create a CMake project with a C++ MPI program nbodyring that simulates the motion of bodies under mutual gravitation with options --bodies <n>, --steps <k>, --exchange ring|allgather, --overlap, --csv <file>, and --help. In ring mode, blocks of bodies are passed around a ring of ranks, and with --overlap, with nonblocking operations while the forces of the current block are computed. The program writes the trajectories of three bodies and prints a timing table for 1–16 processes.
Variant 14. A word counter for files
1. Initial level. Create a C++ console program with MPI that receives text file names as arguments, distributes the files among ranks by number (MPI_Reduce), printing the total number of words.
2. Basic level. Create a C++ console program with MPI that, for the files in a given folder, builds frequency dictionaries on each rank, sends them to rank 0 as variable-length strings (MPI_Probe and MPI_Get_count), merges them, and prints the 20 most frequent words and the time.
3. Advanced level. Create a CMake project with a C++ MPI program wordcount that builds a word frequency dictionary for the text files of a folder, distributing the files among ranks, with options --dir <folder>, --top <k>, --min-length <n>, --balance files|bytes (by number of files or by total size), and --help. The ranks’ dictionaries are merged by a tree of pairwise exchanges (
Variant 15. Election results
1. Initial level. Create a C++ console program with MPI in which each rank simulates a polling station: it generates the votes of 1000 voters for 5 candidates (the seed equals the rank), and MPI_Reduce of an array of 5 counters gives the total on rank 0 with percentages.
2. Basic level. Create a C++ console program with MPI in which each rank produces a variable-length text report of its polling station (number, number of voters, votes), and rank 0 gathers the reports with MPI_Gatherv (lengths with MPI_Gather), verifies the checksums, and prints a table of stations and the total.
3. Advanced level. Create a CMake project with an elections program with options --input <reports folder>, --threshold <percent>, --report <file.csv>, and --help that distributes the report files among ranks, detects reports with errors (the sum of votes exceeds the number of voters), and prints the total, the candidates above the threshold, and a list of erroneous reports on stderr; code 3 if there are errors.
Variant 16. A hybrid Jacobi method
1. Initial level. Create a C++ console program with MPI and OpenMP that solves the system #pragma omp parallel for; use MPI_Init_thread with MPI_THREAD_FUNNELED.
2. Basic level. Create a C++ console program with MPI and OpenMP that solves the system MPI_Allreduce every 10 iterations), checks the provided thread support level, and prints the number of ranks, threads, and iterations, the time, and the error.
3. Advanced level. Create a CMake project with a C++ MPI and OpenMP program hybridjacobi that solves the system --size, --iters, --csv, and --help. A script runs the program in “ranks × threads” configurations 8×1, 4×2, 2×4, 1×8 with --map-by slot:PE=<t> and --report-bindings, checks the binding, and writes the time, communication time, and speedup to CSV.
Variant 17. Breadth-first search in a graph
1. Initial level. Create a C++ console program with MPI that, for a MPI_Allgather; print the number of levels and the number of vertices at each level.
2. Basic level. Create a C++ console program with MPI that generates a random graph (the user enters the number of vertices and the average degree), performs BFS by sending requests to vertex owners via MPI_Alltoall of counts and MPI_Alltoallv of vertices, and prints the distances to 10 random vertices and the time.
3. Advanced level. Create a CMake project with a bfsmpi program with options --graph <file>, --source <v>, --distances <file>, and --help that reads a graph as an edge list, verifies the result with a sequential BFS on rank 0 for graphs of up to
Variant 18. Gaussian elimination
1. Initial level. Create a C++ console program with MPI that solves an MPI_Bcast; print the maximum residual.
2. Basic level. Create a C++ console program with MPI that prompts for MPI_Allreduce with MPI_MAXLOC) and back substitution, and prints the residual, the time, and a comparison of block and cyclic row distributions.
3. Advanced level. Create a CMake project with a gaussmpi program with options --input <file>, --size <n>, --distribution block|cyclic, --output <file>, and --help that reads a system from a text file, detects a singular matrix (code 3), writes the solution, and prints a table of time and residual for 1–16 processes.
Variant 19. The 1D wave equation
1. Initial level. Create a C++ console program with MPI that simulates string vibration (an explicit scheme for the wave equation, MPI_Sendrecv, and prints the energy of the string at the beginning and at the end.
2. Basic level. Create a C++ console program with MPI that simulates string vibration (an explicit scheme for the wave equation) divided into blocks among ranks with halo exchange. The program prompts for the number of nodes per process, the number of steps, and the Courant number (with a stability check), measures weak scaling for 1–16 processes, and prints the time, the efficiency, and the change in the string’s energy.
3. Advanced level. Create a CMake project with a C++ MPI program wave1d that simulates string vibration with an explicit scheme for the wave equation, with blocks of nodes on ranks and halo exchange, with options --nodes <n>, --steps <k>, --courant <c>, --mode strong|weak, --snapshots <folder>, and --help. The program writes string profiles to CSV (gathered with MPI_Gatherv), checks energy conservation within a tolerance, and prints a scalability table. An unstable scheme produces code 1.
Variant 20. Retail chain sales statistics
1. Initial level. Create a C++ console program with MPI in which rank 0 creates 100,000 sales records (a structure: store, amount, date), describes them with a derived type MPI_Type_create_struct, and distributes them with MPI_Scatter, and MPI_Reduce sums the revenue for 10 stores.
2. Basic level. Create a C++ console program with MPI that reads sales records from CSV on rank 0 (the user enters the file name), distributes them with MPI_Scatterv using a derived type, computes the revenue, the number of receipts, and the average receipt by store and month, and prints a table.
3. Advanced level. Create a CMake project with a salesmpi program with options --input <file.csv>, --group shop|month|both, --top <k>, --report <file>, and --help that finds the largest receipt with the store number using a custom reduction operation (MPI_Op_create), skips invalid lines with a message on stderr, and prints a report. A missing file produces code 2.
Variant 21. Ray tracing
1. Initial level. Create a C++ console program with MPI that renders a scene of three spheres (an 800×600 image, one ray per pixel), distributing rows among ranks and gathering them with MPI_Gather on rank 0 into scene.ppm.
2. Basic level. Create a C++ console program with MPI that renders a scene of spheres by ray tracing. The program prompts for the resolution and the number of rays per pixel, distributes 32×32 tiles among workers with the manager–worker scheme, gathers the image into a PPM file, and prints the time and the number of tiles of each worker.
3. Advanced level. Create a CMake project with a C++ MPI program raympi that renders by ray tracing (with shadows and reflections) a scene described in a text file, distributing image tiles among processes. Options: --scene <file>, --size <w>x<h>, --spp <n>, --tile <k>, --output <file.ppm>, --help. The program saves the image and prints a timing table for static and dynamic tile distribution on 2–16 processes.
Variant 22. Forest fires
1. Initial level. Create a C++ console program with MPI that simulates a forest fire cellular automaton (tree, fire, ash) on a
2. Basic level. Create a C++ console program with MPI that simulates a forest fire cellular automaton (tree, fire, ash) on a grid with a 2D Cartesian topology and halo exchange. The program prompts for the grid size, the forest density, and the ignition probability, uses independent generators based on global coordinates (the result does not depend on the number of processes), and prints the fraction of burned trees and the number of steps until the fire dies out.
3. Advanced level. Create a CMake project with a C++ MPI program fire that simulates a forest fire cellular automaton on a grid distributed among processes with options --size <n>, --density <d1,d2,…>, --runs <k>, --wind <direction>, --csv <file>, and --help. For each forest density, the program performs
Variant 23. Substring search in a genome
1. Initial level. Create a C++ console program with MPI in which rank 0 generates a DNA sequence of MPI_Scatter, each rank counts the occurrences of a given pattern of length 12 in its part, and MPI_Reduce gives the total count.
2. Basic level. Create a C++ console program with MPI that finds all occurrences of a pattern of length MPI_Sendrecv) to account for occurrences at part boundaries. The positions of the occurrences are gathered with MPI_Gatherv on rank 0 and verified with a sequential search.
3. Advanced level. Create a CMake project with a dnasearch program with options --genome <file.fasta>, --patterns <file>, --mismatches <k>, and --help that searches for several patterns allowing
Variant 24. Simpson’s rule integration to a given precision
1. Initial level. Create a C++ console program with MPI that computes
2. Basic level. Create a C++ console program with MPI that computes an integral with Simpson’s rule with subintervals distributed among ranks. The program prompts for the function, the limits, and the precision, doubles the number of subintervals until the difference between two approximations (identical on all ranks thanks to MPI_Allreduce) is below the precision, and prints a table of doublings.
3. Advanced level. Create a CMake project with a simpson program with options --func <name>, --range <a>:<b>, --eps <e>, --adaptive, and --help, where the --adaptive mode distributes subintervals with the manager–worker scheme with recursive subdivision, and print a comparison of the uniform and adaptive methods by the number of function evaluations and the time.
Variant 25. Document clustering in groups
1. Initial level. Create a C++ console program with MPI that divides processes into two groups with MPI_Comm_split (even and odd ranks); each group computes the sum of its ranks with MPI_Allreduce in its own communicator, and each process prints its rank in the world and in the group.
2. Basic level. Create a C++ console program with MPI in which documents (frequency vectors of 100 words) are distributed among ranks, processes are divided into
3. Advanced level. Create a CMake project with a docclust program with options --input <folder>, --k-list 2,4,8, --groups <g>, and --help that builds TF-IDF vectors of text files, runs k-means for different
Variant 26. Bank risk simulation
1. Initial level. Create a C++ console program with MPI in which each rank simulates MPI_Reduce, prints the average loss.
2. Basic level. Create a C++ console program with MPI in which ranks simulate scenarios of the annual change in portfolio value with the Monte Carlo method. The program prompts for the number of scenarios, the portfolio composition (3 assets with return and volatility), and the confidence level, gathers the losses on rank 0 (MPI_Gatherv), and prints the VaR, the expected shortfall, and a 95 % confidence interval of the mean.
3. Advanced level. Create a CMake project with a varsim program with options --portfolio <file.csv>, --scenarios <n>, --confidence 0.95,0.99, --seed <s>, and --help that computes VaR without gathering all scenarios (a histogram of losses via MPI_Reduce and a quantile search), compares it with the exact method for small
Variant 27. Blocking and nonblocking communication
1. Initial level. Create a C++ console program with MPI in which ranks form a ring and pass a block of 1000 double numbers to the right neighbor 100 times in three ways (MPI_Sendrecv, MPI_Isend/MPI_Irecv with MPI_Waitall, even/odd with MPI_Send/MPI_Recv) and prints the time of each.
2. Basic level. Create a C++ console program with MPI that prompts for the block size, demonstrates a deadlock with MPI_Ssend (after a timeout, MPI_Test prints a warning and terminates the program with MPI_Abort), and measures the size at which MPI_Send stops completing without a receiver.
3. Advanced level. Create a CMake project with an overlap program with options --sizes 1e3,1e5,1e7, --work <µs>, --mode block|nonblock|test, and --help that measures what fraction of the communication time can be hidden behind computation with nonblocking operations (with and without periodic MPI_Test), and prints a table for all sizes.
Variant 28. A hybrid Julia set
1. Initial level. Create a C++ console program with MPI and OpenMP that computes a Julia set (schedule(dynamic); rank 0 gathers the number of iterations.
2. Basic level. Create a C++ console program with MPI and OpenMP that computes a Julia set (rows among ranks, and within a rank among threads). The program prompts for MPI_Gatherv) into a PGM file, and prints the number of ranks, the number of threads, the thread support level, and the time.
3. Advanced level. Create a CMake project with a C++ MPI and OpenMP program juliahybrid that computes a Julia set (rows among ranks, and within a rank among threads) with options --c, --size, --iter, and --help, and a script that compares “ranks × threads” configurations with different --map-by and --bind-to (including --bind-to none and a single rank with 8 threads without PE), writes the time and the binding from --report-bindings to CSV, and prints the best configuration.
Variant 29. Prefix sum
1. Initial level. Create a C++ console program with MPI in which each rank has 1000 random numbers, computes a local prefix sum, and obtains its rank offset with MPI_Exscan; rank 0 gathers the array and verifies it with a sequential computation.
2. Basic level. Create a C++ console program with MPI that implements a prefix sum of the ranks’ sums with the recursive doubling algorithm (MPI_Sendrecv with rank MPI_Scan, and prints a table.
3. Advanced level. Create a CMake project with a prefix program with options --count <n>, --method scan|doubling|gather, --op sum|max, and --help that supports an arbitrary (not only a power of two) number of processes, verifies the result, and prints a timing table of the methods for 1–16 processes. A failed check produces code 4.
Variant 30. The α–β model
1. Initial level. Create a C++ console program with MPI in which ranks 0 and 1 perform a “ping-pong” with messages from 1 byte to 1 MB (in multiples of 4), and rank 0 prints a table of one-way transfer time and bandwidth.
2. Basic level. Create a C++ console program with MPI that measures a “ping-pong” for sizes from a file or the keyboard, finds
3. Advanced level. Create a CMake project with an alphabeta program with options --sizes <list>, --reps <k>, --pairs same-node|any, --csv <file>, and --help that measures the parameters for pairs of ranks on one node and on different nodes (a hostfile), predicts the halo exchange time for a given grid and number of processes, and compares it with the measured time.
Procedure
- Study the theory and worked examples.
- Install Open MPI in Ubuntu 26.04 (WSL2 or a virtual machine), check the version with
ompi_info --version, and run the “Hello, MPI” example with 4 processes. - Create a CMake project with
find_package(MPI REQUIRED)(andOpenMPfor hybrid tasks), implement a sequential version of the task, and verify the result of the parallel version for different numbers of processes, including ones that do not evenly divide the problem size. - Make sure there are no deadlocks: run the program with large messages and, if needed, replace
MPI_SendwithMPI_Ssendto check. - Measure the time for 1, 2, 4, 8, and 16 processes (median of at least 5 runs,
MPI_Wtime, the time of the slowest rank) and the communication fraction, and for hybrid tasks, different “ranks × threads” configurations with--report-bindings; build a table and a speedup chart and explain the results. If several VMs are available, repeat the measurements with a hostfile. - Demonstrate the program, explain the code and measurement results, and answer the review questions.