I'm writing code that uses a lot of graph operations; many higher-level algorithms iterate over all the graph edges and do some processing on them. There's an iterator method that returns a batch of edges, like so:
G.get_edges(edges,iterator,num_edges);
for (k = 0; k < num_edges; k++) {
i = edges[k,0];
j = edges[k,1];
// Do something to (i,j)
}
Elsewhere in the program, there's a parameter called batch_size
which is the standard number of edges to operate on whenever this algorithm is called. Currently, I have have batch_size
hard-coded to 64, figuring that a cache line can hold 128 integers on my computer.
What's a sane way to automatically tune the batch size? I'd like to do something akin to how ATLAS chooses the block size without having to read the ATLAS source code.
My best guess for how this should work:
Compile an initial version of the code where the batch size is chosen at run-time
Run a test suite several times with different batch sizes.
Pick the batch size
b
for which the test suite ran fastest.Generate a new
.h
file containing a pre-processor directive that sets the batch size to beb
.Compile the rest of the code, for which the batch size is now known at compile time.