A09 - MPI + OpenMP Mixed Heat
Assignment: GitHub Classroom
Late Policy
- You have until the assigned due date, after that you will receive 0 points.
Heat Diffusion Simulation with MPI+OpenMP (25 points)
Overview
In this assignment, you will develop a hybrid MPI+OpenMP C++ program, mixedHeat
, that simulates heat diffusion on a 2D grid and outputs frames of the simulation as PPM images using a blue-to-red colormap. The grid is partitioned among MPI processes (by rows), and each process uses OpenMP to update its portion of the grid in parallel. Fixed boundary conditions are applied: the global top boundary is held at 100.0 (hot), and all other boundaries are maintained at 0.0 (cold). The program periodically gathers the complete grid from all processes and writes a PPM image to visualize the simulation.
Objectives and Expected Learning Outcomes
Hybrid Parallel Programming
- MPI is used for distributed memory communication, and OpenMP is for shared memory parallelism.
- Implement ghost row exchange (using, for example,
MPI_Sendrecv
) to manage boundary data between processes. - Collect the distributed grid data on the root process (using, for example,
MPI_Gatherv
).
Visualization and Image Output
- Map temperature values (0.0 to 100.0) to a blue-to-red colormap (0.0 maps to blue
[0, 0, 255]
and 100.0 maps to red[255, 0, 0]
). - Automatically output the simulation state as a PPM image every X timesteps (specified via a command-line argument).
Performance and Build Management
- Hybrid Parallelism: Leverage MPI (distributed memory) and OpenMP (shared memory) to simulate heat diffusion on a 2D grid efficiently.
-
Data Collection: Run the simulation under multiple configurations (varying the number of MPI processes and OpenMP threads), recording key metrics (e.g., execution time, iteration counts) in a CSV file (
mixedHeat.csv
). Note: This can be done in your submission script and does not need to be in the code itself, but how you do it is your choice. - Analysis Artifacts: Use the CSV data to create visualizations (e.g., heatmaps, bar charts) that reveal performance trends and insights.
-
Makefile Management: Provide a
Makefile
that compiles your code into an executable namedmixedHeat
and cleans up build artifacts (does not remove any scripts you use, the CSV file, analysis graphs, or sample PPM files).
Instructions
Part 1: Extending the C++ Program
-
Create a File:
- Modify the provided starter code
mixedHeat.cc
.
- Modify the provided starter code
-
Implement the Following Features:
-
Heat Diffusion Simulation:
- Partition the global 2D grid (fixed at 1920x1024) among MPI processes.
- Implement the exchange of ghost rows between neighboring processes (e.g.,
MPI_Sendrecv
). - Use OpenMP to update the interior grid cells (each cell updated as the average of its four neighbors).
-
PPM Image Output:
- Save an output image every X iteration (where X is a frame interval provided as a command-line argument) by gathering the complete grid onto process 0 (e.g.,
MPI_Gatherv
). - Implement a function that maps grid values to RGB colors using a linear blue-to-red colormap and outputs a PPM image (e.g.,
mixedHeatXXXX.ppm
).
- Save an output image every X iteration (where X is a frame interval provided as a command-line argument) by gathering the complete grid onto process 0 (e.g.,
-
Error Handling and Documentation:
- Ensure proper error handling for MPI operations and file I/O.
- Please be sure to comment your code to explain your design choices and the simulation steps.
-
Heat Diffusion Simulation:
Part 2: Makefile
-
Create a
Makefile
:- The Makefile should compile
mixedHeat.cc
into an executable namedmixedHeat
. - Include targets for
make all
(to build) andmake clean
(to remove executables and object files).
- The Makefile should compile
-
Test Your Build:
- Verify that your Makefile compiles the code without errors and produces the correct executable.
Part 3: Data Collection and Analysis
-
Gather Performance Data:
- Run your mixedHeat program multiple times, varying the number of MPI ranks (i.e., processes) and the number of OpenMP threads per rank.
- Record relevant performance metrics (e.g., wall-clock time, iterations, grid size) in a CSV file (
mixedHeat.csv
).
-
Create an Analysis Artifact:
- Use the CSV data to visualize or analyze how your hybrid MPI+OpenMP configuration impacts performance.
- You may generate a heatmap, line chart, or any other suitable plot to illustrate relationships between the number of ranks, threads, and runtime.
- Example: A heatmap (like the one shown below) where rows represent the number of MPI ranks, columns represent the number of OpenMP threads, and cell colors represent average run time.
Note: This heatmap is just one way to approach the analysis. You are free to choose different visualization methods or performance metrics as long as you produce some artifact that supports your performance discussion.
-
Interpret Your Findings:
- Summarize any trends or interesting observations in your results. For instance, explain why specific configurations yielded faster or slower performance.
- Reflect on how load balancing, communication overhead, and shared-memory parallelism might have influenced your results.
- Provide insights into how one might select an optimal combination of MPI ranks and OpenMP threads based on factors like system architecture or problem size.
Submission Guidelines and Evaluation Criteria
-
Add/edit: the following files in your GitHub repository:
-
mixedHeat.cc
– Your hybrid MPI+OpenMP C++ source code. -
Makefile
– To build the executable. -
mixedHeat.csv
- Data collected for your analysis. - Three randomly selected PPM images generated during your simulation.
-
mixedHeatReflection.txt
– A brief document describing your approach, challenges, and lessons learned—primarily focusing on the hybrid MPI+OpenMP design. Discuss how you partitioned the 2D grid across MPI processes, exchanged ghost rows (e.g., via MPI_Sendrecv), and leveraged OpenMP for parallel updates within each process. Include insights on balancing MPI vs. OpenMP, any performance comparisons, and your overall experience integrating distributed and shared-memory techniques.
-
-
Execution environment: Your simulation must be run on either
lakeshore.acer.uic.edu
orcrux.alcf.anl.gov
. - Follow the Assignment Submission Instructions when committing and pushing your repository.
- Your work will be evaluated based on adherence to the instructions, file naming, code quality, completeness, and the depth of your reflection.