The first excercise of the course of Parallel Programming. The objective is to create a knnsearch function in c and optimize it using parallel programming.
The project is divided in 4 directories:
- cilk_pthreads This directory contains the implementation of both simple and parallel knnsearch using the OpenCilk and Pthreads libraries. Both a source file (.c) and a header file (.h) are included and needed. The source file contains the main function while the header one has all the other functions. To compile it manually (not recommended, a Makefile is provided, see details below) in a terminal, the following command should be used, with the necessary adjustments for your system: /yourPath/clang -I/usr/include/openblas -L/usr/lib/openblas -o cilk_pthreads cilk_pthreads.c -lopenblas -lm -fopencilk -O3
- omp_pthreads Similarly, this directory contains the implementation of both simple and parallel knnsearch using the OpenMP and Pthreads libraries. To compile it manually in a terminal, the following command should be used, with the necessary adjustments for your system: gcc -fopenmp -I/usr/include/openblas -L/usr/lib/openblas -o omp_pthreads omp_pthreads.c -lopenblas -lm
- test_files This directory was created mostly for testing and having a natural flaw when coding. It reveals the whole process of the project
- txtDataset This directory contains all the .txt files used, although for your convenience they have already been placed inside the directories.
This project contains a Makefile to compile two different versions of a program: one using OpenMP and the other using OpenCilk. The Makefile automates the process of compiling both versions, each with the appropriate flags and compilers.
Before running the Makefile, make sure you have the following installed:
-
GCC: For the OpenMP version.
-
OpenCilk: For the OpenCilk version of the program.
- You must have OpenCilk installed on your system, and you should be using the OpenCilk-enabled
clangcompiler (not the system defaultclang).
To install OpenCilk, follow the instructions on the OpenCilk GitHub page.
If you already have OpenCilk installed, make sure the
clangcompiler provided by OpenCilk is available in your systemPATHor directly referenced in theMakefile. - You must have OpenCilk installed on your system, and you should be using the OpenCilk-enabled
-
OpenBLAS: Make sure OpenBLAS is installed and the required headers and libraries are available:
- Headers:
/usr/include/openblas - Libraries:
/usr/lib/openblas
- Headers:
-
Clone the repository:
git clone https://github.com/NicKylis/Parallel-Programming.git cd Parallel-Programming -
Check that your
clangpoints to the OpenCilk version:Run the following to ensure the OpenCilk
clangis being used:which clang clang --version
If the output doesn't mention "OpenCilk," make sure to update your
PATHto include the OpenCilkclang:export PATH=~/opencilk/opencilk-YOUR_VERSION_HERE/bin:$PATH
To make this change permanent, add the
export PATH=...line to your~/.bashrc(or~/.zshrcif you're using Zsh) and run:source ~/.bashrc
-
Run the
Makefileto compile both versions of the program:make
This will compile two executables:
omp_programin theomp_pthreadsdirectory (compiled with OpenMP).cilk_programin thecilk_pthreadsdirectory (compiled with OpenCilk).
-
Clean up compiled files:
To remove the compiled executables, run:
make clean
This will delete both
omp_programandcilk_program.
- If you encounter an error like
unknown argument: '-fopencilk', it means you're using the wrong cilk compiler.
Nikolaos Kylintireas