Debian Codegraph @

benchmarks/benchmark-ftrsv.C

raw
1 /* Copyright (c) FFLAS-FFPACK 2017
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 // declare that the call to openblas_set_numthread will be made here, hence don't do it
23 // everywhere in the call stack
24 #define __FFLASFFPACK_OPENBLAS_NT_ALREADY_SET 1
25
26 #include "fflas-ffpack/fflas-ffpack-config.h"
27 #include <iostream>
28 #include <givaro/modular.h>
29
30 #include "fflas-ffpack/fflas-ffpack.h"
31 #include "fflas-ffpack/utils/timer.h"
32 #include "fflas-ffpack/utils/args-parser.h"
33
34 using namespace std;
35 using namespace FFLAS;
36
37 int main(int argc, char** argv) {
38
39 #ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS
40 openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS);
41 #endif
42
43 size_t iter = 10;
44 int q = 131071;
45 size_t n = 4000;
46 bool u = true; // Upper triangular
47 bool d = false; // NonUnit diagonal
48 bool t = false; // NoTrans
49 bool v = true; // verification
50
51 Argument as[] = {
52 { 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q },
53 { 'n', "-n N", "Set the col dimension of the RHS matrix.", TYPE_INT , &n },
54 { 'u', "-u U", "Upper/Lower triangular.", TYPE_BOOL , &u },
55 { 'd', "-d D", "Unit/NonUnit diagonal.", TYPE_BOOL , &d },
56 { 't', "-t T", "Trans/NoTrans.", TYPE_BOOL , &t },
57 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
58 { 'v', "-v V", "Whether to check for correctness (probabilistic).", TYPE_BOOL , &v },
59 END_OF_ARGUMENTS
60 };
61
62 parseArguments(argc,argv,as);
63
64 FFLAS_UPLO UpLo = u? FflasUpper : FflasLower;
65 FFLAS_TRANSPOSE Trans = t? FflasTrans : FflasNoTrans;
66 FFLAS_DIAG Diag = d? FflasUnit : FflasNonUnit;
67
68 typedef Givaro::ModularBalanced<double> Field;
69 typedef Field::Element Element;
70
71 Field F(q);
72 Element * A;
73 Element * b, *c=NULL;
74
75 FFLAS::Timer chrono;
76 double time=0.0;
77 Field::RandIter G(F);
78 Field::Element proj;
79 F.init(proj);
80
81 A = fflas_new (F,n,n,Alignment::CACHE_PAGESIZE);
82
83 FFPACK::RandomTriangularMatrix (F, n, n, UpLo, Diag, true, A, n, G);
84
85 b = fflas_new(F,n,1,Alignment::CACHE_PAGESIZE);
86 for (size_t i=0;i<=iter;++i){
87 chrono.clear();
88 frand (F,G,n,1,b,1);
89 if (v){
90 c = fflas_new(F,n,1,Alignment::CACHE_PAGESIZE);
91 frand (F,G,n,1,c,1);
92 // proj <- c^T . b
93 proj = fdot (F, n, c, 1, b, 1);
94 // cerr<<"proj = "<<proj<<endl;
95 }
96 if (v){
97 // c <- c U
98 ftrmm (F, FflasRight, UpLo, Trans, Diag,
99 1,n, F.one, A, n, c, n);
100
101 }
102 chrono.start();
103 // b <- U^-1 b
104 ftrsv (F, UpLo, Trans, Diag, n, A, n, b, 1);
105 chrono.stop();
106 if (i) { time+=chrono.usertime();}
107
108 if (v){
109 // check b.c == proj
110 Element verif = fdot (F, n, c, 1, b, 1);
111 if (!F.areEqual (proj,verif)){
112 cerr<<"FAIL: proj = "<<proj<<" verif = "<<verif<<endl;
113 fflas_delete (A);
114 fflas_delete (b);
115 fflas_delete (c);
116 return -1;
117 }
118 }
119 }
120 if (v) fflas_delete(c);
121 fflas_delete (A);
122 fflas_delete (b);
123
124 std::cout << "Time: " << time / double(iter)
125 << " Gfops: " << (double(n)/1000.*double(n)/1000000.0) / time * double(iter);
126 writeCommandString(std::cout, as) << std::endl;
127
128 return 0;
129 }
130 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
131 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s