Concept explainers
Please note this is not Java or C++
Complete the program 'Bcast-Reduce-Assignment.c' to make the program have the output as follows if we run the program using 2 processes.
The input sequence is:
0 1 2 3
The output sequence is:
0 2 6 12
This is an MPI program and the code below is partially finished. i am supposed to have input above result in the output above.
//////////////////////////////////////////////////////////////////////////
//
// This is a simple MPI program using MPI_Bcast and MPI_Reduce functions
//
// Compile: mpicc Bcast-Reduce-Example.c -o Bcast-Reduce-Example
//
// Run: mpiexec -n <p> ./Bcast-Reduce-Example
//
// -p: the number of processes
//
/////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
int main(void)
{
int my_rank, comm_sz;
int i;
int Count = 4;
int Number[4];
int PartialResult = 0;
int Result;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if(my_rank == 0)
{
printf("The input sequence is as follows: \n");
for (i = 0; i < Count; i++)
{
Number[i] = i;
printf("%d ", Number[i]);
}
printf("\n");
}
// Process 0 sends data to all of the processes
MPI_Bcast(Number, Count, MPI_INT, 0, MPI_COMM_WORLD);
for (i = 0; i < Count; i++)
{
Number[i] += my_rank;
PartialResult += Number[i];
}
MPI_Reduce(&PartialResult, &Result, 1, MPI_INT, MPI_PROD, 0, MPI_COMM_WORLD);
// Print out the result
if (my_rank == 0)
printf("The final resutl is: %d. \n", Result);
MPI_Finalize();
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- output should be the same in the sample outputarrow_forward23. Write a C++ program that reads a positive integer n and then prints the following pattern which has got 2n-1 rows of stars. The following pattern shows the required output for the case n = 6. Your cout statement must print only one digit at a time. Therefore you must use a nested loop. You can choose whichever loop structure (for, while, do-while or combination of them) to use. The following diagram shows the answer for n = 6. 1 1 1 1 1 1 1 2 2 3 2 3 4 2 3 4 5 2 3 4 5 2 3 4 5 1 1 2 3 1 2 1 2 3 4 5 6 5 5 1 2 1 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 3 2 1 2 1 1arrow_forwardQuestion 1: Please develop a program. The program shows a O(n^2) time complexity. You may design nested loops. When you input a number, the output should be how many times of the loops. For example, if your input is 10, the number of loops should be 100 times, 200 times, 300 times, etc. The number of loops do not have to be an accurate number.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education