Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include double f ( double x ) { return sin ( x ) ; } double Trap ( int n , double a

#include
#include
#include
double f(double x)
{
return sin(x);
}
double Trap(int n, double a, double b, double h)
{
double T, x;
int i;
T =(f(a)+ f(b))/2.0;
for (i =1; i <= n -1; i++)
{
x = a + i * h;
T += f(x);
}
T = T * h;
return T;
}
int main(int argc, char* argv[]){
int rank, S, n;
double a, b, h, local_a, local_b, local_integral, integral;
int local_n;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &S);
if (rank ==0){
printf("Enter a, b, and n:
");
scanf_s("%lf %lf %d", &a, &b, &n);
h =(b - a)/ n;
}
MPI_Bcast(&a,1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Bcast(&b,1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Bcast(&n,1, MPI_INT, 0, MPI_COMM_WORLD);
h =(b - a)/ n;
// Compute the interval for each process
local_n = n / S;
local_a = a + rank * local_n * h;
local_b = local_a + local_n * h;
// Compute the area under the curve using the trapezoidal
local_integral = Trap(local_a, local_b, local_n, h);
MPI_Reduce(&local_integral, &integral, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
// Process 0
if (rank ==0){
printf("With n =%d trapezoids, our estimate of the integral from %f to %f =%f
", n, a, b, integral);
}
MPI_Finalize();
return 0;
}
I need these parts in code:
1- execution time
2-speedup = Tserial/Tparallel
3- efficiency = speedup/#threads

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

Discuss how selfesteem is developed.

Answered: 1 week ago