Debian Codegraph @

benchmarks/benchmark-dtrsm.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 #ifdef __FFLASFFPACK_USE_OPENMP
32 typedef FFLAS::OMPTimer TTimer;
33 #else
34 typedef FFLAS::Timer TTimer;
35 #endif
36
37
38 using namespace std;
39
40 int main(int argc, char** argv) {
41
42 size_t iter = 1;
43 int q = 1009;
44 size_t n = 2000;
45 std::string file1 = "";
46 std::string file2 = "";
47
48 Argument as[] = {
49 { 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q },
50 { 'n', "-n N", "Set the dimension of the matrix.", TYPE_INT , &n },
51 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
52 { 'f', "-f FILE", "Set the first input file (empty for random).", TYPE_STR , &file1 },
53 { 'g', "-g FILE", "Set the second input file (empty for random).", TYPE_STR , &file2 },
54 END_OF_ARGUMENTS
55 };
56
57 FFLAS::parseArguments(argc,argv,as);
58
59 typedef Givaro::Modular<double> Field;
60 typedef Field::Element Element;
61
62 Field F(q);
63 Element * A;
64 Element * B;
65
66 TTimer chrono;
67 double time=0.0;
68
69 for (size_t i=0;i<iter;++i){
70 Field::RandIter G(F);
71 if (!file1.empty()){
72 FFLAS::ReadMatrix (file1.c_str(),F,n,n,A);
73 }
74 else{
75 A = FFLAS::fflas_new<Element>(n*n);
76 for (size_t j = 0; j< (size_t)n*n; ++j)
77 G.random(*(A+j));
78 }
79
80 if (!file2.empty()){
81 FFLAS::ReadMatrix (file2.c_str(),F,n,n,B);
82 }
83 else{
84 B = FFLAS::fflas_new<Element>(n*n);
85 for (size_t j=0 ; j< (size_t)n*n; ++j)
86 G.random(*(A+j));
87 }
88
89 for (size_t k=0;k<(size_t)n;++k)
90 while (F.isZero( G.random(*(A+k*(n+1)))));
91
92 chrono.clear();
93 chrono.start();
94 cblas_dtrsm (CblasRowMajor, CblasLeft, CblasLower, CblasNoTrans,
95 CblasNonUnit, n,n, F.one, A, n, B, n);
96
97 chrono.stop();
98 time+=chrono.usertime();
99 FFLAS::fflas_delete( A);
100 FFLAS::fflas_delete( B);
101
102 }
103
104 // -----------
105 // Standard output for benchmark - Alexis Breust 2014/11/14
106 std::cout << "Time: " << time / double(iter)
107 << " Gfops: " << (2.*double(n)/1000.*double(n)/1000.*double(n)/1000.0) / time * double(iter) / 3.;
108 FFLAS::writeCommandString(std::cout, as) << std::endl;
109
110 return 0;
111 }
112 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
113 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s