Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/marcotallone/parallel-quicksort-algorithms

A collection of multiple parallel quicksort algorithms implemented in C both in MPI (distributed memory) and OpenMP (shared memory). UniTS, SDIC, 2023-2024.
https://github.com/marcotallone/parallel-quicksort-algorithms

c cmake hpc hpc-cluster hyperquicksort mpi openmp parallel-quicksort psrs quicksort slurm

Last synced: about 2 months ago
JSON representation

A collection of multiple parallel quicksort algorithms implemented in C both in MPI (distributed memory) and OpenMP (shared memory). UniTS, SDIC, 2023-2024.

Awesome Lists containing this project

README

        

[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]
[![Gmail][gmail-shield]][gmail-url]




Parallel Quicksort Algorithms in MPI and OpenMP


A collection of parallel quicksort algorithms implemented in MPI and OpenMP


Explore the docs ยป


Read the official report ยป




View Demo
ยท
Report Bug
ยท
Request Feature


๐Ÿ“‘ Table of Contents



  1. About The Project



  2. Getting Started


  3. Usage

  4. License

  5. Contact

  6. References

  7. Acknowledgments

## About The Project

This repository contains a different **parallel** implementations of the well-known **quicksort** sorting **algorithms**.\
Multiple algorithms have been implemented in `C` both in distributed memory, using the `MPI` library, and in shared memory, with `OpenMP` directives. Among the studied algorithms this repository includes the following parallel implementations:

* **(Simple) Parallel Quicksort**

* **Hyperquicksort**

* **Parallel Sort by Regular Sampling (PSRS)**

* **Task Quicksort** (`OpenMP` only)

More implementation-specific details are explained below.\
The whole project is organized as explained in the next section. All of the functions for the different algorithms have been implemented in dedicated files in the `src/` folder. The compilation of the library is managed through the `CMake` build system as explained below. The `apps/` folder contains some ready-to-use scripts that show how to use the implemented functions.\
The `python/` folder contains some scripts for plotting and analyzing the scaling data obtained from the execution of the algorithms on the **ORFEO** cluster at AREA Science Park, Basovizza (TS). The data from the scaling analysis are available in the `datasets/` folder.\
Further details about the study and the results obtained with these implementations can be fount in the [dedicated report](./parallel-quicksort-marco-tallone.pdf) that can be found in this repository.

### Project Structure

The project is organized with the following structure:

```bash
.
โ”œโ”€โ”€ ๐Ÿ“‚ apps # Ready-to-use scripts
โ”‚ย ย  โ””โ”€โ”€ main.c
โ”œโ”€โ”€ ๐Ÿ“‚ datasets # Datasets with scaling data
โ”œโ”€โ”€ ๐Ÿ“‚ include # Include headers
โ”‚ย ย  โ””โ”€โ”€ qsort.h
โ”œโ”€โ”€ ๐Ÿ python # Python scripts for plotting and analysis
โ”‚ย ย  โ”œโ”€โ”€ utils
โ”‚ย ย  โ””โ”€โ”€ scaling.ipynb
โ”œโ”€โ”€ ๐Ÿ“„ report.pdf # Report of the project
โ”œโ”€โ”€ ๐Ÿ“œ README.md # This file
โ”œโ”€โ”€ โš™ install.sh # Quick compilation and installation
โ”œโ”€โ”€ mpi.job # MPI job script for Slurm
โ”œโ”€โ”€ omp.job # OpenMP job script for Slurm
โ””โ”€โ”€ ๐Ÿ“‚ src # Source files
โ””โ”€โ”€ qsort.c
```

### Built With

