Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

The following code isn't working correctly and I am unable to figure out why. The for loop is never reached in the first if statement and the program never terminates. May someone please explain to me why that is.

 

 

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <mpi.h>
int main(void)
{
int sum, comm_sz, my_rank, i, next, x;
int powTwo = 2;
int diff = 1;

MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
srandom((unsigned)time(NULL) + my_rank);
x = random() % 10;
if (my_rank % powTwo == 0)
{
printf("IF----");
printf("Process %d generates: %d\n", my_rank, x);
for (i = 0; i < comm_sz; i++)
{
MPI_Recv(&x, 1, MPI_INT, i, my_rank , MPI_COMM_WORLD, MPI_STATUS_IGNORE);
sum += x;
printf("Current Sum=: %d\n", sum);
}

printf("The new divisor is:%d\n", powTwo);
powTwo *= 2;
diff *= 2;

} else if (my_rank % powTwo != 0) {
printf("ELSE----");
printf("Process %d generates: %d\n", my_rank, x);
MPI_Send(&x, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
}else if (my_rank==0){
printf("Sum=: %d\n", sum);
}
MPI_Finalize();
return 0;
}

In the following figure shows how to distribute amount of work between 8 processes (See
lecture 7, page 21):
Processes
1
3
4
6
7
5
9.
11
Write an MPI program to generate a random number in the range 0-10 for each process.
Your MPI program must works for 1, 2, 4, 8, 16, 32, 64, 128 process.
Note: Assume the user enters power of 2 for the numbers of processes.
The following is just a sample from my program for 128 processes. Your program must
work for any number of processes that is a power of 2:
expand button
Transcribed Image Text:In the following figure shows how to distribute amount of work between 8 processes (See lecture 7, page 21): Processes 1 3 4 6 7 5 9. 11 Write an MPI program to generate a random number in the range 0-10 for each process. Your MPI program must works for 1, 2, 4, 8, 16, 32, 64, 128 process. Note: Assume the user enters power of 2 for the numbers of processes. The following is just a sample from my program for 128 processes. Your program must work for any number of processes that is a power of 2:
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education