#include #include #include /* 10 million */ #define N 10000000 /* the kernel fills an array up with square roots */ void square_roots(double* array) { unsigned int i; for (i = 0; i < N; i++) { array[i] = sqrt((double) i); } } int main() { /* store the square roots of 0 to (N-1) on the CPU * stored on the heap since it's too big for the stack for large values of N */ double* roots = (double*) malloc(N * sizeof(double)); /* calculate the square roots on the CPU */ square_roots(roots); /* print out 100 evenly spaced square roots just to see that it worked */ unsigned int i; for (i = 0; i < N; i += (N / 100)) { printf("sqrt(%d) = %lf\n", i, roots[i]); } /* free the CPU memory */ free(roots); return 0; }