Open main menu

CDOT Wiki β

Changes

Team False Sharing

802 bytes added, 15:47, 17 December 2017
Padding
===Padding===
<source lang ="cpp">
#include <iostream>
#include <omp.h>
#include "timer.h"
#define NUMPAD 7
#define NUM_THREADS 8
int main(int argc, const char * argv[]) {
struct s{
float value;
int pad[NUMPAD];
}Array[4];
Timer stopwatch;
int numThreadsUsed;
const int SomeBigNumber = 100000000;
omp_set_num_threads(NUM_THREADS);
double start_time = omp_get_wtime();
#pragma omp parallel for
for(int i = 0; i < 4;i++){
if(i ==0){numThreadsUsed = omp_get_num_threads();}
for(int j = 0;j < SomeBigNumber;j++){
Array[i].value = Array[i].value + (float)rand();
}
}
double time = omp_get_wtime() - start_time;
std::cout<<time<<std::endl;
std::cout<<"Threads Used: "<<numThreadsUsed<<std::endl;
return 0;
}
</source>
96
edits