Debian Codegraph @

benchmarks/benchmark-charpoly-mp.C

raw
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 #define __FFLASFFPACK_FORCE_SEQ
22
23 #include "fflas-ffpack/fflas-ffpack-config.h"
24 #include <iostream>
25 #include <givaro/modular.h>
26
27 #include "fflas-ffpack/fflas-ffpack.h"
28 #include "fflas-ffpack/utils/timer.h"
29 #include "fflas-ffpack/utils/test-utils.h"
30 #include "fflas-ffpack/utils/Matio.h"
31 #include "fflas-ffpack/utils/args-parser.h"
32
33
34 using namespace std;
35
36 int main(int argc, char** argv) {
37
38 size_t iter = 1;
39 size_t n = 100;
40 std::string file = "";
41 static int variant =0;
42 uint64_t b = 150;
43 uint64_t seed = FFLAS::getSeed();
44
45 Argument as[] = {
46 { 'b', "-b B", "Set the bitsize of the random characteristic.", TYPE_INT , &b },
47 { 'n', "-n N", "Set the dimension of the matrix.", TYPE_INT , &n },
48 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
49 { 'f', "-f FILE", "Set the input file (empty for random).", TYPE_STR , &file },
50 { 'a', "-a algorithm", "Set the algorithmic variant", TYPE_INT, &variant },
51 { 's', "-s S", "Sets seed.", TYPE_INT , &seed },
52
53 END_OF_ARGUMENTS
54 };
55
56 FFLAS::parseArguments(argc,argv,as);
57 typedef Givaro::ZRing<Givaro::Integer> Field;
58 FFPACK::FFPACK_CHARPOLY_TAG CT;
59 switch (variant){
60 case 0: CT = FFPACK::FfpackAuto; break;
61 case 1: CT = FFPACK::FfpackLUK; break;
62 case 2: CT = FFPACK::FfpackDanilevski; break;
63 case 3: CT = FFPACK::FfpackArithProg; break;
64 case 4: CT = FFPACK::FfpackKG; break;
65 case 5: CT = FFPACK::FfpackKGFast; break;
66 case 6: CT = FFPACK::FfpackHybrid; break;
67 case 7: CT = FFPACK::FfpackKGFastG; break;
68 default: CT = FFPACK::FfpackAuto; break;
69 }
70 typedef Field::Element Element;
71
72 Field F;
73 FFLAS::Timer chrono;
74 double time=0.0;
75
76 Element *A;
77 uint64_t bs=1;
78 uint64_t size=b;
79 for (size_t i=0;i<iter;++i){
80
81 if (!file.empty()){
82 FFLAS::ReadMatrix (file, F, n, n, A);
83 }
84 else{
85 A = FFLAS::fflas_new<Element>(n*n);
86 // typename Field::Residu_t samplesize(1); samplesize <<= size;
87 Field::RandIter G(F,seed);
88 G.setBitsize(size);
89 for (size_t j=0; j< (size_t)n*n; ++j)
90 G.random(*(A+j));
91 }
92
93 typedef Givaro::Poly1Dom<Field> PolRing;
94 PolRing R(F);
95 PolRing::Element cpol;
96 chrono.clear();
97 chrono.start();
98 FFPACK::CharPoly (R, cpol, n, A, n, CT);
99 chrono.stop();
100
101 time+=chrono.usertime();
102
103 bs = FFLAS::bitsize (F,n,n,A,n);
104 FFLAS::fflas_delete( A);
105 }
106
107 // -----------
108 // Standard output for benchmark - Alexis Breust 2014/11/14
109 std::cout <<"Time: " << time / double(iter)
110 << " Gfops: " << (2.*double(n)/1000.*double(n)/1000.*double(n)/1000.0) / time * double(iter)
111 << " bitsize: " << bs;
112 FFLAS::writeCommandString(std::cout, as) << std::endl;
113
114 return 0;
115 }
116
117 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
118 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s