chundoong-lab-ta/APWS23/integral-skeleton/main.cpp

35 lines
898 B
C++
Raw Normal View History

2023-02-09 01:28:51 +09:00
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include "integral.h"
#include "util.h"
int main(int argc, char **argv) {
size_t num_intervals = 1073741824;
if (argc > 1) sscanf(argv[1], "%lu", &num_intervals);
printf("Number of intervals: %lu\n", num_intervals);
double cpu_st, cpu_en, gpu_st, gpu_en;
cpu_st = get_current_time();
double cpu_pi_estimate = integral_cpu(num_intervals);
cpu_en = get_current_time();
integral_gpu_initialize(num_intervals);
gpu_st = get_current_time();
double gpu_pi_estimate = integral_gpu(num_intervals);
gpu_en = get_current_time();
integral_gpu_finalize();
printf("Estimated PI value from CPU: %.16f\n", cpu_pi_estimate);
printf("Estimated PI value from GPU: %.16f\n", gpu_pi_estimate);
printf("CPU elapsed time: %.3f sec\n", cpu_en - cpu_st);
printf("GPU elapsed time: %.3f sec\n", gpu_en - gpu_st);
2023-02-14 01:23:28 +09:00
2023-02-09 01:28:51 +09:00
return 0;
}