Not all computations are simple, competing threads

All threads are potentially accessing and changing the same values, maxloc and maxval.

  1. OpenMP provides several ways to coordinate access to shared values
#pragma omp atomic
  1. Only one thread at a time can execute the following statement (not block). We can use the critical option
#pragma omp critical
  1. Only one thread at a time can execute the following block

Atomic may be faster than critical but depends on hardware