couldn't see the result while running omp

Viewed 49

This is my code

#include "/usr/local/opt/libomp/include/omp.h"

int main(){
   int x = 0;
   #pragma omp parallel num_threads(100)
   {
      int id = omp_get_thread_num();
      if(id < 50){  //first 50 threads increment x
         # pragma omp critical 
         x++; 
      }else {    //other 50 threads decrement x
         # pragma omp atomic
         x--; 
      }
   }
   printf("%d", x);
}

When I run gcc-12 -fopenmp test.c on terminal, there is no results, it doesn't print x out.

0 Answers
Related