Skip to content
Snippets Groups Projects
Commit 9696f017 authored by Erik Strand's avatar Erik Strand
Browse files

Evaluate more terms

Now the calculation runs for about 2 seconds. Previously it was a
fraction of a second, so GFLOPS between runs varied wildly.
parent 63f36cbe
No related branches found
Tags
No related merge requests found
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment