/* iobasic.c 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 defines 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; if (argc !=2) { printf("usage: %s [n]\n", argv[0]); exit(1); } 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 t1 = clock(); printf("%30s", "allocate and initialize a: "); int* a = (int*)malloc(n * sizeof(int)); assert(a); for (long i=0; i