### Lab 6: Erlang Concurrency

Due Friday, December 3rd at 11:59pm.

Work in groups of 2 or 3.

#### Problem 1

Write an Erlang distributed program for factoring an integer number.
More specifically, given a number N, you need to check all possible
divisors of N between 2 and sqrt(N).

The process starts with a control thread that spawns processes to
check separate ranges for possible factors: each process gets a range
of numbers to check (i.e. it gets sent N, the minimum, and the
maximum of the range). The control processes then is prepared to receive
a message from the other processes. It keeps the list of PIDs of the
processes (or just the number of processes).

If a process discovers a factor, it sends that information back to the
control process. Otherwise it sends an atom indicating that there are
no factors of N in the range.

The control process outputs the factors if they are found or waits
until all the processes finish without finding a factor, in which case
it outputs that the nubmer is prime.

Use Prime numbers
archive to generate test data. Use at least one large prime
number and at least one product of two large primes (7-8 digit
values of N will do for starters). Check how the program performs
for different range sizes.

#### Problem 2

Write a program that does the following:

- The strating process spawns N processes. Each process gets a
process id of the previous process and a random number.
- The processes communicate to each other trying to determine the
largest of the random numbers.
- After R rounds of message passing the processes output what they
discovered as the largest number. Not all of them may have
detected the largest number; that's OK.
- You might want to experiment with N and R and see how accuracy
improves with more messages.

UMM CSci 4409

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.