root / tests / test-ftrtri.C

Revision 25, 2.4 kB (checked in by pernet, 1 year ago)

* add a transposed version of the LQUP decomposition routine LUdivine
* fix many bugs in LUdivine
* new schedules for Winograd algorithm for matrix multiplication: 2 cases depending whether beta = 0 or not, taken form [Huss Ledermann & Al. 96]
* new tests for ftrtri, echelon and redechelon

Line 
1/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2//--------------------------------------------------------------------------
3//                        Test for ftrtri : 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/ffpack.h"
18
19
20
21using namespace std;
22
23typedef Modular<float> Field;
24
25int main(int argc, char** argv){
26
27        int n;
28        int nbit=atoi(argv[3]); // number of times the product is performed
29        cerr<<setprecision(10);
30        Field::Element zero, one;
31
32        if (argc != 4)  {
33                cerr<<"Usage : test-ftrtri <p> <A> <<i>"
34                    <<endl
35                    <<"         to invert a triangular matrix  A mod p (i computations)"
36                    <<endl;
37                exit(-1);
38        }
39        Field F(atoi(argv[1]));
40        F.init(zero,0.0);
41        F.init(one,1.0);
42        Field::Element * A,*Ab;
43        A = read_field(F,argv[2],&n,&n);
44        Ab = new Field::Element[n*n];
45       
46        for (int i=0; i<n;++i){
47                for(int j=0; j<i; ++j)
48                        F.assign(*(Ab+i*n+j),*(A+i*n+j));
49                F.assign(*(Ab+i*(n+1)), 1.0);
50                for(int j=i+1; j<n; ++j)
51                        F.assign(*(Ab+i*n+j),0.0);
52        }
53
54
55        Field::Element * X = new Field::Element[n*n];
56
57        Timer tim,t; t.clear();tim.clear(); 
58               
59        for(int i = 0;i<nbit;++i){
60                t.clear();
61                t.start();
62                                FFPACK::trinv_left (F, n, A, n, X, n);
63                //FFPACK::ftrtri(F, FFLAS::FflasLower, FFLAS::FflasUnit, n, A, n);
64                t.stop();
65                tim+=t;
66                if (i+1<nbit)
67                        for (int i=0; i<n*n;++i)
68                                F.assign(*(A+i),*(Ab+i));
69        }
70
71#if DEBUG
72        FFLAS::ftrmm (F, FFLAS::FflasRight, FFLAS::FflasLower, FFLAS::FflasNoTrans, FFLAS::FflasUnit,
73                      n, n, 1.0,
74                      X,
75                      //A,
76                      n, Ab, n); 
77        bool wrong = false;
78
79        for (int i=0;i<n;++i)
80                for (int j=0;j<n;++j)
81                        if ( ((i!=j) && !F.areEqual(*(Ab+i*n+j),zero))
82                             ||((i==j) &&!F.areEqual(*(Ab+i*n+j),one)))
83                                wrong = true;
84       
85        if ( wrong ){
86                cerr<<"FAIL"<<endl;
87                write_field (F,cerr<<"Ab="<<endl,A,n,n,n);
88                //write_field (F,cerr<<"X="<<endl,X,n,n,n);
89        }else{
90       
91                cerr<<"PASS"<<endl;
92        }
93#endif
94
95#if TIME
96        double mflops = 1.0/3.0*(n*n/1000000.0)*nbit*n/tim.usertime();
97        cerr<<"n = "<<n<<" Inversion over Z/"<<atoi(argv[1])<<"Z : t= "
98             << tim.usertime()/nbit 
99             << " s, Mffops = "<<mflops
100             << endl;
101       
102        cout<<n<<" "<<mflops<<" "<<tim.usertime()/nbit<<endl;
103#endif
104}
Note: See TracBrowser for help on using the browser.