UNIVERSITY OF WEST ATTICA
SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING AND INFORMATICS
University of West Attica · Department of Computer Engineering and Informatics
Operating Systems II
Vasileios Evangelos Athanasiou
Student ID: 19390005
Supervision
Supervisor: Vasileios Mamalis, Professor
Co-supervisor: Nikolaos Psarras, Applications Lecturer
Athens, June 2022
This repository contains an assignment for Operating Systems II, focusing on parallel computation using POSIX threads in C to efficiently calculate the inner product of two vectors.
| Section | Folder/File | Description |
|---|---|---|
| 1 | assign/ |
Assignment material for the Threads workshop |
| 1.1 | assign/ASK-2A-OS-II-LAB-2021-22.png |
Assignment description in English |
| 1.2 | assign/ΑΣΚ-2Α-ΛΣ-ΙΙ-ΕΡΓ-2021-22.png |
Assignment description in Greek |
| 2 | src/ |
Source code demonstrating thread usage |
| 2.1 | src/pthreads.c |
POSIX threads (pthreads) example implementation |
| 3 | README.md |
Project documentation |
| 4 | INSTALL.md |
Usage instructions |
The project implements a C program that calculates the inner product of two vectors using multiple threads.
The inner product is defined as:
A₁ × B₁ + A₂ × B₂ + ... + Aₙ × Bₙ
where Aᵢ and Bᵢ are elements of vectors A and B.
The computation is parallelized by dividing the workload among multiple threads.
- Compute the inner product using p parallel threads.
- Assign each thread a portion of the vector to compute.
- Combine partial sums into a shared global result.
- Protect shared data using mutex synchronization.
- Measure performance with different thread counts (1, 2, 4, and 8).
- Support vector input via user input or file loading.
-
Dynamic Thread Creation
Number of threads is determined at runtime. -
Local Computation
Each thread computes a local partial sum independently. -
Mutex Synchronization
Critical sections are protected to prevent race conditions. -
Random Vector Initialization
Allows performance testing with large datasets.
- Read vector size
nand thread countp. - Allocate memory for vectors A and B.
- Create threads to compute partial products.
- Synchronize updates to shared variable
total_sum. - Output the final inner product result.

