Template-ifizierung: ulmblas.h und gemm_refcolmajor.h

Hier ist hauptsächlich der geschickte Umgang mit dem Texteditor gefragt:

An wenigen Stellen muss man aber beachten, dass dies im Allgemeinen nicht funktionieren kann:

template <typename T>
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:

template <typename T>
void
foo(T alpha)
{
    if (alpha==T(1)) {
        /* ... */
    }
}

Tests für die folgende Implementierung präsentieren wir später.

Aufgabe: ulmblas.h

#ifndef HPC_ULMBLAS_H
#define HPC_ULMBLAS_H 1

/*
      ... includes ??? ...
 */

namespace ulmBLAS {

//------------------------------------------------------------------------------
// A <- B
//------------------------------------------------------------------------------

template <typename T, typename Index>
void
gecopy(Index m, Index n,
       const T *A, Index incRowA, Index incColA,
       T *B, Index incRowB, Index incColB)
{
    /* ... */
}

//------------------------------------------------------------------------------
// Y <- Y + alpha*X
//------------------------------------------------------------------------------

template <typename T, typename Index>
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 <typename T, typename Index>
void
gescal(Index m, Index n,
       T alpha,
       T *X, Index incRowX, Index incColX)
{
    /* ... */
}

} // namespace ulmBLAS

#endif // HPC_ULMBLAS_h

Aufgabe: gemm_refcolmajor.h

#ifndef HPC_GEMM_REFCOLMAJOR_H
#define HPC_GEMM_REFCOLMAJOR_H 1

/*
      ... includes ??? ...
 */

namespace refColMajor {

template <typename T, typename Index>
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