Quantcast
Channel: Parallel Computing in C++ and Native Code forum
Viewing all articles
Browse latest Browse all 856

OpenMP thread number

$
0
0

Hi,

On a PC with Intel i7 that has 4 cores, windows 10 and vs 2017, I test the following code using OpenMP with the thread number being set as 3, however, in the task manager of windows 10, the thread number of the process is 6; besides, setting the thread number as 3 only obtains a speedup of 2.18. What's the reason for this phenomenon? 

On  intel i5 (without hyper-threading), windows 7, I did not see these problems.

#include<omp.h>
#include<iostream>
#include<fstream>
using namespace std;
void test()
{
int count = 0;
for (int i = 0; i<100000; i++)
{
count += i;
}
}

int main()
{
int iterationNum = 1000000;
fstream outfile("result.txt", ios::app);
double start, end;

omp_set_num_threads(3);
start = omp_get_wtime();
#pragma omp parallel for
for (int i = 0; i<iterationNum; i++)
{
//if (omp_get_thread_num() == 0)
//printf("run threads number is %d\n",omp_get_num_threads());
test();
}
end = omp_get_wtime();
outfile << "with omp optimization, time elapsed is " << end - start << endl;
outfile.close();
return 0;
}


Viewing all articles
Browse latest Browse all 856

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>