Код: Выделить всё
const char* pcData = pkt.data().c_str(); // big string
int numChannels = 128;
int numThreads = 1;
std::vector rowGlobalIds(numChannels, std::vector());
for(auto& v: indices){
v.reserve(3000);
}
#pragma omp parallel num_threads(numThreads)
{
omp_set_nested(1);
double wtime = omp_get_wtime();
int thread_num = omp_get_thread_num();
int localItNumber = 0;
int localValidNumber = 0;
// Create local vector, to be merged below
std::vector thIds(numChannels, std::vector());
for(auto& v: indices){
v.reserve(1500);
}
#pragma omp for nowait schedule(static)
for(int i=0; i < pointCount; ++i){
int16_t val1 = copyFromBuffer(pcData, i, 1);
if(val1 > threshold){
uint16_t val2 = copyFromBuffer(pcData, i, 2);
thIds[val2].push_back(i);
localValidNumber++;
}
localItNumber++;
}
wtime = omp_get_wtime() - wtime;
printf( "Time taken by thread %d is %f ms with %d iterations and %d valid points\n", thread_num, wtime*1000, itcounts[thread_num], validPoints[thread_num] );
// Merging local vectors of vectors. This must be in order th 0 then 1
#pragma omp for schedule(static) ordered
for(int th = 0; th < omp_get_num_threads(); ++th) {
for(int i = 0; i < numChannels; ++i){
#pragma omp ordered
rowGlobalIds.insert(indices[i].end(), thIds[i].begin(), thIds[i].end());
}
}
omp_set_nested(0);
}
Для numThreads = 1:
--> Тема 0:
Итерации 634 060
Действительные баллы 214 742
Время выполнения 33,936843 мс
Для numThreads = 2:
-->Поток 0:
Итераций 317 644
Действительные баллы 112 428
Время выполнения 34,031533 мс
-->Поток 1:
Итерации 317 644
Действительные баллы 102 304
Время выполнения 26,162064 мс
Почему время в итоге почти одинаковое, если в принципе, половину времени читают из буфера?
Я не пробовал ничего, кроме измерения производительности с помощью приведенного выше кода
Подробнее здесь: https://stackoverflow.com/questions/785 ... nt-speedup
Мобильная версия