diff --git a/mpi_pi_cpu/mpi_pi_cpu.c b/mpi_pi_cpu/mpi_pi_cpu.c index 7f4031a97f020a2662f62a86750f261203cb242e..722d7c9b5e7d314a0c05b29686a1793681af5dba 100644 --- a/mpi_pi_cpu/mpi_pi_cpu.c +++ b/mpi_pi_cpu/mpi_pi_cpu.c @@ -10,17 +10,19 @@ #include <sys/time.h> // number of terms evaluated by each process -#define NPTS 1000000 +#define NPTS 250000000 void main(int argc, char** argv) { // variables used by all ranks - int rank, i, istart, iend; + int rank; + long unsigned int i, istart, iend; double sum, pi; // variables used only by rank 0 unsigned long int start_time, end_time; struct timeval start, end; int nproc; + unsigned long int total_terms; double mflops; MPI_Init(&argc, &argv); @@ -28,11 +30,13 @@ void main(int argc, char** argv) { if (rank == 0) { MPI_Comm_size(MPI_COMM_WORLD, &nproc); + total_terms = nproc; + total_terms *= NPTS; gettimeofday(&start, NULL); } - istart = NPTS * rank + 1; - iend = NPTS * (rank + 1) + 1; + istart = (long unsigned int)NPTS * rank + 1; + iend = istart + NPTS; sum = 0.0; for (i = istart; i <= iend; ++i) { sum += 0.5 / ((i - 0.75) * (i - 0.25)); @@ -44,8 +48,8 @@ void main(int argc, char** argv) { start_time = start.tv_sec * 1e6 + start.tv_usec; end_time = end.tv_sec * 1e6 + end.tv_usec; mflops = (double)nproc * NPTS * 5.0 / (end_time - start_time); - printf("processes = %d, terms per process = %ld, total terms = %ld\n", nproc, NPTS, nproc * NPTS); - printf("time = %f, estimated MFlops = %f\n", (end_time - start_time) / 1.0e6, mflops); + printf("processes = %d, terms per process = %ldM, total terms = %ldM\n", nproc, NPTS / 1000000, total_terms / 1000000); + printf("time = %fs, estimated GFlops = %f\n", (end_time - start_time) / 1.0e6, mflops / 1000); printf("pi ~ %f\n", pi); }