openMP:pourquoi ne suis-je pas obtenir différents id de thread lorsque j'utilise “ #pragma omp parallel num_threads(4)”

Pourquoi je n'obtiens pas les différents id de thread lorsque j'utilise " #pragma omp parallel num_threads(4)". Tous les id de thread sont 0 dans ce cas.
Mais quand je commente la ligne et de l'utilisation nombre de threads par défaut, j'ai eu différents id de thread.
Remarque: variable - j'ai utilisé la variable tid pour obtenir l'id de thread.

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char *argv[]) 
{
int nthreads, tid;
int x = 0;

#pragma omp parallel num_threads(4)
#pragma omp parallel private(nthreads, tid)
  {
  /* Obtain thread number */
 tid = omp_get_thread_num();
  printf("Hello World from thread = %d\n", tid);

  ///* Only master thread does this */
   if (tid == 0) 
     {
     nthreads = omp_get_num_threads();
     printf("Number of threads = %d\n", nthreads);
     }

  }


}

De sortie de code ci-dessus:-

Hello World from thread = 0
Hello World from thread = 0
Number of threads = 1
Hello World from thread = 0
Number of threads = 1
Hello World from thread = 0
Number of threads = 1
Number of threads = 1

De sortie quand je commente la ligne mentionnée ci-dessus: -

Hello World from thread = 3
Hello World from thread = 0
Number of threads = 4
Hello World from thread = 1
Hello World from thread = 2
Remarque :- pour la compilation je n'ai gcc-fopenmp ouvrir.c -o bonjour

OriginalL'auteur jayesh hathila | 2012-11-03