35 lines
898 B
C++
35 lines
898 B
C++
#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);
|
|
|
|
return 0;
|
|
}
|