# akashkinkarpandey/multithreaded-merge-sort architecture

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

- Interactive diagram: https://gitdiagram.com/akashkinkarpandey/multithreaded-merge-sort
- Repository: https://github.com/akashkinkarpandey/multithreaded-merge-sort

## Overview

##### Project Context and Components
- The project implements a multi-threaded merge sort algorithm in C++.
- The main entry point is in src/main.cpp.
- Two sorting implementations are provided in the src/sorting directory: one for parallel execution (parallelMergeSort) and one for a simpler (possibly sequential) merge sort (simpleMergeSort).
- The parallel version employs threading for splitting the workload and merging sorted subarrays.

##### Identifying Key Components
- Entry Point: main() from src/main.cpp.
- Sorting Module: The sorting logic divided into separate files:
a. parallelMergeSort (both .cpp and .hpp) — handles the multi-threading part.
b. simpleMergeSort (both .cpp and .hpp) — handles a more straightforward merge sort.
- Threading: Illustrate where new threads are created, managed, and joined, especially within the parallel merge sort implementation.
- Data: Show how input data (dataset to be sorted) flows into the sorting functions and how the result is produced.

- Begin at main().
- Clearly split into the choosing of the algorithm (parallel or simple).
- In the parallel branch: Show data partitioning → spawning threads → concurrent sort → merging results.
- In the sequential branch: Show direct recursive sorting.
- End with output of the sorted array.

## Diagram (Mermaid)

```mermaid
flowchart TD
    m["main() in main.cpp"]
    d{"Sorting Decision?"}
    
    m --> d
    
    d -- "parallel" --> ps["parallelMergeSort.cpp"]
    ps --> ph["parallelMergeSort.hpp"]
    ph --> pp["Data Partitioning"]
    pp --> tc["Thread Creation (for each partition)"]
    tc --> ce["Concurrent Sorting (Threads)"]
    ce --> ms["Merge Sorted Sublists"]
    
    d -- "sequential" --> ss["simpleMergeSort.cpp"]
    ss --> sh["simpleMergeSort.hpp"]
    sh --> rd["Recursive Divide-and-Conquer"]
    
    ms --> j["Reassemble Sorted Data"]
    rd --> j
    
    j --> out["End/Output Sorted Array"]
    
    click m "https://github.com/akashkinkarpandey/multithreaded-merge-sort/blob/main/src/main.cpp"
    click ps "https://github.com/akashkinkarpandey/multithreaded-merge-sort/blob/main/src/sorting/parallelMergeSort.cpp"
    click ph "https://github.com/akashkinkarpandey/multithreaded-merge-sort/blob/main/src/sorting/parallelMergeSort.hpp"
    click ss "https://github.com/akashkinkarpandey/multithreaded-merge-sort/blob/main/src/sorting/simpleMergeSort.cpp"
    click sh "https://github.com/akashkinkarpandey/multithreaded-merge-sort/blob/main/src/sorting/simpleMergeSort.hpp"
    
    class m main;
    class d decision;
    class ps,ph,ss,sh module;
    class pp,tc,ce,rd process;
    class j merge;
    class out io;
    
    classDef main fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef decision fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef module fill:#A9DFBF,stroke:#000,stroke-width:2px;
    classDef process fill:#FAD7A0,stroke:#000,stroke-width:2px;
    classDef merge fill:#D2B4DE,stroke:#000,stroke-width:2px;
    classDef io fill:#AED6F1,stroke:#000,stroke-width:2px;
```
