Debian Codegraph @

benchmarks/benchmark-inverse.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * Written by Clément 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 #include "fflas-ffpack/fflas-ffpack-config.h"
23 #include <iostream>
24 #include <givaro/modular.h>
25
26 #include "fflas-ffpack/fflas-ffpack.h"
27 #include "fflas-ffpack/utils/timer.h"
28 #include "fflas-ffpack/utils/fflas_io.h"
29 #include "fflas-ffpack/utils/args-parser.h"
30
31
32 using namespace std;
33
34 int main(int argc, char** argv) {
35
36 size_t iter = 3;
37 int q = 131071;
38 size_t n = 2000;
39 std::string file = "";
40
41 Argument as[] = {
42 { 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q },
43 { 'n', "-n N", "Set the dimension of the matrix.", TYPE_INT , &n },
44 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
45 { 'f', "-f FILE", "Set the input file (empty for random).", TYPE_STR , &file },
46 END_OF_ARGUMENTS
47 };
48
49 FFLAS::parseArguments(argc,argv,as);
50
51 typedef Givaro::ModularBalanced<double> Field;
52 typedef Field::Element Element;
53
54 Field F(q);
55 Field::Element * A;
56
57 FFLAS::Timer chrono;
58 double time=0.0;
59
60 for (size_t i=0;i<=iter;++i){
61 if (!file.empty()){
62 FFLAS::ReadMatrix (file.c_str(),F,n,n,A);
63 }
64 else {
65 A = FFLAS::fflas_new<Element>(n*n);
66 Field::RandIter G(F);
67 for (size_t j=0; j<(size_t)n*n; ++j)
68 G.random(*(A+j));
69 }
70
71 int nullity=0;
72 chrono.clear();
73 if (i) chrono.start();
74 FFPACK::Invert (F, n, A, n, nullity);
75 if (i) chrono.stop();
76
77 time+=chrono.usertime();
78 FFLAS::fflas_delete( A);
79 }
80
81 // -----------
82 // Standard output for benchmark - Alexis Breust 2014/11/14
83 #define CUBE(x) ((x)*(x)*(x))
84 std::cout << "Time: " << time / double(iter)
85 << " Gfops: " << 2. * CUBE(double(n)/1000.) / time * double(iter);
86 FFLAS::writeCommandString(std::cout, as) << std::endl;
87
88
89 return 0;
90 }
91
92 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
93 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s