Question: ParallelsumDC.c #include #include #include #include int main ( int argc, char * argv [ ] ) { MPI _ Init ( &argc, &argv ) ;
ParallelsumDC.c
#include
#include
#include
#include
int mainint argc, char argv
MPIInit&argc, &argv;
int rank, size;
MPICommrankMPICOMMWORLD, &rank;
MPICommsizeMPICOMMWORLD, &size;
int n ; total numbers
std::vector datan;
ifrank
forint i ; i n; i
datai i ;
int logSize logsize;
forint i logSize ; i ; i
ifrank & intpow i
ifrank & intpow i
printfProcessor d sends sublist to processor d at level d
rank, rank intpow i i;
MPISend&datan n MPIINT, rank intpow i MPICOMMWORLD;
n ;
else
printfProcessor d receives sublist from processor d at level d
rank, rank intpow i i;
MPIRecv&data n MPIINT, rank intpow i MPICOMMWORLD, MPISTATUSIGNORE;
int sum ;
forint i ; i n; i
sum datai;
printfThe partial sum on processor d is d
rank, sum;
ifrank
printfProcessor d sends sublist to processor at level
rank;
MPISend&sum, MPIINT, MPICOMMWORLD;
else
int temp;
forint i ; i size; i
MPIRecv&temp, MPIINT, i MPICOMMWORLD, MPISTATUSIGNORE;
printfProcessor receives sublist from processor d at level
i;
sum temp;
printfThe final sum is d
sum;
MPIFinalize;
return ;
Probelm Statement :
Find the Parallel Sum Using Divide and Conquer
Assume there are processing nodes and there are numbers to be added. The original list is initialized at processor and then is divided into two halves to broadcast level by level until the leaves are reached as shown below each processor will have numbers After each processor receives its final sublist numbers it calculates its partial sum. The partial sums will be reduced level by level as shown below. The final sum will be obtained and printed out on processor
Expected
Processor sends sublist to processor at level
Processor sends sublist to processor at level
Processor sends sublist to processor at level
The partial sum on processor is
Processor receives sublist from processor at level
The partial sum on processor is
Processor sends sublist to processor at level
Processor receives sublist from processor at level
Processor sends sublist to processor at level
The partial sum on processor is
Processor receives sublist from processor at level
Processor sends sublist to processor at level
Processor sends sublist to processor at level
The partial sum on processor is
Processor receives sublist from processor at level
Processor sends sublist to processor at level
The partial sum on processor is
Processor receives sublist from processor at level
Processor receives sublist from processor at level
Processor receives sublist from processor at level
The partial sum on processor is
Processor sends sublist to processor at level
Processor receives sublist from processor at level
Processor sends sublist to processor at level
Processor receives sublist from processor at level
Processor sends sublist to processor at level
Processor receives sublist from processor at level
The partial sum on processor is
Processor sends sublist to processor at level
Processor receives sublist from processor at level
The partial sum on processor is
Processor sends sublist to processor at level
Processor receives sublist from processor at level
Processor sends sublist to processor at level
Processor receives sublist from processor at level
Processor receives sublist from processor at level
The final sum is
Correction:
This is my code i have worked on there are some mistakes in distributing and reducing steps i guess i am unable to figure it out correct the code to solve the below problem. the out put should look the same
Output I got:
The partial sum on processor is
Processor sends sublist to processor at level
Processor receives sublist from processor at level
Processor sends sublist to processor at level
The partial sum on processor is
Processor sends sublist to processor at level
Processor sends sublist to processor at level
Processor sends sublist to processor at level
The partial sum on processor is
Processor receives sublist from processor at level
Processor receives sublist
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
