root / tests / test-fgemv.C

Revision 21, 2.3 kB (checked in by pernet, 2 years ago)

Introduction of the new automatic choice of underlying BLAS, for any finite finite field implementation:
float/double is chosen depending on the prime, the dimension, and efficiency considerations.

Line 
1/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2//--------------------------------------------------------------------------
3//                        Test for fgemv : 1 computation
4//                 
5//--------------------------------------------------------------------------
6// Clement Pernet
7//-------------------------------------------------------------------------
8
9#define DEBUG 1
10#define TIME 1
11
12#include <iomanip>
13#include <iostream>
14#include "fflas-ffpack/modular-balanced.h"
15#include "timer.h"
16#include "Matio.h"
17#include "fflas-ffpack/fflas.h"
18
19
20
21using namespace std;
22
23typedef Modular<double> Field;
24
25int main(int argc, char** argv){
26
27        int m,n,k;
28        int nbit=atoi(argv[4]); // number of times the product is performed
29        cerr<<setprecision(10);
30        Field::Element alpha,beta;
31
32
33        if (argc != 8)  {
34                cerr<<"Usage : test-fgemm <p> <A> <b> <i>"
35                    <<" <alpha> <beta> <c>"<<endl
36                    <<"         to do i computations of c <- alpha AB + beta C"
37                    <<endl;
38                exit(-1);
39        }
40        Field F(atoi(argv[1]));
41
42        F.init( alpha, double(atoi(argv[5])));
43        F.init( beta, double(atoi(argv[6])));
44
45        Field::Element * A;
46        Field::Element * b;
47       
48        b = read_field(F,argv[3],&n,&k);
49        A = read_field(F,argv[2],&m,&n);
50       
51        Field::Element * c;
52        c = new Field::Element[n];
53
54       
55
56        Timer tim,t; t.clear();tim.clear(); 
57        for(int i = 0;i<nbit;++i){
58                c = read_field(F,argv[7],&m,&k);
59                t.clear();
60                t.start();
61                FFLAS::fgemv (F, FFLAS::FflasNoTrans,m,n,alpha, A,n, b,1,
62                              beta, c, 1);
63                t.stop();
64                tim+=t;
65        }
66
67#if DEBUG
68        Field::Element *d = new Field::Element[n];
69        for (int i=0; i<m; ++i)
70                F.mul (d[i], beta, b[i]);
71        for (int i=0; i<m; ++i)
72                F.mulin (b[i], alpha);
73        for (int i=0; i<m; ++i)
74                for (int j=0; j<n; ++j)
75                        F.axpyin (d[i], *(A+i*m+j), b[j]);
76        bool fail = false;
77        for (int i=0; i<m; ++i)
78                if (!F.areEqual(d[i], c[i]))
79                        fail = true;
80
81        if (fail)
82                cerr<<"FAIL"<<endl;
83        else
84                cerr<<"PASS"<<endl;
85        delete[] d;
86#endif
87        delete[] A;
88        delete[] b;
89        delete[] c;
90#if TIME
91        double mflops = (2.0*(m*n/1000000.0)*nbit/tim.usertime());
92        cerr << m <<"x" <<n <<" : fgemv over Z/"
93             <<atoi(argv[1])<<"Z : [ "
94             <<mflops<<" MFops in "<<tim.usertime()/nbit<<"s]"
95             << endl;
96       
97        cerr<<"alpha, beta = "<<alpha <<", "<<beta <<endl;
98
99        cout<<m<<" "<<n<<" "<<mflops<<" "<<tim.usertime()/nbit<<endl;
100#endif
101} 
102
Note: See TracBrowser for help on using the browser.