Add OpenMP libraries and pragmas.
Add critical section around addition.
We're changing a shared value, so it needs to be accessed separately.
Add p to the shared variable list.
p doesn't change during the loop, so it can be shared without any problem.