achilleaspappas / Parallel-Systems

OpenMP and CUDA

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parallel Systems

The purpose of this project is to implement parallel algorithms using OpenMP and CUDA. The source code files address different exercise problems. This project was part of a course I did in my 9th semester.

Prerequisites

To use the files in this repository, you will need the following:

Getting Started

To get started with this project, follow these steps:

  1. Clone this repository to your local machine.

  2. Compile the source code file using the appropriate compiler and compile flags.

    For openMP:

    gcc file.c -o file -fopenmp
    

    For CUDA:

    nvcc file.cu -o file
    
  3. Run the executable file generated by the compilation process.

    ./file
    

Contents

This repository contains the following files:

  1. Source_Code_1.c
  2. Source_Code_2A.c
  3. Source_Code_2B_1.c
  4. Source_Code_2B_2.c
  5. Source_Code_2B_3.c

Specifications

Functionality

Source_Code_1.c

A matrix A(NxN) is called "strictly dominating diagonal" if for each row of 'i' it is true that:

|𝛒𝑖𝑖| > βˆ‘ |𝐴𝑖𝑗| where j=0…N-1 i<>j
  • Check (in parallel) whether the matrix A is strictly diagonally dominated.
  • If this is the case, calculate in parallel (use OpenMP's reduction clause appropriately at this point) the maximum (m) in absolute value element of the diagonal of
Ξ‘ (m = max(|𝛒𝑖𝑖|), i=0…N-1)
  • Then based on this (m) make (in parallel) a new table B(ΓΏxN) (which it will print at the end on the screen) where:
𝐡𝑖𝑗 = m – |𝐴𝑖𝑗| Ξ³ΞΉΞ± i<>j ΞΊΞ±ΞΉ 𝐡𝑖𝑗 = m Ξ³ΞΉΞ± i=j
  • For the above table B , it is also requested to calculate in parallel (and print on the screen) its minimum value element using the reduction clause.

Source_Code_2A.c

Write a program in OpenMP that sorts a sequence of N integers A[0…N-1] in parallel, according to the recursive sorting algorithm 'multisort'.

Source_Code_2B_1.c

Write a program in CUDA to calculate the 2-D convolution. Specifically, given a 2-D register A, to calculate its new value at position (i,j) both the current value of that specific position and the values of all its neighboring elements (9 values in total) are used, each of which is multiplied by a "weight". The calculation is shown in the figure below. For the new register A' that will result from the calculations, it is also requested to find the minimum value (min) of the elements of its diagonal.

A’(i, j) = c11 βˆ™ A(i - 1, j - 1) + c12 βˆ™ A(i, j - 1) + c13 βˆ™ A(i + 1, j - 1) +
c21 βˆ™ A(i - 1, j) + c22 βˆ™ A(i, j) + c23 βˆ™ A(i + 1, j) +
c31 βˆ™ A(i - 1, j + 1) + c32 βˆ™ A(i, j + 1) + c33 βˆ™ A(i + 1, j + 1)

Source_Code_2B_2.c

Write a program in CUDA that, given a 2-D register A of dimensions NxM and a vector x of size M, is asked to compute the expression

A^T * A * x 

that is the product of the inverse of the register times the original register times the vector x. For limiting the number of transactions and the intermediate storage space that required for the calculation, the A βˆ™ x calculation is performed first.

Source_Code_2B_3.c

Write a CUDA program that, given a 2-D matrix A, calculates the covariance matrix of A as follows:

  • For each column of register A calculates the average of the elements of the column.
  • From each element of a column of register A subtracts the average of the corresponding column calculated in the previous step.
  • Multiplies the A register of the previous step by the inverse of this register. Because the resulting register is symmetric, it is sufficient to calculate either the upper or lower triangular part of the result.

Contributing

This is a university project so you can not contribute.

Authors

  • [University of West Attica] - Provided the exersice
  • [Achilleas Pappas] - Wrote the code

License

This project is licensed by University of West Attica as is a part of a university course. Do not redistribute.

Acknowledgments

Thank you to University of West Attica and my professors for providing the resources and knowledge to complete this project.

About

OpenMP and CUDA


Languages

Language:C 100.0%