![C](https://img.shields.io/badge/C-00CCFF?style=for-the-badge&logo=c&logoColor=white)
![Cmake](https://img.shields.io/badge/Cmake-00A3FF?style=for-the-badge&logo=cmake&logoColor=white)
![MPI](https://img.shields.io/badge/MPI-007AFF?style=for-the-badge&logo=mpi&logoColor=white)
![OpenMP](https://img.shields.io/badge/OpenMP-0052FF?style=for-the-badge&logo=openmp&logoColor=white)
![Python](https://img.shields.io/badge/Python-0000FF?style=for-the-badge&logo=python&logoColor=white)
![NeoVim](https://img.shields.io/badge/NeoVim-0700C4?style=for-the-badge&logo=neovim&logoColor=white)

(back to top)

### Implemented Quicksort Functions

This file presents here the main characteristics of the implemented functions and explains their practical usage.
The main implemented sorting functions are the folowing:

* `void serial_qsort(data_t *, int, int, compare_t)`: serial version of the quicksort algorithm. Takes in input the array to be sorted, the starting and ending index of the array and a comparison function to be used for sorting.

* `void omp_task_qsort(data_t *, int, int, compare_t)`: task-based parallel version using OpenMP. Takes in input the array to be sorted, the starting and ending index of the array and a comparison function to be used for sorting. This function requires to be used inside a parallel region as follows:

```c
#pragma omp parallel
{
#pragma omp single
{
omp_task_qsort(array, 0, N, compare_f);
}
}
```

* `void omp_parallel_qsort(data_t *, int, int, compare_t, int)`: shared memory version of the quicksort algorithm using OpenMP. Takes in input the array to be sorted, the starting and ending index of the array, a comparison function to be used for sorting and the depth of the recursive call (First call 0). Can be normally used as any other function in the main script.

* `void omp_hyperquicksort(data_t *, int, int, compare_t, int)`: shared memory version of the hyperquicksort algorithm using OpenMP. Takes in input the array to be sorted, the starting and ending index of the array, a comparison function to be used for sorting and the depth of the recursive call (First call is 0).

* `void omp_psrs(data_t *, int, int, compare_t)`: shared memory version of the PSRS algorithm using OpenMP. Takes in input the array to be sorted, the starting and ending index of the array and a comparison function to be used for sorting.

* `void MPI_Parallel_qsort(data_t **, int *, int *, int, MPI_Comm, MPI_Datatype, compare_t)`: distributed memory version of the quicksort algorithm using MPI. This function must be called after `MPI_Initialize()` to enable communication between multiple processes. Takes in input the local array to be sorted, the size of the local array, the rank of the process, the number of processes, the MPI communicator, the MPI specific datatype of the array elements and a comparison function to be used for sorting.

* `void MPI_Hyperquicksort(data_t **, int *, int *, int, MPI_Comm, MPI_Datatype, compare_t)`: distributed memory version of the hyperquicksort algorithm using MPI. This function must be called after `MPI_Initialize()` to enable communication between multiple processes. Takes in input the local array to be sorted, the size of the local array, the rank of the process, the number of processes, the MPI communicator, the MPI specific datatype of the array elements and a comparison function to be used for sorting.

* `void MPI_PSRS(data_t **, int *, int, int, int, MPI_Datatype, compare_t)`: distributed memory version of the PSRS algorithm using MPI. This function must be called after `MPI_Initialize()` to enable communication between multiple processes. Takes in input the local array to be sorted, the size of the local array, the size of the global array, the rank of the process, the number of processes, the MPI communicator, the MPI specific datatype of the array elements and a comparison function to be used for sorting.

The serial and shared memory versions sort the input array in place directly without the need of any additional operation. The MPI versions require the master process to initially split the input array in multiple chunks and to actually send the chunks to the different processes. The chunks are then sorted in place by the single processes. These can be merged by the master process at the end of the function execution to check for sorting correctness.
The `mpi_example.c` and `omp_example.c` script in the `apps/` folder show some [usage examples](./apps/).

(back to top)

## Getting Started

If you want to use the implemented `epyc` module you can follow these steps. It is anyway recommended to take a look at the scripts in the `apps/` folder for eventual [usage examples](./apps/example.py).

### Prerequisites

The following are needed to compile and run the parallel versions of the implemented algorithms:

* `CMake` build system
* `OpenMP`
* `MPI` library
* Access to **ORFEO** or another cluster with `Slurm` job scheduler for scaling jobs

### Installation

Compilation of the implemented library is performed with the `cmake` system.\
By executing the following commands (and eventually specifying the correct `-DCMAKE_PREFIX_PATH` for eventual third party libraries if not found) all the `C` libraries will be compiled in the `build/` folder.

```bash
cmake -S . -B build/

make -C build/ -j -D=ON
```

The library can be compiled in different modes. These includes the following:

* **serial** compilation: this will only compile the serial version of the library without any parallel algorithm.

* **openmp** compilation: this will compile the library with the OpenMP parallel algorithms, in order to enable this version compile with the option `-DOMP=ON`.

* **mpi** compilation: this will compile the complete library with the MPI parallel algorithms and also using OpenMP since these algorithm require it, in order to enable this version compile with the option `-DMPI=ON`.

All of these modes also include a debugging mode where no optimization is performed at compile time and some debugging flags are enabled. This can be enabled by adding the `-DDEBUG=ON` flag to the compilation command.

> [!NOTE]
> For a quick installation following these commands a `build.sh` script has been provided in the root folder. To compile more easily with this script you can pass the compile version you want as a command like argument. Accepted argument include `omp`, `mpi` or their debug versions `debug omp` and `debug mpi`.

After compilation the executables can be found in the `build/bin/` folder. In order to add a personal executable to be compiled with the library you just need to update the `MAIN_FILES` list in the provided `CMakeLists.txt` file by directly editing the file.\
In the root directory of the project there are also 2 Slurm job to showcase how to compile and use the library on the ORFEO cluster. These will run a scaling test to asses strong and weak scalability of the implementations depending on the specified input. The results of the test will be appended on a relative `csv` file in the `datasets/` folder. It's possible to visualize the file with an editor of choice or by running the `display.c` program if compiled by the cmake system. Further details on the scaling tests can be found in the `mpi_scaling.c` and `omp_scaling.c` files.

(back to top)

## Usage

To be able to use the implemented library in a `C` script it's possible to import the `qsort.h` header file and link to the library at compilation time. Compilation details are explained below.

```c
#include "qsort.h"
```

In the `apps/` folder the `mpi_example.c` and `omp_example.c` files provide a starting point with some basic [usage example](./apps/) of the implemented features.

(back to top)

## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

(back to top)

## Contact

| Contact Me | |
| --- | --- |
| Mail | |
| LinkedIn | [LinkedIn Page](https://linkedin.com/in/marco-tallone-40312425b) |
| GitHub | [marcotallone](https://github.com/marcotallone) |

(back to top)

## References

* [MPI Forum](https://www.mpi-forum.org/)
* [OpenMP](https://www.openmp.org/)
* [CMake](https://cmake.org/)
* [AREA Science Park](https://www.area.trieste.it/it/infrastrutture/orfeo)
* [ORFEO Documentation](https://orfeo-doc.areasciencepark.it/)
* [HPC UniTS](https://github.com/Foundations-of-HPC/High-Performance-Computing-2023)

(back to top)

## Acknowledgments

* [Best-README-Template](https://github.com/othneildrew/Best-README-Template?tab=readme-ov-file)

(back to top)

[forks-shield]: https://img.shields.io/github/forks/marcotallone/parallel-quicksort-algorithms.svg?style=for-the-badge
[forks-url]: https://github.com/marcotallone/parallel-quicksort-algorithms/network/members
[stars-shield]: https://img.shields.io/github/stars/marcotallone/parallel-quicksort-algorithms.svg?style=for-the-badge
[stars-url]: https://github.com/marcotallone/parallel-quicksort-algorithms/stargazers
[issues-shield]: https://img.shields.io/github/issues/marcotallone/parallel-quicksort-algorithms.svg?style=for-the-badge
[issues-url]: https://github.com/marcotallone/parallel-quicksort-algorithms/issues
[license-shield]: https://img.shields.io/github/license/marcotallone/parallel-quicksort-algorithms.svg?style=for-the-badge
[license-url]: https://github.com/marcotallone/parallel-quicksort-algorithms/blob/master/LICENSE

[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-blue?style=for-the-badge&logo=linkedin&logoColor=white&colorB=0077B5
[linkedin-url]: https://linkedin.com/in/marco-tallone-40312425b

[gmail-shield]: https://img.shields.io/badge/-Gmail-red?style=for-the-badge&logo=gmail&logoColor=white&colorB=red
[gmail-url]: mailto:[email protected]