// integral.c #include #include "mpi.h" int main(int argc, char **argv) { double integral; double a, b; int n; double h; double x; int i, rank, size; double f(double x); // MPI_Status status; // MPI_Init(&argc, &argv); // MPI_Comm_rank(MPI_COMM_WORLD, &rank); // MPI_Comm_size(MPI_COMM_WORLD, &size); printf("Enter a, b, and n\n"); scanf("%lf %lf %d", &a, &b, &n); h = (b - a)/n; integral = (f(a) + f(b))/2.0; x = a; for(i = 1; i <= n-1; i++) { x = x + h; integral = integral + f(x); } integral = integral*h; printf("With n = %d trapezoids, the estimate ",n); printf("of the integral from %lf to %lf = %lf\n", a, b, integral); // MPI_Finalize(); return 0; } double f(double x) { return x * x; } /* CRAY SV1: cc integral.c ./a.out */