-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest1.cpp
More file actions
36 lines (29 loc) · 884 Bytes
/
test1.cpp
File metadata and controls
36 lines (29 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <time.h>
#include <omp.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
double time1=0.0, tstart;
int nthreads, tid;
tstart = clock();
time1 += clock() - tstart;
time1 = time1/CLOCKS_PER_SEC;
printf("%lf\n",time1 );
#pragma omp parallel for
for (size_t i = 0; i < 1000; i++) {
printf("I'm thread %i of %d\n", omp_get_thread_num(), omp_get_num_threads());
}
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
} /* All threads join master thread and disband */
}