a2 - MPI_Comm_size (MPI_COMM_WORLD, &p); M for (i=0; i...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <stdio.h> #include <mpi.h> # #define INTERVALS 1000000 # int main (int argc, char*argv[]) { double area; /* area under curve*/ double ysum; /*Sum of rectangle heights */ double xi; /*Midpoint of interval*/ double tArea; // total Area int i; i int id; // Process Rank int p; //Number of processes ysum = 0.0; y MPI_Init(&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &id);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MPI_Comm_size (MPI_COMM_WORLD, &p); M for (i=0; i <INTERVALS; i+= p) { xi=(1.0/INTERVALS)*(i+0.5); ysum+=4.0/(1.0+xi*xi); } area = ysum * (1.0 / INTERVALS); a MPI_Reduce(&area, &tArea, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); M if(id == 0) printf ("Area is %13.11f\n", tArea); p MPI_Finalize(); return 0; }...
View Full Document

This note was uploaded on 02/14/2010 for the course COMPUTER S COIS-3030 taught by Professor Hircock during the Spring '10 term at Trent University.

Ask a homework question - tutors are online