akaros/tests/openmp/old/omp_hello.c
<<
>>
Prefs
   1#include <sys/sysinfo.h>
   2#include <omp.h>
   3#include <stdio.h>
   4#include <stdlib.h>
   5#include <parlib/vcore.h>
   6
   7int main (int argc, char *argv[]) 
   8{
   9  int nthreads, tid;
  10  printf("get_nprocs: %d\n", get_nprocs());
  11  printf("SC_NPROCESSORS_ONLN: %d\n", sysconf (_SC_NPROCESSORS_ONLN));
  12  printf("max num vcores: %d\n", max_vcores());
  13
  14/* Fork a team of threads giving them their own copies of variables */
  15#pragma omp parallel private(nthreads, tid)
  16  {
  17
  18  /* Obtain thread number */
  19  tid = omp_get_thread_num();
  20  printf("Hello World from thread = %d\n", tid);
  21
  22  /* Only master thread does this */
  23  if (tid == 0) 
  24    {
  25    nthreads = omp_get_num_threads();
  26    printf("Number of threads = %d\n", nthreads);
  27    }
  28
  29  }  /* All threads join master thread and disband */
  30
  31}
  32