# tanvirahmedkhan74/dynapex architecture

> Architecture diagram of the GitHub repository tanvirahmedkhan74/dynapex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanvirahmedkhan74/dynapex
- Repository: https://github.com/tanvirahmedkhan74/dynapex

## Overview

##### Main components of the system
- Main Application: Represented by src/main.cpp, which drives the overall execution.
- Dependency Analysis Module: Implemented in src/dependency_checker.cpp and its corresponding header in include/dependency_checker.h; its role is to analyze code sections for data dependencies.
- Pragma Injection Module: Found in src/pragma_injector.cpp (with header include/pragma_injector.h); this part dynamically inserts OpenMP pragmas to enable parallelism.
- Dynamic Dispatcher: Located in src/dispatcher.cpp (and its header include/dispatcher.h), which, based on profiling data, selects whether to dispatch tasks to the CPU (using OpenMP) or the GPU (using OpenMP target offloading).
- Build Artifacts & Logging: The build directory holds the compiled binaries (e.g., main_parallel, dispatcher), while the logs directory contains execution logs, GPU statistics, and dependency graphs, indicated by files like execution_log.txt and valgrind.dot.
- Test Modules: Additional source files such as test_1.cpp and test_2.cpp support verification and experimentation.

##### Detail the relationships and interactions
- The Main Application (main.cpp) orchestrates the execution by calling the dependency analysis and then invoking the dynamic dispatcher.
- The Dependency Checker feeds critical information into the Pragma Injector which, by modifying the code with proper OpenMP directives, enables parallel execution.
- The Dynamic Dispatcher is crucial: It utilizes the profiling output (collected during execution and recorded in the logs) and, based on execution mode (Normal, CPU, or GPU), directs the computation accordingly.
- External tools (like Valgrind, Graphviz, and gprof2dot) are integrated indirectly for profiling, visualization, and performance analysis. They aren’t coded into the system but play a supporting role in architecture.

##### Architectural patterns and design principles
- Modular Design: The separation into independent modules (dependency analysis, pragma injection, and dispatcher) shows a modular design that makes it easier to develop, test, and maintain.
- Dynamic Decision Making: The dynamic dispatcher employs real-time profiling data to optimize performance—a design pattern that leverages runtime feedback.
- Integration with External Profiling Tools: The architecture assumes an external instrumentation and profiling loop, seen in the logs output and profiling steps detailed in the README.
- Use of Standard Parallelization Libraries: OpenMP is explicitly used for parallelism on the CPU and selectively on the GPU (via target offloading), indicating reliance on industry-standard libraries.

##### Relevant technologies, frameworks, or libraries
- C++ as the primary language.
- OpenMP for parallelization on the CPU and GPU.
- GNU Make for the build process, as detailed in the Makefile.
- Profiling tools such as Valgrind and Graphviz, along with gprof2dot for visualization.
- GPU support (using NVIDIA’s CUDA Toolkit and proprietary drivers) even though GPU integration is not yet fully optimized for CUDA/OpenCL workflows.

##### Specific elements that must appear
- Clear labels for each module/component:
- "Main Application (main.cpp)"
- "Dependency Analyzer (dependency_checker.cpp / .h)"
- "Pragma Injector (pragma_injector.cpp / .h)"
- "Dynamic Dispatcher (dispatcher.cpp / .h)"
- "Build Artifacts & Binaries (build/)"
- "Log & Profiling Tools (logs/)"
- "Test Modules (test_1.cpp, test_2.cpp)"
- From Main Application to Dependency Analyzer.
- From Dependency Analyzer to Pragma Injector.
- From both dependency analysis and profiling logs to the Dynamic Dispatcher.

- From there, branch out to display dependency analysis and pragma injection (which work in sequence) leading to the Dynamic Dispatcher.
- On the side, incorporate the logging and profiling framework which feeds back into the dispatcher to influence execution mode decisions.
- Build and test components as supporting blocks.
- To include notes about the integration of OpenMP for both CPU and GPU and the dynamic runtime profiling that modulates execution strategy.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    subgraph "Core Modules"
        A["Main Application (main.cpp)"]:::core
        B["Dependency Analyzer (dependency_checker.cpp / .h)"]:::core
        C["Pragma Injector (pragma_injector.cpp / .h)"]:::core
        D["Dynamic Dispatcher (dispatcher.cpp / .h)"]:::core
    end

    %% Supporting Components
    subgraph "Supporting Components"
        E["Build Artifacts & Binaries (build/)"]:::support
        F["Log & Profiling Tools (logs/)"]:::support
    end

    %% Test Modules
    subgraph "Test Modules"
        G["Test Module (test_1.cpp)"]:::test
        H["Test Module (test_2.cpp)"]:::test
    end

    %% Relationships
    A -->|"calls"| B
    B -->|"feeds"| C
    A -->|"orchestrates"| D
    F -->|"providesProfiling"| D

    %% Styles
    classDef core fill:#BBDEFB,stroke:#1E88E5,stroke-width:2px;
    classDef support fill:#C8E6C9,stroke:#43A047,stroke-width:2px;
    classDef test fill:#FFF9C4,stroke:#FDD835,stroke-width:2px;

    %% Click Events for Core Modules
    click A "https://github.com/tanvirahmedkhan74/dynapex/blob/main/src/main.cpp"
    click B "https://github.com/tanvirahmedkhan74/dynapex/blob/main/src/dependency_checker.cpp"
    click B "https://github.com/tanvirahmedkhan74/dynapex/blob/main/include/dependency_checker.h"
    click C "https://github.com/tanvirahmedkhan74/dynapex/blob/main/src/pragma_injector.cpp"
    click C "https://github.com/tanvirahmedkhan74/dynapex/blob/main/include/pragma_injector.h"
    click D "https://github.com/tanvirahmedkhan74/dynapex/blob/main/src/dispatcher.cpp"
    click D "https://github.com/tanvirahmedkhan74/dynapex/blob/main/include/dispatcher.h"

    %% Click Events for Supporting Components
    click E "https://github.com/tanvirahmedkhan74/dynapex/tree/main/build/"
    click F "https://github.com/tanvirahmedkhan74/dynapex/tree/main/logs/"

    %% Click Events for Test Modules
    click G "https://github.com/tanvirahmedkhan74/dynapex/blob/main/src/test_1.cpp"
    click H "https://github.com/tanvirahmedkhan74/dynapex/blob/main/src/test_2.cpp"
```
