Debian Codegraph @

benchmarks/benchmark-ftrtri.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * Written by Clément Pernet <[email protected]> and Philippe Ledent
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 // declare that the call to openblas_set_numthread will be made here, hence don't do it
32 // everywhere in the call stack
33 #define __FFLASFFPACK_OPENBLAS_NT_ALREADY_SET 1
34
35 using namespace std;
36
37 int main(int argc, char** argv) {
38
39
40 #ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS
41 openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS);
42 #endif
43
44 size_t iter = 3;
45 int q = 131071;
46 size_t n = 2000;
47 size_t t = 0;
48 std::string file = "";
49
50 Argument as[] = {
51 { 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q },
52 { 'n', "-n N", "Set the dimension of the matrix.", TYPE_INT , &n },
53 { 't', "-t T", "Set the base case threshold.", TYPE_INT , &t },
54 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
55 { 'f', "-f FILE", "Set the input file (empty for random).", TYPE_STR , &file },
56 END_OF_ARGUMENTS
57 };
58
59 FFLAS::parseArguments(argc,argv,as);
60
61 typedef Givaro::ModularBalanced<double> Field;
62 typedef Field::Element Element;
63
64 Field F(q);
65 Field::Element * A, *B;
66
67 FFLAS::Timer chrono;
68 double time=0.0;
69
70 A = FFLAS::fflas_new<Element>(n*n);
71 B = FFLAS::fflas_new<Element>(n*n);
72 FFPACK::RandomTriangularMatrix (F, n, n, FFLAS::FflasUpper,FFLAS::FflasNonUnit,true,B,n);
73
74 for (size_t i=0;i<=iter;++i){
75 if (!file.empty()){
76 FFLAS::ReadMatrix (file.c_str(),F,n,n,A);
77 }
78 else {
79 FFLAS::fassign(F,n,n,B,n,A,n);
80 }
81 chrono.clear();
82 if (i) chrono.start();
83 if (t)
84 FFPACK::ftrtri(F, FFLAS::FflasUpper, FFLAS::FflasNonUnit, n, A, n, t);
85 else
86 FFPACK::ftrtri(F, FFLAS::FflasUpper, FFLAS::FflasNonUnit, n, A, n);
87 if (i) chrono.stop();
88
89 time+=chrono.realtime();
90 }
91 FFLAS::fflas_delete (A);
92 FFLAS::fflas_delete (B);
93
94 // -----------
95 // Standard output for benchmark - Alexis Breust 2014/11/14
96 #define CUBE(x) ((x)*(x)*(x))
97 std::cout << "Time: " << time / double(iter)
98 << " Gfops: " << CUBE(double(n)/1000.)/(3*time) * double(iter);
99 FFLAS::writeCommandString(std::cout, as) << std::endl;
100
101
102 return 0;
103 }
104
105 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
106 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s