Hello!
I have been attempting to compile my double precision approximation of pi with the different compiler switches in Assignment 1, but the switches do not seem to make any difference in runtime, approximation of pi, or the number of cycles per loop iteration. I'm not exactly sure why it would be doing this, and I can't seem to get a human-readable compiler report with -opt-report5, so I'm at a complete loss.
My code is here:
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double getTimeStamp();
int main(int argc, char *argv[]) {
double wcTime,wcTimeStart,wcTimeEnd;
int SLICES = 1000000000;
double sum=0., delta_x = 1./1000000000;
wcTimeStart = getTimeStamp();
for (int i=0; i < SLICES; i++) {
double x = (i+0.5)*delta_x;
double root = sqrt(1.0 - x * x);
sum += 4.0 * root;
}
double Pi = sum * delta_x;
wcTimeEnd = getTimeStamp();
wcTime = wcTimeEnd-wcTimeStart;
//Calculate performance in cy/iteration by multiplying walltime with clock frequency to get total number of cycles.
//Then divide by the total number of iterations
double perf = wcTime * 2400000000 * delta_x;
printf("Walltime: %.3lf s\n",wcTime);
printf("The value of pi is approximately %lf .", Pi );
printf("Your cycles/iteration performance is %lf .", perf );
return 0;
}
double getTimeStamp() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (double)ts.tv_sec + (double)ts.tv_nsec * 1.e-9;
}