#include #include #include #include #include #include #include #include #include #include "example_util_gettime.h" #define COARSENESS 100 #define ITERS 10 int rec_cilkified(int * a, int * b, int n ) { return 0; } int loop_cilkified(int * a, int * b, int n) { return 0; } int hyperobject_cilkified(int * a, int * b, int n) { return 0; } // A simple test harness int inn_prod_driver(int n) { int * a = new int[n]; int * b = new int[n]; for (int i = 0; i < n; ++i) { a[i] = i; b[i] = i; } std::random_shuffle(a, a + n); std::random_shuffle(b, b + n); int seqresult = std::inner_product(a, a+n, b, 0); long t1 = example_get_time(); for(int i=0; i< ITERS; ++i) { seqresult = std::inner_product(a, a+n, b, 0); } long t2 = example_get_time(); float seqtime = (t2-t1)/(ITERS*1000.f); std::cout << "Sequential time: " << seqtime << " seconds" << std::endl; /***********************************************************/ /******** START TESTING RECURSIVE CILKFIED VERSION *******/ /***********************************************************/ int parresult = rec_cilkified(a, b, n); t1 = example_get_time(); for(int i=0; i< ITERS; ++i) { parresult = rec_cilkified(a, b, n); } t2 = example_get_time(); float partime = (t2-t1)/(ITERS*1000.f); std::cout << "Recursive cilkified time:" << partime << " seconds" << std::endl; std::cout << "Speedup is: " << seqtime/partime << std::endl; std::cout << "Result is " << ((seqresult == parresult) ? "correct":"incorrect") << std::endl; /****************************************************************/ /******** START TESTING NESTED LOOPED CILKIFIED VERSION *******/ /****************************************************************/ parresult = loop_cilkified(a, b, n); t1 = example_get_time(); for(int i=0; i< ITERS; ++i) { parresult = loop_cilkified(a, b, n); } t2 = example_get_time(); partime = (t2-t1)/(ITERS*1000.f); std::cout << "Nested loop cilkified time: " << partime << " seconds" << std::endl; std::cout << "Speedup is: " << seqtime/partime << std::endl; std::cout << "Result is " << ((seqresult == parresult) ? "correct":"incorrect") << std::endl; /**************************************************************/ /******** START TESTING HYPEROBJECT CILKIFIED VERSION *******/ /**************************************************************/ parresult = hyperobject_cilkified(a, b, n); t1 = example_get_time(); for(int i=0; i< ITERS; ++i) { parresult = hyperobject_cilkified(a, b, n); } t2 = example_get_time(); partime = (t2-t1)/(ITERS*1000.f); std::cout << "Hyperobject cilkified time:" << (t2-t1)/(ITERS * 1000.f) << " seconds" << std::endl; std::cout << "Speedup is: " << seqtime/partime << std::endl; std::cout << "Result is " << ((seqresult == parresult) ? "correct":"incorrect") << std::endl; delete [] a; delete [] b; return 0; } int cilk_main(int argc, char* argv[]) { int n = 1 * 1000 * 1000; if (argc > 1) { n = std::atoi(argv[1]); } return inn_prod_driver(n); }