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 multi-computer. 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 Assign7 and would like a copy to work from, send me an email.,
Use a RING topology with 26 processors, numbered 0 to 25.
Use the Assign7 technique to get processor names (this code is in the template.)
Follow the C* conventions for multi-computers.
No global data except the 26 element stream (connection) array and data managed by main().
Start processes on processors 1 through 25 using RPC. Use a 26 element character array (ldr_rtn[26] 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 0's name when calling it.
After all processors finish, main() should compare ldr_rtn[0] with elements 1 through 26, 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 0 name is J
leader is Z
complete
------below is the given code template-------
#include
#define PCS 26
#define OFFSET 'A'
boolean track[PCS]={false};
char ldr_rtn[PCS];
/*
* generate and return a random, unique, 1-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 unique_name()
{
int id, ct;
id = rand()% PCS;
ct =0;
while (ct < PCS)
{
if (!track[id])
{
track[id]= true;
return id + OFFSET;
}
id =(id +1)% PCS;
ct +=1;
}
return '\0'; /* error return when called more than PCS times */
}
/*
* a process for a multi-computer with a unique name connected in a ring by
* channel[self] and a passed left channel subscript, and a variable parameter return location
*/
void process()
{
}
int main()
{
int ix;
char nm;
for (ix =1; ix < PCS; ++ix)
{
/* establish the ring with PCS-1 processes */
/*
cout << nm <<" started" << endl;
*/
}
nm = unique_name();
cout << "process 0 name is "<< nm << endl;
/* hook process 0 into the ring */
/* wait until all processes terminate after electing a leader */
cout << "leader is "<< ldr_rtn[0]<< endl; /* write the result of the election */
for (ix =1; ix < PCS; ++ix)
{
if (ldr_rtn[ix]!= ldr_rtn[0])
cout << "processor "<< ix <<" leader "<< ldr_rtn[ix]<< endl;
}
cout << "complete" << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!