Question: Convert the Leader Election algorithm of the code given below from a multiprocessor to a multi - computer. Instead of writing a message from each
Convert the Leader Election algorithm of the code given below from a multiprocessor to a multicomputer. Instead of writing a message from each process when it determines the leader, have the process return the leader's name through an RPC variable parameter. See the attached template code. If you had trouble with Assign and would like a copy to work from, send me an email.,
Use a RING topology with processors, numbered to
Use the Assign technique to get processor names this code is in the template.
Follow the C conventions for multicomputers.
No global data except the element stream connection array and data managed by main
Start processes on processors through using RPC Use a element character array ldrrtn in the template managed by main to provide a return location for each processor to return its leader determination.
Use a designated reader for each processor, reading the stream whose subscript is equal to the processor number self This is the "right" stream. Pass the subscript of the "left" stream to each process when starting.
After main performs all initialization, it should become the last processor in the ring by calling not starting the same function that it started on every other processor. Display process s name when calling it
After all processors finish, main should compare ldrrtn with elements through and display the subscript and value of any that are not equal. If your program is correct, there will be no not equal displays. This code is in the template.
The program output should look like:
process name is J
leader is Z
complete
below is the given code template
#include
#define PCS
#define OFFSET A
boolean trackPCSfalse;
char ldrrtnPCS;
generate and return a random, unique, character name. Track names generated in the boolean track array.
A name is A plus a random offset mod the number of names. The names are comparable, and the
obvious ones are min name and max name.
char uniquename
int id ct;
id rand PCS;
ct ;
while ct PCS
if trackid
trackid true;
return id OFFSET;
id id PCS;
ct ;
return ; error return when called more than PCS times
a process for a multicomputer with a unique name connected in a ring by
channelself and a passed left channel subscript, and a variable parameter return location
void process
int main
int ix;
char nm;
for ix ; ix PCS; ix
establish the ring with PCS processes
cout nm started" endl;
nm uniquename;
cout "process name is nm endl;
hook process into the ring
wait until all processes terminate after electing a leader
cout "leader is ldrrtn endl; write the result of the election
for ix ; ix PCS; ix
if ldrrtnix ldrrtn
cout "processor ix leader ldrrtnix endl;
cout "complete" endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
