Debian Codegraph @

benchmarks/benchmark-ftrsm.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 = 1009;
45 size_t m = 2000 ;
46 size_t n = 2000;
47 std::string file1 = "";
48 std::string file2 = "";
49 int t=MAX_THREADS;
50 int NBK = -1;
51 int p = 0; // 0 for sequential 1 for pIter-sRec ; 2 for pRec; 3 for hybrid
52
53 Argument as[] = {
54 { 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q },
55 { 'm', "-m M", "Set the row dimension of the RHS matrix.", TYPE_INT , &m },
56 { 'n', "-n N", "Set the col dimension of the RHS matrix.", TYPE_INT , &n },
57 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
58 { 'f', "-f FILE", "Set the first input file (empty for random).", TYPE_STR, &file1 },
59 { 'g', "-g FILE", "Set the second input file (empty for random).", TYPE_STR, &file2 },
60 { 't', "-t T", "number of virtual threads to drive the partition.", TYPE_INT, &t },
61 { 'b', "-b B", "number of numa blocks per dimension for the numa placement", TYPE_INT, &NBK },
62 { 'p', "-p P", "0 for sequential, 1 for Iterative, 2 for Recursive, 3 for Hybrid.", TYPE_INT , &p },
63 END_OF_ARGUMENTS
64 };
65
66 FFLAS::parseArguments(argc,argv,as);
67 if (NBK==-1) NBK = t;
68
69 typedef Givaro::ModularBalanced<double> Field;
70 typedef Field::Element Element;
71
72 Field F(q);
73 Element * A;
74 Element * B;
75
76 FFLAS::Timer chrono;
77 double time=0.0;
78 Field::RandIter G(F);
79
80 if (!file1.empty()){
81 FFLAS::ReadMatrix (file1.c_str(),F,m,m,A);
82 }
83 else{
84 A = FFLAS::fflas_new (F,m,m,Alignment::CACHE_PAGESIZE);
85 PAR_BLOCK{ FFLAS::pfrand(F,G,m,m,A,m/NBK); }
86
87 for (size_t k=0;k<(size_t)m;++k)
88 while (F.isZero( G.random(*(A+k*(m+1)))));
89 }
90
91 if (!file2.empty()){
92 FFLAS::ReadMatrix (file2.c_str(),F,m,n,B);
93 }
94 else{
95 B = FFLAS::fflas_new(F,m,n,Alignment::CACHE_PAGESIZE);
96 PAR_BLOCK{ FFLAS::pfrand(F,G,m,n,B,m/NBK); }
97 }
98 //}
99
100 for (size_t i=0;i<=iter;++i){
101 chrono.clear();
102 if (i) chrono.start();
103
104 if (!p){
105 FFLAS::ParSeqHelper::Sequential H;
106 FFLAS::ftrsm (F, FFLAS::FflasLeft, FFLAS::FflasLower,
107 FFLAS::FflasNoTrans, FFLAS::FflasNonUnit,
108 m,n, F.one, A, m, B, n, H);
109 }
110 else{
111 FFLAS::ParSeqHelper::Parallel<FFLAS::CuttingStrategy::Block,FFLAS::StrategyParameter::Threads> PSH(t);
112 PAR_BLOCK{
113 switch (p) {
114 case 1: {
115 FFLAS::TRSMHelper<FFLAS::StructureHelper::Iterative,
116 FFLAS::ParSeqHelper::Parallel<FFLAS::CuttingStrategy::Block,FFLAS::StrategyParameter::Threads> >
117 PH (PSH);
118 FFLAS::ftrsm (F, FFLAS::FflasLeft, FFLAS::FflasLower,
119 FFLAS::FflasNoTrans, FFLAS::FflasNonUnit,
120 m,n, F.one, A, m, B, n, PH);
121 break;}
122 case 2: {FFLAS::TRSMHelper<FFLAS::StructureHelper::Recursive,
123 FFLAS::ParSeqHelper::Parallel<FFLAS::CuttingStrategy::Block,FFLAS::StrategyParameter::Threads> >
124 PH (PSH);
125 FFLAS::ftrsm (F, FFLAS::FflasLeft, FFLAS::FflasLower,
126 FFLAS::FflasNoTrans, FFLAS::FflasNonUnit,
127 m,n, F.one, A, m, B, n, PH);
128 break;}
129 case 3:
130 FFLAS::TRSMHelper<FFLAS::StructureHelper::Hybrid, FFLAS::ParSeqHelper::Parallel<FFLAS::CuttingStrategy::Block,FFLAS::StrategyParameter::Threads> >
131 PH (PSH);
132 FFLAS::ftrsm (F, FFLAS::FflasLeft, FFLAS::FflasLower,
133 FFLAS::FflasNoTrans, FFLAS::FflasNonUnit,
134 m,n, F.one, A, m, B, n, PH);
135 break;
136 }
137
138 }
139 }
140 if (i) {chrono.stop(); time+=chrono.realtime();}
141 }
142
143 FFLAS::fflas_delete( A);
144 FFLAS::fflas_delete( B);
145
146 // -----------
147 // Standard output for benchmark - Alexis Breust 2014/11/14
148 std::cout << "Time: " << time / double(iter)
149 << " Gfops: " << (double(m)/1000.*double(m)/1000.*double(n)/1000.0) / time * double(iter);
150 FFLAS::writeCommandString(std::cout, as) << std::endl;
151
152 return 0;
153 }
154 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
155 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s