How hardvan/mpi-analysis-using-llvm works
Main components
• MPI C/C++ Source Code: The source files (e.g., mpi_example.c, mpi_example2.c, original.c) that contain MPI calls.
• LLVM IR Generation: The process where clang is used to compile the MPI C code into LLVM IR (input.ll). This is a key preprocessing step.
• LLVM Analysis Pass (MPIAnalysisPass): The core analysis component implemented in MPIAnalysisPass.cpp which detects MPI_Send and MPI_Recv calls and extracts communication patterns.
• Shell Script Automation (run_mpi_analysis.sh): A tool that automates the compilation of the LLVM pass and the execution of the analysis, streamlining the workflow.
• Build and Execution Environment: The use of LLVM, Clang, MPI libraries (e.g., mpicc/mpirun), and associated build flags. These external dependencies are vital to correctly set up and run the analysis.
• Output Reporting: The generation of detailed output logs that display the detected MPI communication patterns, including data like communicator, tag, and rank.
Relationships and data flow
• Data Flow: Start from the MPI program source code that is compiled into LLVM IR using clang. The LLVM IR file then serves as the input for the analysis pass.
• Control Flow: The run_mpi_analysis.sh script manages the sequential process: IR generation → LLVM pass compilation → analysis execution.
• Internal Interactions: The LLVM Analysis Pass (MPIAnalysisPass.cpp) is loaded into the LLVM ‘opt’ tool as a plugin. It processes the IR and reports on MPI calls.
• External Dependencies: LLVM/Clang and MPI libraries are foundational – they support both the IR generation and the execution of MPI programs.
Architectural patterns and design principles
• Modular Design: The project separates various concerns clearly – input generation, analysis logic, and automation script are distinct components.
• Plugin Architecture: The LLVM analysis pass is built as a shared object and dynamically loaded by the LLVM ‘opt’ tool, illustrating extensible plugin use.
• Automated Workflow: Use of a shell script to encapsulate the multiple steps shows emphasis on automation and repeatability.
• Integration with External Tools: Clear integration with compilation tools and MPI libraries indicates that the design leverages standard components.
• Block is labeled clearly with its purpose (e.g., “MPI Source Code Files: mpi_example.c, mpi_example2.c, original.c”).
• Next to the LLVM IR generation step, note the command used (e.g., “clang -emit-llvm –S …”) and mention the dependency on MPI headers.
• For the LLVM Analysis Pass, note that it is implemented in C++ (MPIAnalysisPass.cpp) and compiled to a shared object (MPIAnalysisPass.so) using LLVM’s build flags.
• For the automation script, highlight its role in sequencing the operations.
• External dependencies (LLVM/Clang, mpicc/ MPI libraries) either as separate blocks or annotate them near the components that use them.
Detail and clarity
• Given the project’s multiple components, use a layered approach: show a high-level overview (workflow from source to analysis output) and then, if needed, expand individual components (especially the LLVM pass) to show internal steps like detecting MPI calls and reporting uniform participation.