Basic HTML version of Foils prepared 19 September 98

Foil 54 Pi Example continued

From MPI Message Passing Interface Computational Science for Simulations -- Fall Semester 1998. by Geoffrey C. Fox, Nancy McCracken


1 { if (myid == 0)
2 { printf ("Enter the number of intervals: (0 quits) ");
3 scanf ("%d", &n);
4 }
5 MPI_Bcast (&n, 1, MPI_INT, 0, MPI_COMMWORLD);
6 if (n == 0) break;
7 h = 1.0 / (double) n;
8 sum = 0.0;
9 for (i = myid+1; i <= n; i += numprocs)
10 { x = h * ((double) i - 0.5); sum += 4.0 / 1.0 + x*x): }
11 mypi = h * sum;
12 MPI_Reduce (&mypi, &pi,1, MPI_DOUBLE,MPI_SUM, 0,MPI_COMMWORLD);
13 if (myid == 0)
14 printf("pi is approximately %.16f, Error is %.16f\n",pi, fabs(pi-PI35DT); }
15 MPI_Finalize; }

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Apr 11 1999