please tell me why the results of the two codes are identical? I don't know why no add #pragma omp critical ,no data race too,in code1.
It's obvious you'vea potential data race => you've a percentile of chance to have one it's for that it's so difficult to detect and reproduce => that's the heart of parallelism
Statistically,it depends on size (in cache line) of potential data racable,number of caches and cores, cash coherency policy (inclusive,exclusive), and time needed to read/write from cache => not easy to calculate (I could perhapsif you pay me :=) :=) )
But if you want to increase the chances to "SEE" a cache race, I propose:
- increase hardware configuration (more cores and caches involved) - diminish the size of your array to few elements - randomize your data in array