Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "omp.h"
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include "stdio.h"
#define SIZE 10
/**
* Critical sections are OpenMP constructs we use to prevent multiple threads from accessing
* the critical section's code at the same time. In simpler words, a critical section specifies
* code which is to be executed by only one thread at a time.
*/
/**
* @brief A function that generates a random array of SIZE 10 and returns the biggest number in that array
* @note Makes use of OpenMP
*/
int main()
{
int i, max, a[SIZE];
for(i=0; i<SIZE; i++)
{
a[i] = rand();
std::cout<<a[i]<<std::endl;
}
max = a[0];
/**
* @TODO: Find the biggest number in the array 'a' by utilising OpenMP
* @note Use 2 directives
* -> the first should assign 4 threads to run at the same time
* -> the second one should use the OMP critical statement (applicable only when avoiding Race Conditions)
*/
std::cout<<"Max ="<<max<<std::endl;
return 0;
}