/* iobasic.c Run as: iobasic What is does: allocates an array of n integegers, and traverses the array in sequential vs random order. Demonstrates the effect of the memory hierarchy and the limitations of the RAM model. The RAM model assumes that all memory accesses take the same and complexity is modeled as complexity = CPU complexity = nb. CPU operations When working with large data the cache and IO behaviour (nb. cache misses/page faults) are relevant and may actually be dominant. Theoretically this is modeled by cache complexity = nb blocks transferred between cache and main memory IO complexity = nb blocks transferred between main memory and disk */ #include #include #include #include #define PRINT if(0) int main(int argc, char** argv) { clock_t t1, t2; //need to run as: iobasic if (argc !=2) { printf("usage: %s [n]\n", argv[0]); exit(1); } //convert the argument to a long and print it long n = atol(argv[1]); printf("n=%ld (%.1f G) ints which require %.1f GB RAM\n", n, (float)n/(1<<30), (float)n*sizeof(int)/(1<<30)); //allocate and initialize an array of n ints t1 = clock(); printf("%30s", "allocate and initialize a: "); int* a = (int*)malloc(n * sizeof(int)); assert(a); for (long i=0; i