openMP is not creating threads in visual studio

后端 未结 4 1934
旧时难觅i
旧时难觅i 2020-12-06 16:26

My openMP version did not give any speed boost. I have a dual core machine and the CPU usage is always 50%. So I tried the sample program given in Wiki. Looks like the openM

4条回答
  •  半阙折子戏
    2020-12-06 17:11

    Why would you need more than one thread for that program? It's clearly the case that OpenMP realizes that it doesn't need to create an extra thread to run a program with no loops, no code that could run in parallel whatsoever.

    Try running some parallel stuff with OpenMP. Something like this:

    #include 
    #include 
    #include 
    #define CHUNKSIZE   10
    #define N       100
    
    int main (int argc, char *argv[]) 
    {
    int nthreads, tid, i, chunk;
    float a[N], b[N], c[N];
    
    /* Some initializations */
    for (i=0; i < N; i++)
      a[i] = b[i] = i * 1.0;
    chunk = CHUNKSIZE;
    
    #pragma omp parallel shared(a,b,c,nthreads,chunk) private(i,tid)
      {
      tid = omp_get_thread_num();
      if (tid == 0)
        {
        nthreads = omp_get_num_threads();
        printf("Number of threads = %d\n", nthreads);
        }
      printf("Thread %d starting...\n",tid);
    
      #pragma omp for schedule(dynamic,chunk)
      for (i=0; i

    If you want some hard core stuff, try running one of these.

提交回复
热议问题