openmp.c 483 B

123456789101112131415161718192021
  1. /* https://github.com/cirosantilli/linux-kernel-module-cheat#openmp */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <omp.h>
  5. int main (void) {
  6. int nthreads, tid;
  7. #pragma omp parallel private(nthreads, tid)
  8. {
  9. tid = omp_get_thread_num();
  10. printf("Hello World from thread = %d\n", tid);
  11. if (tid == 0) {
  12. nthreads = omp_get_num_threads();
  13. printf("Number of threads = %d\n", nthreads);
  14. }
  15. }
  16. return EXIT_SUCCESS;
  17. }