Debian Codegraph @

benchmarks/benchmark-fgesv.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 // 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/fflas_io.h"
33 #include "fflas-ffpack/utils/args-parser.h"
34
35 using namespace std;
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 = 3;
44 int q = 131071;
45 size_t m = 2000 ;
46 size_t n = 1000;
47 std::string file1 = "";
48 std::string file2 = "";
49 bool v=false;
50
51 Argument as[] = {
52 { 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q },
53 { 'm', "-m M", "Set the row dimension of the RHS matrix.", TYPE_INT , &m },
54 { 'n', "-n N", "Set the col dimension of the RHS matrix.", TYPE_INT , &n },
55 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
56 { 'f', "-f FILE", "Set the first input file (empty for random).", TYPE_STR, &file1 },
57 { 'g', "-g FILE", "Set the second input file (empty for random).", TYPE_STR, &file2 },
58 { 'v', "-v V", "Whether to run the verification of the solution.", TYPE_BOOL, &v },
59 END_OF_ARGUMENTS
60 };
61
62 FFLAS::parseArguments(argc,argv,as);
63
64 typedef Givaro::ModularBalanced<double> Field;
65
66 Field F(q);
67 Field::Element_ptr A, Ac, B, Bc;
68
69 FFLAS::Timer chrono;
70 double time=0.0;
71 Field::RandIter G(F);
72
73 if (!file1.empty()){
74 FFLAS::ReadMatrix (file1.c_str(),F,m,m,A);
75 }
76 else{
77 A = FFLAS::fflas_new (F,m,m,Alignment::CACHE_PAGESIZE);
78 FFPACK::RandomMatrixWithRank (F, m,m, m, A, m);
79 }
80
81 if (!file2.empty()){
82 FFLAS::ReadMatrix (file2.c_str(),F,m,n,B);
83 }
84 else{
85 B = FFLAS::fflas_new(F,m,n,Alignment::CACHE_PAGESIZE);
86 FFPACK::RandomMatrix(F, m, n, B, n, G);
87 }
88
89 Bc = FFLAS::fflas_new(F,m,n);
90 Ac = FFLAS::fflas_new (F,m,m,Alignment::CACHE_PAGESIZE);
91
92 for (size_t i=0;i<=iter;++i){
93 FFLAS::fassign (F,m,m,A,m,Ac,m);
94 FFLAS::fassign (F,m,n,B,n,Bc,n);
95 int info;
96 chrono.clear();
97 if (i) chrono.start();
98 FFPACK::fgesv (F, FFLAS::FflasLeft, m,n, Ac, m, Bc, n, &info);
99 if (i) {chrono.stop(); time+=chrono.realtime();}
100 }
101
102 // -----------
103 // Standard output for benchmark
104 std::cout << "Time: " << time / double(iter)
105 << " Gfops: " << (double(m*m)/1000000.*(2*double(m)/3000.+2*double(n)/1000.0)) / time * double(iter);
106 FFLAS::writeCommandString(std::cout, as) << std::endl;
107
108 if (v){
109 FFLAS::fgemm(F,FFLAS::FflasNoTrans,FFLAS::FflasNoTrans,m,n,m,F.one,A,m,Bc,n,F.mOne,B,n);
110 if (!FFLAS::fiszero(F,m,n,B,n)){
111 std::cerr<<"Verification FAILED"<<std::endl;
112 // FFLAS::WriteMatrix(std::cerr<<"A= "<<std::endl,F,m,m,A,m);
113 // FFLAS::WriteMatrix(std::cerr<<"X= "<<std::endl,F,m,n,Bc,n);
114 // FFLAS::WriteMatrix(std::cerr<<"B= "<<std::endl,F,m,n,B,n);
115 FFLAS::fflas_delete( A);
116 FFLAS::fflas_delete( B);
117 return -1;
118 }
119 }
120 FFLAS::fflas_delete( A);
121 FFLAS::fflas_delete( B);
122
123
124 return 0;
125 }
126 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
127 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s