Implemented everything pending Python chart generation

This commit is contained in:
uzy lol 2024-10-24 16:34:21 -07:00
parent 475aaf100f
commit 29b4f6b2ef
3 changed files with 27 additions and 11 deletions

View File

@ -14,17 +14,16 @@
#include <vector> #include <vector>
#include <string.h> #include <string.h>
extern void setup(int64_t N, uint64_t A[]); extern void setup(int64_t N, uint64_t A[]);
extern int64_t sum(int64_t N, uint64_t A[]); extern int64_t sum(int64_t N, uint64_t A[]);
/* The benchmarking program */ /* The benchmarking program */
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
std::cout << std::fixed << std::setprecision(2); std::cout << std::fixed << std::setprecision(2);
#define MAX_PROBLEM_SIZE 1 << 28 // 256M #define MAX_PROBLEM_SIZE 1 << 28 // 256M
std::vector<int64_t> problem_sizes{ MAX_PROBLEM_SIZE >> 5, MAX_PROBLEM_SIZE >> 4, MAX_PROBLEM_SIZE >> 3, MAX_PROBLEM_SIZE >> 2, MAX_PROBLEM_SIZE >> 1, MAX_PROBLEM_SIZE}; std::vector<int64_t> problem_sizes{MAX_PROBLEM_SIZE >> 5, MAX_PROBLEM_SIZE >> 4, MAX_PROBLEM_SIZE >> 3, MAX_PROBLEM_SIZE >> 2, MAX_PROBLEM_SIZE >> 1, MAX_PROBLEM_SIZE};
std::vector<uint64_t> A(MAX_PROBLEM_SIZE); std::vector<uint64_t> A(MAX_PROBLEM_SIZE);
@ -40,13 +39,19 @@ int main(int argc, char** argv)
setup(n, &A[0]); setup(n, &A[0]);
// insert your timer code here // insert your timer code here
std::chrono::time_point<std::chrono::high_resolution_clock> start_time = std::chrono::high_resolution_clock::now();
// invoke method to perform the sum // invoke method to perform the sum
t = sum(n, &A[0]); t = sum(n, &A[0]);
// insert your end timer code here, and print out elapsed time for this problem size // insert your end timer code here, and print out elapsed time for this problem size
std::chrono::time_point<std::chrono::high_resolution_clock> end_time = std::chrono::high_resolution_clock::now();
printf(" Sum result = %lld \n",t); std::chrono::duration<double> elapsed = end_time - start_time;
std::cout << " Elapsed time is : " << elapsed.count() << " " << std::endl;
printf(" Sum result = %lld \n", t);
} // end loop over problem sizes } // end loop over problem sizes
} }

View File

@ -13,6 +13,7 @@ void
setup(int64_t N, uint64_t A[]) setup(int64_t N, uint64_t A[])
{ {
printf(" inside direct_sum problem_setup, N=%lld \n", N); printf(" inside direct_sum problem_setup, N=%lld \n", N);
result = 0;
} }
int64_t int64_t
@ -23,6 +24,6 @@ sum(int64_t N, uint64_t A[])
{ {
result += i; result += i;
} }
return 0; return result;
} }

View File

@ -6,19 +6,29 @@
#include <vector> #include <vector>
#include <string.h> #include <string.h>
int64_t result;
void void
setup(int64_t N, uint64_t A[]) setup(int64_t N, uint64_t A[])
{ {
printf(" inside sum_vector problem_setup, N=%lld \n", N); printf(" inside sum_vector problem_setup, N=%lld \n", N);
result = 0;
for (int64_t i = 0; i < N; i++)
{
A[i] = i;
}
} }
int64_t int64_t
sum(int64_t N, uint64_t A[]) sum(int64_t N, uint64_t A[])
{ {
printf(" inside sum_vector perform_sum, N=%lld \n", N); printf(" inside sum_vector perform_sum, N=%lld \n", N);
for (int64_t i = 0; i < N; i++)
{
result += A[i];
}
return 0; return result;
} }