Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions