Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#pragma omp parallel num_threads is not working

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

    void main(int argc, int *argv[]){


   #pragma omp parallel num_threads(3)
   {

    int tid = omp_get_thread_num();
    printf("Hello world from thread = %d \n",tid);
    if(tid == 0){
        int nthreads = omp_get_num_threads();
        printf("Number of threads = %d\n",nthreads);
    }
   }

  }

I am learning OpenMP and I don't understand why it executes only one thread when I have specified the number of threads 3? The program ouptut:

   Hello world from thread = 0
   Number of threads = 1
like image 597
Jona Avatar asked Jun 25 '14 19:06

Jona


1 Answers

You need to compile your program with -fopenmp.

g++ a.cc -fopenmp
like image 79
cheerss Avatar answered Oct 08 '22 20:10

cheerss