I have an assignment and the following was mentioned:
Parallelism adds further complications, as the random number generator function must behave correctly when two or more threads call it simultaneously, i.e., it must be thread-safe.
However, I can't understand why that is a problem in the first place. Random generators are usually called with a seed as a parameter and output a number by doing multiple operations on it, I understand that we need each thread to use a different seed but other than that where does the problem come from? I have realized that spawning and calling the random generator in a parallel region instead of a serial one also really worsens performance but I can't understand why this would happen as by the looks of it, the random number generator should be parallelizable with no problems since they are no dependencies.
Any help in understand the theory behind this would be appreciated.
Aucun commentaire:
Enregistrer un commentaire