Question

Problem 5 (Dot product for multicore machines - 15 points): Complete the SPMD (single pro- gram multiple data) program below

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here i am providing the answer. Hope it helps. please give me a like. it helps me a lot.

Answer:

MPI_Scatter(src_lst,m,MPI_INT,dst_lst,m,MPI_INT,MASTER,world);

MPI_Gather(src_buf,number,MPI_INT,dst_buf,number,MPI_INT,MASTER,world);

int main(int argc, char *argv[])

{

int i,n,nprocs,pid,size,prod=0;

int vector_x[NELMS],vector_y[NELMS],partial_prods[MAXPROCS];

MPI_Status status;

MPI_Comm world;

n = atoi(argv[1]); /* number of elements */

MPI_Init(&argc, &argv);

world = MPI_COMM_WORLD;

MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

MPI_Comm_rank(MPI_COMM_WORLD, &pid);

size=n/nprocs;

MPI_Scatter(vector_x,size,MPI_INT,partial_prods,m,MPI_INT,MASTER,world);

MPI_Scatter(vector_y,size,MPI_INT,partial_prods,m,MPI_INT,MASTER,world);

prod=dot_product(1,NELMS,vector_x,vector_y);

MPI_Gather(&prod,1,MPI_INT,partial_prods,1,MPI_INT,MASTER,world);

printf("\n DotProduct value is %d",prod);

MPI_Finalize();

}

int dot_product(int s,int e,int *x,int *y)

{

int i,prod=0;

for (i=s;i<=e;i++)

prod=prod+s[i]*y[i];

return prod;

}

Thank you. please upvote.

Add a comment
Know the answer?
Add Answer to:
Problem 5 (Dot product for multicore machines - 15 points): Complete the SPMD (single pro- gram...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using matlab to solve this problem as soon as possible thanks use matlab to slove the...

    using matlab to solve this problem as soon as possible thanks use matlab to slove the problem as soon as possible solve the activity of number 1&2&3 by using matlab for this problem i need from you to solve activity one and two and three by using matlab DIRECTIONS: Perform the following using MATLAB. After the simulation, your report must be uploaded in the Moodle Learning system. ACTIVITY I. VECTORS AND ITS OPERATIONS Procedure 1: Define two vectors a and...

  • The last 3 cases are tests .cpp files to test the code. The language of this...

    The last 3 cases are tests .cpp files to test the code. The language of this code must be C++ because that is the only I am familiar with. Soreland, a software company, is planning on releasing its first C++ compiler with the hopes of putting MiniSoft's Visual C++ out of business (that reminds me of another story). Consequently, Soreland has contracted with the Fruugle Corporation to design and build part of their compiler. Of course, since Fruugle gets all...

  • How do I do this C++ in a Unix Environment assignment Given dot1m.c 1. The program (dot1m.c) uses...

    How do I do this C++ in a Unix Environment assignment Given dot1m.c 1. The program (dot1m.c) uses mutex to lock and unlock the shared resource (dotstr.sum) for access control as shown below. pthread_mutex_lock (&mutexsum); dotstr.sum += mysum; printf("Thread %ld did %d to %d: mysum=%f global sum=%f\n", offset,start,end,mysum,dotstr.sum); pthread_mutex_unlock (&mutexsum); 2. Modify dot1m.c program to use reader-writer lock (instead of mutex).      Replace the codes (for mutex) by the codes (for reader-writer lock).            To initialize reader-writer lock, pthread_rwlock_initializer.            At the end,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT