[erlang-questions] Distributing things

Calum caluml@REDACTED
Sat Nov 7 21:57:02 CET 2009


On Sat, Nov 7, 2009 at 8:13 PM, Joe Armstrong <erlang@REDACTED> wrote:
> Hang on - the algorithm just generates a random integer and tests if
> it is a prime,
> if it's not a prime it tries again. It has to generate many candidates
> before it finds a
> prime. Why not start N parallel processes each of which generates and
> tests candidates
> then when either one of them succeeds you can stop. Sounds easier to me.
>
> /Joe

Heya Joe (crikey I feel honoured!)

I thought it picked a random number, and then tested N-1 over and over
to see if it was prime.
I was trying to think how to coordinate the N value among all the
processes so that they wouldn't try the same ones.
I.e.:

Main program selects 1234567 as a random number, and knows it has 3
Erlang nodes it can work on
Node one tries 1234566
Node two tries 1234565
Node three tries 1234564
Then, when node one has found out that 1234566 isn't a prime
(unsurprisingly!), it would have to know where the other nodes were at
so it could know to check 1234563.

Although I suppose it doesn't really matter (for this program) if
they're all checking 123456* - but for some applications, they'd need
to be in sync.

The other thing I was wondering was what would happen if I fired up a
new node in the middle of this running - how would it join in? Are
there tried-and-tested software patterns to handle this sort of
dynamic loading?

C


More information about the erlang-questions mailing list