Shared state on local node


Although it goes against the principles in message passing, it might sometimes be useful to have a standardized way to share state between two (or more) workers on the same node.
Shared state should be avoided whenever possible, but in rare cases it is necessary due to performance issues. Consider the following naive example:
You have a list of 10,000,000 integers in which you want to find the largest value. You have 4 processing cores in your CPU so naturally you want to spawn 4 workers running through 1/4 of the list. Splitting the list into 4 equal parts and use the Send primitive to distribute them to the workers will take more time than iterating through the lists themselves since each message is serialized and deserialized to prevent shared state.
Instead it will be better to put the entire list in a shared repository and let each worker run through their assigned part of this list. In this example there are no updates to the list itself, so sharing it is not a problem.
Closed Jun 5, 2008 at 5:32 PM by fthomsen