===================================================== Template-ifizierung: ulmblas.h und gemm_refcolmajor.h ===================================================== Hier ist hauptsächlich der geschickte Umgang mit dem Texteditor gefragt: - Include-Guards einfügen. - Template-Parameter für Element- und Index-Typen verwenden. An wenigen Stellen muss man aber beachten, dass dies im Allgemeinen nicht funktionieren kann: ---- CODE (type=cc) ------------------------------------------------------------ template void foo(T alpha) { if (alpha==1.0) { /* ... */ } } -------------------------------------------------------------------------------- Die Konstante `1.0` ist vom Typ `double`, aber _alpha_ im Allgemeinen nicht. Wir gehen aber davon aus, dass der Typ `T` einen Konstruktor besitzt, der eine `int` akzeptiert, so dass dies stets funktioniert: ---- CODE (type=cc) ------------------------------------------------------------ template void foo(T alpha) { if (alpha==T(1)) { /* ... */ } } -------------------------------------------------------------------------------- Tests für die folgende Implementierung präsentieren wir später. Aufgabe: `ulmblas.h` ==================== ---- CODE (type=cc) ------------------------------------------------------------ #ifndef HPC_ULMBLAS_H #define HPC_ULMBLAS_H 1 /* ... includes ??? ... */ namespace ulmBLAS { //------------------------------------------------------------------------------ // A <- B //------------------------------------------------------------------------------ template void gecopy(Index m, Index n, const T *A, Index incRowA, Index incColA, T *B, Index incRowB, Index incColB) { /* ... */ } //------------------------------------------------------------------------------ // Y <- Y + alpha*X //------------------------------------------------------------------------------ template void geaxpy(Index m, Index n, T alpha, const T *X, Index incRowX, Index incColX, T *Y, Index incRowY, Index incColY) { /* ... */ } //------------------------------------------------------------------------------ // A <- alpha * A //------------------------------------------------------------------------------ template void gescal(Index m, Index n, T alpha, T *X, Index incRowX, Index incColX) { /* ... */ } } // namespace ulmBLAS #endif // HPC_ULMBLAS_h -------------------------------------------------------------------------------- Aufgabe: `gemm_refcolmajor.h` ============================= ---- CODE (type=cc) ------------------------------------------------------------ #ifndef HPC_GEMM_REFCOLMAJOR_H #define HPC_GEMM_REFCOLMAJOR_H 1 /* ... includes ??? ... */ namespace refColMajor { template void gemm(Index m, Index n, Index k, T alpha, const T *A, Index incRowA, Index incColA, const T *B, Index incRowB, Index incColB, T beta, T *C, Index incRowC, Index incColC) { /* ... */ } } // namespace refColMajor #endif // HPC_GEMM_REFCOLMAJOR_H -------------------------------------------------------------------------------- :navigate: up -> doc:index back -> doc:session10/page03 next -> doc:session10/page05