Question: Modify the problem so that aggregation is performed on the integer values sent to the Aggregate ( ) function, and the float average of the

Modify the problem so that aggregation is performed on the integer values sent to the Aggregate() function, and the float average of the values (the aggregation) broadcast back to the processes.
Use the attached C* template. Pay close attention to the comments in the template.
The output should be approximately:
finished 3 loops
SEQUENTIAL EXECUTION TIME: 4715
PARALLEL EXECUTION TIME: 2663
SPEEDUP: 1.77
NUMBER OF PROCESSORS USED: 12
-----below is the template--------
/* Assign6*/
/* Compute, Aggregate, and Broadcast using streams */
#define LOOPS 3
#define PROCESSES 10
typedef struct {
int addr;
int valu;
float aggr;
} aggmsg_t;
float verify[LOOPS]={5.5,15.5,25.5};
/*
* define a stream array of the correct type and size named 'aga'
*/
/*
* Aggregate receives a process count parameter. Aggregate must initially block on a receive,
* waiting for its input. It counts its input, and performs steps needed for aggregation.
* When it has received all messages, it completes the aggregation and broadcasts the result.
* It leaves itself in a state so that it can be reused, until receiving an endmarker message,
* one with an addr field of 0.
*/
void Aggregate(int prct)
{
}
/*
* process() tests the Aggregation() function.
*/
void process(int i, int j)
{
aggmsg_t pmsg;
pmsg.addr = i;
pmsg.valu = j * PROCESSES + i;
pmsg.aggr =0.0;
send(aga[0], pmsg);
recv(aga[i], pmsg);
if (pmsg.aggr != verify[j])
cout << "process "<< myid <<" aggr "<< pmsg.aggr <<" not equal to expect value "<< verify[j]<< endl;
}
/*
* initialization for Aggregate if needed
*/
void initAgg()
{
return;
}
int main()
{
int i, j;
aggmsg_t emsg;
/*
* initialization code
*/
for (j =0; j < LOOPS; ++j)
{
forall i =1 to PROCESSES do
process(i, j);
}
/*
* termination code
*/
cout << "finished "<< j <<" loops" << 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!