Skip to content

C program using POSIX threads (pthreads) to compute the inner product of two vectors in parallel, demonstrating multithreading, workload distribution, and mutex synchronization (Operating Systems II, UNIWA).

Notifications You must be signed in to change notification settings

Operating-Systems-2-aka-Uniwa/Threads

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

UNIWA

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

Parallel Inner Product Calculation using C POSIX Threads

Vasileios Evangelos Athanasiou
Student ID: 19390005

GitHub · LinkedIn


Supervision

Supervisor: Vasileios Mamalis, Professor

UNIWA Profile

Co-supervisor: Nikolaos Psarras, Applications Lecturer

UNIWA Profile · LinkedIn


Athens, June 2022



README

Parallel Inner Product Calculation using C POSIX Threads

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.


Table of Contents

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

1. Project Overview

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.


2. Objectives

  • 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.

3. Key Features

  • 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.


4. Program Structure

  1. Read vector size n and thread count p.
  2. Allocate memory for vectors A and B.
  3. Create threads to compute partial products.
  4. Synchronize updates to shared variable total_sum.
  5. Output the final inner product result.

About

C program using POSIX threads (pthreads) to compute the inner product of two vectors in parallel, demonstrating multithreading, workload distribution, and mutex synchronization (Operating Systems II, UNIWA).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages