7
#define DEFAULT_SIZE 100
9
size_t exercise(unsigned long *res, size_t size, int iterations);
10
int exercise_init(const char *name, size_t size);
13
extern int exercise_required_alignment;
15
size_t get_padded_size(size_t size, size_t block_size) {
16
size_t blocks = (size / block_size);
17
size_t inc = blocks * block_size - size;
18
if (inc) return (blocks + 1) * block_size;
22
int main(int argc, char *argv[]) {
25
size_t size = DEFAULT_SIZE;
26
size_t iterations = ITERATIONS;
27
int standard_memory = 0;
32
struct timeval tv1,tv2;
34
char *name, fname[255];
37
name = strrchr(argv[0], '/');
46
iterations = atoi(argv[2]);
47
if (!iterations) iterations = 1;
52
if (exercise_required_alignment > 1) {
53
size = get_padded_size(size, exercise_required_alignment);
56
setlocale(LC_NUMERIC, "en_US");
57
printf("Computing pi using %'lum throws of monte carlo, Iterations %u\n", size/1000000, iterations);
59
err = exercise_init(name, size);
62
gettimeofday(&tv1, NULL);
63
runtime = exercise(&res, size, iterations);
64
gettimeofday(&tv2, NULL);
66
if (runtime == (size_t)-1) {
70
printf("Result: %lf (should 3.14159265358979323846)\n", 4. * res / size);
74
us = (tv2.tv_sec - tv1.tv_sec)*1000000 + (tv2.tv_usec - tv1.tv_usec);
76
printf("Speed: %.2lf giga-tries/sec (%lf s)\n", 0.001 * size / us, us / 1000000.);