Changes

Jump to: navigation, search

Team False Sharing

923 bytes added, 16:35, 16 December 2017
Identifying False Sharing
The frequent coordination required between processors when cache lines are marked ‘Invalid’ requires cache lines to be written to memory and subsequently loaded. False sharing increases this coordination and can significantly degrade application performance.
In Figure, threads 0 and 1 require variables that are adjacent in memory and reside on the same cache line. The cache line is loaded into the caches of CPU 0 and CPU 1. Even though the threads modify different variables, the cache line is invalidated forcing a memory update to maintain cache coherency.
#include <iostream>
#include <omp.h>
#include "timer.h"
#define NUM_THREADS 1
#define SIZE 1000000
<code>
#include <iostream>
#include <omp.h>
#include "timer.h"
#define NUM_THREADS 1
#define SIZE 1000000
 
int main(int argc, const char * argv[]) {
int* a = new int [SIZE];
int* b = new int [SIZE];
int sum = 0.0;
int threadsUsed;
Timer stopwatch;
for(int i = 0; i < SIZE; i++){//initialize arrays
a[i] = i;
b[i] = i;
}
omp_set_num_threads(NUM_THREADS);
stopwatch.start();
#pragma omp parallel for reduction(+:sum)
for(int i = 0; i < SIZE; i++){//calcultae sum of product of arrays
threadsUsed = omp_get_num_threads();
sum+= a[i] * b[i];
}
stopwatch.stop();
std::cout<<sum<<std::endl;
std::cout<<"Threads Used: "<<threadsUsed<<std::endl;
std::cout<<"Time: "<<stopwatch.currtime()<<std::endl;
 
return 0;
}
</code>
=Eliminating False Sharing=
96
edits

Navigation menu