Open main menu

CDOT Wiki β

Changes

Team False Sharing

286 bytes removed, 15:39, 17 December 2017
Identifying False Sharing
#include "timer.h"
#define NUM_THREADS 8
#define SIZE 1000000
 
int main(int argc, const char * argv[]) {
int* a = new int [SIZE]; int* b = new int [SIZE]; int* sum_local = new int[NUM_THREADS]; int sum = 0.0; int threadsUsed; Timer stopwatch; for(int i = 0; i < SIZE; i++)struct s{//initialize arrays a[i] = 1float value; b }Array[i4] = 1; }
int numThreadsUsed;
const int SomeBigNumber = 100000000;
omp_set_num_threads(NUM_THREADS);
stopwatch.start();#pragma omp parallel{ int threadNum double start_time = omp_get_thread_numomp_get_wtime(); sum_local[threadNum]=0;#pragma omp parallel for for(int i = 0; i < SIZE4; i++){//calcultae sum of product of arrays if(i==0){threadsUsed numThreadsUsed = omp_get_num_threads();} sum_local[threadNum] for(int j = 0;j < SomeBigNumber;j++= a){ Array[i] * b.value = Array[i].value + (float)rand(); }
}
#pragma omp atomic double time = omp_get_wtime() - start_time; std::cout<<time<<std::endl; sum += sum_local[threadNum]std::cout<<"Threads Used: "<<numThreadsUsed<<std::endl; return 0;
}
stopwatch.stop();
std::cout<<sum<<std::endl;
std::cout<<"Threads Used: "<<threadsUsed<<std::endl;
std::cout<<"Time: "<<stopwatch.currtime()<<std::endl;
return 0;
}
</source>
[[File:ExecVsThreadsFalse.png]]
96
edits