none
OpenMP thread number RRS feed

  • Question

  • 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;
    }

    Monday, May 28, 2018 1:30 PM