Parallel
#include <omp.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int nthreads=4;
omp_set_num_threads(nthreads);
int i;
/* Fork a team of threads with each thread having a private tid variable */
#pragma omp parallel for
for (i=0; i<nthreads; i++) {
/* Obtain and print thread id */
int tid = omp_get_thread_num();
printf("i = %d, Hello World from thread = %d\n", i, tid);
} /* All threads join master thread and terminate */
}Last updated