Permalink
Browse files

Added cache testing to valgrind example

  • Loading branch information...
1 parent b0f970d commit 4dfb8a68e4668e7086104e50728216b6e8c38fac @guyrt guyrt committed Feb 27, 2012
Showing with 61 additions and 13 deletions.
  1. +39 −2 valgrind/Readme.rst
  2. +22 −11 valgrind/cacheTest.cc
View
@@ -1,3 +1,40 @@
-Run this line to see errors in this code.
+Compile each program without optimization first.
+
+For simpleTest.cc, run this line to see errors in this code.
+
+::
+
+ valgrind --track-origins=yes --leak-check=full ./simpleTest 300 300
+
+
+We also have a cache test line. Run this line to see the cache errors.
+
+::
+
+ valgrind --tool=cachegrind ./a.out 0 1000 100000
+
+There are two paths in this code. If the first input is 1, it runs a cache-sensitive version of the loop.
+If it is 0, it runs a cache-insensitive version.
+
+FYI: on the Trieste lab machines, this is what cache looks like:
+
+::
+
+ guy ~>dmesg | grep cache
+ CPU: L1 I cache: 32K, L1 D cache: 32K
+ CPU: L2 cache: 6144K
+ CPU: L1 I cache: 32K, L1 D cache: 32K
+ CPU: L2 cache: 6144K
+
+You can run the same command to see cache on your linux machine. Another way to see the exact cache setup that
+valgrind found is the following:
+
+::
+
+ cg_annotate --auto=yes cachegrind.out.21960
+
+Note that your cachegrind.out will have a different number. This command is also handy because it shows which functions caused cache
+misses.
+
+
-valgrind --track-origins=yes --leak-check=full ./a.out
View
@@ -7,23 +7,34 @@ Tests cache misses.
int main(int argc, char **argv)
{
- if (argc < 2){
- printf("Usage: cacheTest sizeI sizeJ\n");
+ if (argc < 4){
+ printf("Usage: cacheTest fast sizeI sizeJ\nIn first input, use 1 for fast code (cache-smart) and anything else for slow (cache-poor) execution.\n");
return 1;
}
- int sI = atoi(argv[1]);
- int sJ = atoi(argv[2]);
- int *arr = new int[sI*sJ]; // double array.
+ int runFast = atoi(argv[1]);
+ long sI = atoi(argv[2]);
+ long sJ = atoi(argv[3]);
+ printf("Operating on matrix of size %d by %d\n",sI,sJ);
+
+ long *arr = new long[sI*sJ]; // double array.
+
+ // El mejor!
//for (int i=0; i < sI*sJ; ++i) arr[i] = i;
- for (int i=0; i < sI; ++i)
- for (int j=0; j < sJ; ++j)
- arr[(i * (sJ)) + j ] = i;
+ if (runFast == 1){
+
+ for (long i=0; i < sI; ++i)
+ for (long j=0; j < sJ; ++j)
+ arr[(i * (sJ)) + j ] = i;
- for (int i=0; i < sI; ++i)
- for (int j=0; j < sJ; ++j)
- arr[(j * (sI)) + i ] = i;
+ }else{
+
+ for (long i=0; i < sI; ++i)
+ for (long j=0; j < sJ; ++j)
+ arr[(j * (sI)) + i ] = i;
+
+ }
return 1;
}

0 comments on commit 4dfb8a6

Please sign in to comment.