Question: assignment 5 _ template.cpp: / / C + + code #include #include #include #include #include #include using namespace std; #define n 1 0 0 int
assignmenttemplate.cpp:
C code
#include
#include
#include
#include
#include
#include
using namespace std;
#define n
int An;
auto printall int p
cout endl;
for int i ; i p; i
for int j ; j n p; j
cout std::setw Ai n p j;
cout endl;
cout endl;
;
int main
srandtimeNULL;
for int i ; i n; i
Ai i; rand;
int p ; Assuming that p indicates # of processors
double k n doublep;
printallp;
Stage : each Processor i computes a local prefix sum
of a subarray of size np logn k
for int i ; i p; i
for int j ; j k; j
int sourcePos i k j ;
int destPos i k j;
AdestPos AsourcePos;
printallp;
Stage : Prefix summation using only the rightmost value
of each subarray Olognk
int i ;
for int j pow i; j p; j
int destPos j k ;
int sourcePos j pow i k ;
if destPos && sourcePos
AdestPos AsourcePos;
printallp;
Stage : each Proc i adds the value computed in Step by Proc i to
each subarray element except for the last one
for int i ; i p; i
int sourcePos i k ;
for int j ; j k ; j
int destPos i k j;
AdestPos AsourcePos;
printallp;
return ;
PLEASE PROVIDE CODE. ONE NONTHREAD CODE. AND ONE THREADED CODE. FOR THREADED CODE, PLEASE USE THREAD. THANKS
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
