int main() { float test[] = { 1,2,3,4,5,6,7,8,9}; printf("Result: %f\n", kahanSum(test, sizeof(test)/sizeof(float))); return 0; }
int main(){ srand( time(NULL) ); int i; float* v = (float*)malloc(N * sizeof(float)); for(i=0; i < N; i++){ v[i] = rand() / (float)RAND_MAX; } // for(i=0; i < N; i++){ // printf("%f ", v[i]); // } // printf("\n", v[i]); clock_t t0, t1; float resTrivial, resKahan, resPairwise; char* exact; char times[128]; const int ITERS = 100; t0 = clock(); for(i=0;i<ITERS;i++) resTrivial = trivialSum(v, N); t1 = clock(); printTime(times, t0, t1, ITERS); printf("Trivial: %s\n", times); t0 = clock(); for(i=0;i<ITERS;i++)resPairwise = pairwiseSum(v, N); t1 = clock(); printTime(times, t0, t1, ITERS); printf("Pairwise: %s\n", times); t0 = clock(); for(i=0;i<ITERS;i++)resKahan = kahanSum(v, N); t1 = clock(); printTime(times, t0, t1, ITERS); printf("Kahan: %s\n", times); exact = mpSum(v, N); printf("Trivial:\t %.32f\n", resTrivial); printf("Pairwise:\t %.32f\n", resPairwise); printf("Kahan:\t\t %.32f\n", resKahan); printf("MP:\t\t %s\n", exact); free(v); free(exact); return 0; }