xref: /petsc/src/sys/tests/ex69.c (revision 9f0612e409f6220a780be6348417bea34ef34962)
1*9f0612e4SBarry Smith #include <omp.h>
2*9f0612e4SBarry Smith #include <petscsys.h>
3*9f0612e4SBarry Smith 
4*9f0612e4SBarry Smith /*
5*9f0612e4SBarry Smith    See the comments in ex69f.F90
6*9f0612e4SBarry Smith */
7*9f0612e4SBarry Smith int main(int argc, char **args)
8*9f0612e4SBarry Smith {
9*9f0612e4SBarry Smith   double wtime_start, wtime_end, mpiwtime_start, mpiwtime_end;
10*9f0612e4SBarry Smith   double x[100];
11*9f0612e4SBarry Smith   int    i, maxthreads;
12*9f0612e4SBarry Smith 
13*9f0612e4SBarry Smith   PetscCall(PetscInitialize(&argc, &args, NULL, NULL));
14*9f0612e4SBarry Smith   wtime_start    = omp_get_wtime();
15*9f0612e4SBarry Smith   mpiwtime_start = MPI_Wtime();
16*9f0612e4SBarry Smith #pragma omp parallel for schedule(static)
17*9f0612e4SBarry Smith   for (i = 0; i < 100; i++) { x[i] = exp(3.0 * i); }
18*9f0612e4SBarry Smith   wtime_end    = omp_get_wtime();
19*9f0612e4SBarry Smith   mpiwtime_end = MPI_Wtime();
20*9f0612e4SBarry Smith   printf("Wall clock time from MPI_Wtime()     %g\n", wtime_end - wtime_start);
21*9f0612e4SBarry Smith   printf("Wall clock time from omp_get_wtime() %g\n", mpiwtime_end - mpiwtime_start);
22*9f0612e4SBarry Smith   printf("Value of x(22) %g\n", x[22]);
23*9f0612e4SBarry Smith   maxthreads = omp_get_max_threads();
24*9f0612e4SBarry Smith   printf("Number of threads set %d\n", maxthreads);
25*9f0612e4SBarry Smith   PetscCall(PetscFinalize());
26*9f0612e4SBarry Smith   return 0;
27*9f0612e4SBarry Smith }
28*9f0612e4SBarry Smith 
29*9f0612e4SBarry Smith /*TEST
30*9f0612e4SBarry Smith 
31*9f0612e4SBarry Smith    build:
32*9f0612e4SBarry Smith      requires: openmp
33*9f0612e4SBarry Smith 
34*9f0612e4SBarry Smith    test:
35*9f0612e4SBarry Smith      filter: grep -v "Number of threads"
36*9f0612e4SBarry Smith 
37*9f0612e4SBarry Smith TEST*/
38