Open main menu

CDOT Wiki β

Changes

DPS921/Intel Parallel Studio Inspector

959 bytes added, 18:31, 29 November 2020
Code for Intel Inspector
}
return counter.getCounter();
}
</syntaxhighlight>
 
 
 
== OMP Race Conditions ==
 
<syntaxhighlight lang="cpp" line='line'>
 
#include <iostream>
#include <iomanip>
#include <omp.h>
 
 
// Race Condition
int main() {
int numThreads = 6;
int numSteps = 1000000;
omp_set_num_threads(numThreads);
double* sum = new double[numThreads];
double pi, totalSum = 0.0;
const double stepSize = 1.0 / numSteps;
 
// Creates The Race Condition, Place within the OMP Parallel to undo race condition
double temp = 0.0;
#pragma omp parallel
{
int ID = omp_get_thread_num();
int incriment = ID;
double x;
for (int i = ID; i < numSteps; i = i + numThreads) {
x = ((double)i + 0.5) * stepSize;
temp += 1.0 / (1.0 + x * x);
}
 
sum[ID] = temp;
}
 
for (int i = 0; i < numThreads; i++)
{
totalSum = totalSum + sum[i];
}
 
pi = (4.0) * totalSum * stepSize;
delete[] sum;
 
std::cout << "Expexted Number : 3.14___" << std::endl;
std::cout << "REceived Number : " << pi << std::endl;
 
}
</syntaxhighlight>
150
edits