dimanche 6 septembre 2015

Using C++ function templates for a group of functions

I have different functions for square matrix multiplication depending on matrix size which varies from 8x8 through 20x20. The functions differ from each other because each employ different strategies for optimization, namely, different loop permutations and different loop unroll factors. Matrix size is invariant during the life of a program. My goal is to reduce the time to decide which function must be used. For example, a naive implementation is:

 if (matrixSize == 8) C = mxm8(A, B);
 else if (matrixSize == 9) C = mxm9(A,B);
 ...
 else if (matrixSize == 20) C = mxm20(A,B);

The time taken to decide which function to use for every matrix multiplication is non-trivial in this case. Can the appropriate function be called right away, perhaps using C++ function templates?

Aucun commentaire:

Enregistrer un commentaire