| 1 |
/* Copyright (c) FFLAS-FFPACK |
| 2 |
* Written by Clement Pernet <[email protected]> |
| 3 |
* ========LICENCE======== |
| 4 |
* This file is part of the library FFLAS-FFPACK. |
| 5 |
* |
| 6 |
* FFLAS-FFPACK is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2.1 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
* ========LICENCE======== |
| 20 |
*/ |
| 21 |
|
| 22 |
#define __FFLASFFPACK_OPENBLAS_NT_ALREADY_SET 1 |
| 23 |
|
| 24 |
#include "fflas-ffpack/fflas-ffpack-config.h" |
| 25 |
#include <iostream> |
| 26 |
#include <givaro/modular.h> |
| 27 |
#include <givaro/givpoly1.h> |
| 28 |
|
| 29 |
#include "fflas-ffpack/fflas-ffpack.h" |
| 30 |
#include "fflas-ffpack/utils/timer.h" |
| 31 |
#include "fflas-ffpack/utils/test-utils.h" |
| 32 |
#include "fflas-ffpack/utils/fflas_randommatrix.h" |
| 33 |
#include "fflas-ffpack/utils/fflas_io.h" |
| 34 |
#include "fflas-ffpack/utils/args-parser.h" |
| 35 |
|
| 36 |
|
| 37 |
using namespace std; |
| 38 |
using namespace FFLAS; |
| 39 |
using namespace FFPACK; |
| 40 |
|
| 41 |
template<class Field> |
| 42 |
void run_with_field(int q, size_t n, size_t m, size_t t, size_t r, size_t iter, uint64_t seed){ |
| 43 |
|
| 44 |
Field F(q); |
| 45 |
typedef typename Field::Element_ptr Element_ptr; |
| 46 |
|
| 47 |
FFLAS::Timer chrono; |
| 48 |
Element_ptr A, TS; |
| 49 |
|
| 50 |
double time_gen = 0, time_cbxts =0; |
| 51 |
for (size_t i=0;i<iter;++i){ |
| 52 |
|
| 53 |
A = FFLAS::fflas_new (F, n, n); |
| 54 |
size_t lda=n; |
| 55 |
TS = FFLAS::fflas_new (F, n, m); |
| 56 |
size_t ldts = m; |
| 57 |
typename Field::RandIter G (F, seed); |
| 58 |
|
| 59 |
FFPACK::RandomMatrix (F, n, n, A, n, G); |
| 60 |
Element_ptr A = fflas_new (F, n, lda); |
| 61 |
Element_ptr TS = fflas_new(F, n, ldts); |
| 62 |
|
| 63 |
RandomLTQSMatrixWithRankandQSorder (F,n,r,t,A,lda,G); |
| 64 |
RandomMatrix(F, n, m, TS, ldts, G); |
| 65 |
|
| 66 |
size_t * P = fflas_new<size_t> (n); |
| 67 |
size_t * Q = fflas_new<size_t> (n); |
| 68 |
Element_ptr L = fflas_new(F,n,n); |
| 69 |
// Element_ptr R = fflas_new(F,n,n); |
| 70 |
Element_ptr U = fflas_new(F,n,n); |
| 71 |
|
| 72 |
Element_ptr Xu = fflas_new(F, 2*t, n); |
| 73 |
size_t * Ku = fflas_new<size_t> (r+1); |
| 74 |
size_t * Mu = fflas_new<size_t> (n); |
| 75 |
size_t * Tu = fflas_new<size_t>(r); |
| 76 |
Element_ptr Xl = fflas_new(F, n, 2*t); |
| 77 |
size_t * Kl = fflas_new<size_t> (r+1); |
| 78 |
size_t * Ml = fflas_new<size_t> (n); |
| 79 |
size_t * Tl = fflas_new<size_t>(r); |
| 80 |
|
| 81 |
size_t r2; |
| 82 |
chrono.clear(); |
| 83 |
chrono.start(); |
| 84 |
r2 = LTBruhatGen (F, FflasNonUnit, n, A, lda, P, Q); |
| 85 |
// getLTBruhatGen(F, n, r, P, Q, R, n); |
| 86 |
getLTBruhatGen(F, FflasLower, FflasUnit, n, r, P, Q, A, lda, L,n); |
| 87 |
size_t NbBlocksL = CompressToBlockBiDiagonal(F, FflasLower, n, t, r, P, Q, L,n ,Xl,2*t,Kl,Ml,Tl); |
| 88 |
getLTBruhatGen(F, FflasUpper, FflasNonUnit, n, r, P, Q, A, lda, U, n); |
| 89 |
size_t NbBlocksU = CompressToBlockBiDiagonal(F, FflasUpper, n, t, r, P, Q, U,n ,Xu,n,Ku,Mu,Tu); |
| 90 |
chrono.stop(); |
| 91 |
|
| 92 |
if (r2!=r){ std::cerr<<"ERROR: r != r2"<<std::endl; exit(-1);} |
| 93 |
|
| 94 |
time_gen+=chrono.usertime(); |
| 95 |
FFLAS::fflas_delete(A,L,U); |
| 96 |
|
| 97 |
Element_ptr CBruhat = fflas_new(F, n, m); |
| 98 |
|
| 99 |
chrono.clear(); |
| 100 |
chrono.start(); |
| 101 |
productBruhatxTS(F, n, t, r, m, P, Q, Xu, n, NbBlocksU, Ku, Tu, Mu,Xl, 2*t, NbBlocksL, Kl, Tl, Ml,TS, ldts, F.zero, CBruhat, m); |
| 102 |
chrono.stop(); |
| 103 |
|
| 104 |
time_cbxts += chrono.usertime(); |
| 105 |
|
| 106 |
FFLAS::fflas_delete(TS,P,Q,Xu,Ku,Mu,Tu,Xl,Ml,Tl); |
| 107 |
} |
| 108 |
// ----------- |
| 109 |
// Standard output for benchmark - Alexis Breust 2014/11/14 |
| 110 |
std::cout << "Time: " << time_gen / double(iter) << " Gfops: Irrelevant (Generator) Time: " << time_cbxts / double(iter)<<" (CB x TS)"; |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
int main(int argc, char** argv) { |
| 115 |
|
| 116 |
#ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS |
| 117 |
openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); |
| 118 |
#endif |
| 119 |
|
| 120 |
size_t iter = 1; |
| 121 |
int q = 131071; |
| 122 |
size_t n = 2000; |
| 123 |
size_t m = 200; |
| 124 |
size_t t = 200; |
| 125 |
size_t r = 1000; |
| 126 |
uint64_t seed = FFLAS::getSeed(); |
| 127 |
|
| 128 |
Argument as[] = { |
| 129 |
{ 'q', "-q Q", "Set the field characteristic (-1 for the ring ZZ).", TYPE_INT , &q }, |
| 130 |
{ 'n', "-n N", "Set the order of the square matrix A.", TYPE_INT , &n }, |
| 131 |
{ 'm', "-m M", "Set the column dimension of n x m RHS matrix B.", TYPE_INT , &m }, |
| 132 |
{ 't', "-t T", "Set the quasiseparability order of A.", TYPE_INT , &t }, |
| 133 |
{ 'r', "-r R", "Set the rank of each upper/lower triangular part of A.", TYPE_INT , &r }, |
| 134 |
{ 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter }, |
| 135 |
{ 's', "-s S", "Sets seed.", TYPE_INT , &seed }, |
| 136 |
END_OF_ARGUMENTS |
| 137 |
}; |
| 138 |
|
| 139 |
FFLAS::parseArguments(argc,argv,as); |
| 140 |
|
| 141 |
run_with_field<Givaro::ModularBalanced<double> >(q, n, m, t, r, iter, seed); |
| 142 |
|
| 143 |
FFLAS::writeCommandString(std::cout, as) << std::endl; |
| 144 |
return 0; |
| 145 |
} |
| 146 |
|
| 147 |
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 148 |
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s |