| 1 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
|---|
| 2 | //-------------------------------------------------------------------------- |
|---|
| 3 | // Test for ftrsm : 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 | using namespace std; |
|---|
| 21 | |
|---|
| 22 | //typedef ModularBalanced<double> Field; |
|---|
| 23 | typedef ModularBalanced<float> Field; |
|---|
| 24 | |
|---|
| 25 | int main(int argc, char** argv){ |
|---|
| 26 | |
|---|
| 27 | int k,n,m; |
|---|
| 28 | cerr<<setprecision(10); |
|---|
| 29 | Field::Element zero, one; |
|---|
| 30 | |
|---|
| 31 | if (argc != 10) { |
|---|
| 32 | cerr<<"Usage : test-ftrsm <p> <A> <B> <iter> <alpha> <left/right> <Up/Low> <NoTrans/Trans> <NonUnit/Unit>" |
|---|
| 33 | <<endl; |
|---|
| 34 | exit(-1); |
|---|
| 35 | } |
|---|
| 36 | int nbit=atoi(argv[4]); // number of times the product is performed |
|---|
| 37 | Field F(atof(argv[1])); |
|---|
| 38 | F.init(zero,0.0); |
|---|
| 39 | F.init(one,1.0); |
|---|
| 40 | Field::Element * A, *B, *B2; |
|---|
| 41 | A = read_field(F,argv[2],&k,&k); |
|---|
| 42 | B = read_field(F,argv[3],&m,&n); |
|---|
| 43 | B2 = new Field::Element[m*n]; |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | for (int i=0; i<m;++i){ |
|---|
| 47 | for(int j=0; j<n; ++j) |
|---|
| 48 | F.assign(*(B2+i*n+j),*(B+i*n+j)); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | Field::Element alpha; |
|---|
| 52 | F.init (alpha, atof(argv[5])); |
|---|
| 53 | |
|---|
| 54 | FFLAS::FFLAS_SIDE side = (atoi(argv[6])) ? FFLAS::FflasRight : FFLAS::FflasLeft; |
|---|
| 55 | FFLAS::FFLAS_UPLO uplo = (atoi(argv[7])) ? FFLAS::FflasLower : FFLAS::FflasUpper; |
|---|
| 56 | FFLAS::FFLAS_TRANSPOSE trans = (atoi(argv[8])) ? FFLAS::FflasTrans : FFLAS::FflasNoTrans; |
|---|
| 57 | FFLAS::FFLAS_DIAG diag = (atoi(argv[9])) ? FFLAS::FflasUnit : FFLAS::FflasNonUnit; |
|---|
| 58 | |
|---|
| 59 | if ( ((side == FFLAS::FflasRight) &&(k != n)) |
|---|
| 60 | || ((side == FFLAS::FflasLeft)&&(k != m))) { |
|---|
| 61 | cerr<<"Error in the dimensions of the input matrices"<<endl; |
|---|
| 62 | exit(-1); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | Timer t; t.clear(); |
|---|
| 66 | double time=0.0; |
|---|
| 67 | //write_field(F, cerr<<"A="<<endl, A, k,k,k); |
|---|
| 68 | |
|---|
| 69 | for(int i = 0;i<nbit;++i){ |
|---|
| 70 | t.clear(); |
|---|
| 71 | t.start(); |
|---|
| 72 | FFLAS::ftrsm (F, side, uplo, trans, diag, m, n, alpha, A, k, B, n); |
|---|
| 73 | t.stop(); |
|---|
| 74 | time+=t.usertime(); |
|---|
| 75 | if (i+1<nbit) |
|---|
| 76 | for (int i=0; i<m*n;++i) |
|---|
| 77 | F.assign(*(B+i),*(B2+i)); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | #if DEBUG |
|---|
| 81 | Field::Element invalpha; |
|---|
| 82 | F.inv(invalpha, alpha); |
|---|
| 83 | |
|---|
| 84 | FFLAS::ftrmm (F, side, uplo, trans, diag, m, n, invalpha, A, k, B, n); |
|---|
| 85 | bool wrong = false; |
|---|
| 86 | |
|---|
| 87 | for (int i=0;i<m;++i) |
|---|
| 88 | for (int j=0;j<n;++j) |
|---|
| 89 | if ( !F.areEqual(*(B2+i*n+j), *(B+i*n+j))){ |
|---|
| 90 | cerr<<"B2 ["<<i<<", "<<j<<"] = "<<(*(B2+i*n+j)) |
|---|
| 91 | <<" ; B ["<<i<<", "<<j<<"] = "<<(*(B+i*n+j)) |
|---|
| 92 | <<endl; |
|---|
| 93 | wrong = true; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | if ( wrong ){ |
|---|
| 97 | cerr<<"FAIL"<<endl; |
|---|
| 98 | //write_field (F,cerr<<"B2="<<endl,B2,m,n,n); |
|---|
| 99 | //write_field (F,cerr<<"B="<<endl,B,m,n,n); |
|---|
| 100 | } else |
|---|
| 101 | cerr<<"PASS"<<endl; |
|---|
| 102 | #endif |
|---|
| 103 | |
|---|
| 104 | delete[] A; |
|---|
| 105 | delete[] B; |
|---|
| 106 | delete[] B2; |
|---|
| 107 | |
|---|
| 108 | #if TIME |
|---|
| 109 | double mflops = m*n/1000000.0*nbit*n/time; |
|---|
| 110 | cerr<<"m,n = "<<m<<" "<<n<<". ftrsm " |
|---|
| 111 | <<((side == FFLAS::FflasLeft)?" Left ":" Right ") |
|---|
| 112 | <<((uplo == FFLAS::FflasLower)?" Lower ":" Upper ") |
|---|
| 113 | <<((diag == FFLAS::FflasUnit)?" Unit ":" NonUnit ") |
|---|
| 114 | <<((trans == FFLAS::FflasTrans)?" Trans ":" NoTrans ") |
|---|
| 115 | <<"over Z/"<<atoi(argv[1])<<"Z :" |
|---|
| 116 | <<endl |
|---|
| 117 | <<"t= " |
|---|
| 118 | << time/nbit |
|---|
| 119 | << " s, Mffops = "<<mflops |
|---|
| 120 | << endl; |
|---|
| 121 | |
|---|
| 122 | cout<<m<<" "<<n<<" "<<mflops<<" "<<time/nbit<<endl; |
|---|
| 123 | #endif |
|---|
| 124 | } |
|---|