1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
#include <cstdio>
#include <cassert>
#include <chrono>
#include <complex>
#include <cmath>
#include <limits>
#include <random>
#include <flens/flens.cxx>

#ifndef MAX_N
#define MAX_N 4000
#endif

#ifndef MAX_M
#define MAX_M 4000
#endif

#include "common.h"

#define BLASINT int64_t

//------------------------------------------------------------------------------

extern "C" {

void
sger_(const BLASINT *m, const BLASINT *n,
      const float *alpha,
      const float *x, const BLASINT *incx,
      const float *y, const BLASINT *incy,
      float *A, const BLASINT *lda);

void
dger_(const BLASINT *m, const BLASINT *n,
      const double *alpha,
      const double *x, const BLASINT *incx,
      const double *y, const BLASINT *incy,
      double *A, const BLASINT *lda);

void
cgeru_(const BLASINT *m, const BLASINT *n,
       const float *alpha,
       const float *x, const BLASINT *incx,
       const float *y, const BLASINT *incy,
       float *A, const BLASINT *lda);

void
zgeru_(const BLASINT *m, const BLASINT *n,
       const double *alpha,
       const double *x, const BLASINT *incx,
       const double *y, const BLASINT *incy,
       double *A, const BLASINT *lda);

void
cgerc_(const BLASINT *m, const BLASINT *n,
       const float *alpha,
       const float *x, const BLASINT *incx,
       const float *y, const BLASINT *incy,
       float *A, const BLASINT *lda);

void
zgerc_(const BLASINT *m, const BLASINT *n,
       const double *alpha,
       const double *x, const BLASINT *incx,
       const double *y, const BLASINT *incy,
       double *A, const BLASINT *lda);

} // extern "C"


//------------------------------------------------------------------------------

template <typename Index>
void
f77_ger(Index m, Index n,
        float alpha,
        const float *X, Index incX,
        const float *Y, Index incY,
        float *A, Index ldA)
{
    BLASINT M     = m;
    BLASINT N     = n;
    BLASINT INCX  = incX;
    BLASINT INCY  = incY;
    BLASINT LDA   = ldA;

    sger_(&M, &N,
          &alpha,
          X, &INCX,
          Y, &INCY,
          A, &LDA);
}

template <typename Index>
void
f77_ger(Index m, Index n,
        double alpha,
        const double *X, Index incX,
        const double *Y, Index incY,
        double *A, Index ldA)
{
    BLASINT M     = m;
    BLASINT N     = n;
    BLASINT INCX  = incX;
    BLASINT INCY  = incY;
    BLASINT LDA   = ldA;

    dger_(&M, &N,
          &alpha,
          X, &INCX,
          Y, &INCY,
          A, &LDA);
}

template <typename Index>
void
f77_ger(Index m, Index n,
        const std::complex<float> &alpha,
        const std::complex<float> *X, Index incX,
        const std::complex<float> *Y, Index incY,
        std::complex<float> *A, Index ldA)
{
    BLASINT M     = m;
    BLASINT N     = n;
    BLASINT INCX  = incX;
    BLASINT INCY  = incY;
    BLASINT LDA   = ldA;

    cgeru_(&M, &N,
           (const float *)&alpha,
           (const float *)X, &INCX,
           (const float *)Y, &INCY,
           (float *)A, &LDA);
}

template <typename Index>
void
f77_ger(Index m, Index n,
        const std::complex<double> &alpha,
        const std::complex<double> *X, Index incX,
        const std::complex<double> *Y, Index incY,
        std::complex<double> *A, Index ldA)
{
    BLASINT M     = m;
    BLASINT N     = n;
    BLASINT INCX  = incX;
    BLASINT INCY  = incY;
    BLASINT LDA   = ldA;

    zgeru_(&M, &N,
           (const double *)&alpha,
           (const double *)X, &INCX,
           (const double *)Y, &INCY,
           (double *)A, &LDA);
}

//------------------------------------------------------------------------------

int
main()
{
    typedef flens::DenseVector<flens::Array<TYPE_X> >          DenseVectorX;
    typedef flens::DenseVector<flens::Array<TYPE_Y> >          DenseVectorY;
    typedef flens::GeMatrix<flens::FullStorage<TYPE_A> >       GeMatrixA;

    TYPE_ALPHA   alpha = ALPHA;

    const std::size_t min_m = MIN_M;
    const std::size_t min_n = MIN_N;

    const std::size_t max_m = MAX_M;
    const std::size_t max_n = MAX_N;

    const std::size_t inc_m = INC_M;
    const std::size_t inc_n = INC_N;

    std::printf("#%5s %5s ", "m", "n");
    std::printf("%20s %9s", "FLENS/ulmBLAS: t", "MFLOPS");
    std::printf("%20s %9s %9s", BLAS_LIB  ":  t", "MFLOPS", "Residual");
    std::printf("\n");

    WallTime<double>  walltime;

    for (std::size_t m=min_m, n=min_n;
         m<=max_m && n<=max_n;
         m += inc_m, n += inc_n)
    {
        DenseVectorX    X(m);
        DenseVectorY    Y(n);
        GeMatrixA       A1(m, n);
        GeMatrixA       A2(m, n);

        fill(X);
        fill(Y);
        fill(A1);
        A2 = A1;

        walltime.tic();
        flens::blas::r(alpha, X, Y, A1);
        double t1 = walltime.toc();

        walltime.tic();
        f77_ger(A2.numRows(), A2.numCols(),
                alpha,
                X.data(), X.stride(),
                Y.data(), Y.stride(),
                A2.data(), A2.leadingDimension());
        double t2 = walltime.toc();

        double res = asumDiff(A1, A2)/(m*n);

        std::printf(" %5ld %5ld ", m, n);
        std::printf("%20.4lf %9.2lf", t1, 2.*m/1000.*n/1000./t1);
        std::printf("%20.4lf %9.2lf", t2, 2.*m/1000.*n/1000./t2);
        std::printf(" %9.1e", res);
        std::printf("\n");
    }
}