Debian Codegraph @

benchmarks/benchmark-fdot.C

raw
1 /* Copyright (c) FFLAS-FFPACK
2 * Written by Philippe LEDENT <[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 #include <givaro/givrational.h>
30
31 #include "fflas-ffpack/fflas-ffpack.h"
32 #include "fflas-ffpack/utils/timer.h"
33 #include "fflas-ffpack/utils/test-utils.h"
34 #include "fflas-ffpack/utils/fflas_io.h"
35 #include "fflas-ffpack/paladin/parallel.h"
36 #include "fflas-ffpack/paladin/fflas_plevel1.h"
37 #include "fflas-ffpack/utils/args-parser.h"
38
39
40 using namespace std;
41 using namespace FFLAS;
42 using namespace FFPACK;
43
44 template<class Field>
45 typename Field::Element run_with_field(int q, size_t iter, size_t N, const uint64_t BS, const size_t p, const size_t threads, uint64_t seed){
46 Field F(q);
47 Givaro::Integer samplesize(1); samplesize <<= BS;
48 typename Field::RandIter G(F, seed, samplesize);
49
50 typename Field::Element_ptr A, B;
51 typename Field::Element d; F.init(d);
52
53 #ifdef __GIVARO_USE_OPENMP
54 Givaro::OMPTimer chrono, time;
55 #else
56 Givaro::Timer chrono, time;
57 #endif
58 time.clear();
59
60 for (size_t i=0;i<iter;++i){
61 A = fflas_new(F, N);
62 B = fflas_new(F, N);
63
64 PAR_BLOCK { pfrand(F, G, N, 1, A); pfrand(F, G, N, 1, B); }
65
66 // FFLAS::WriteMatrix(std::cerr, F, 1, N, A, 1);
67 // FFLAS::WriteMatrix(std::cerr, F, 1, N, B, 1);
68
69 F.assign(d, F.zero);
70
71
72 FFLAS::ParSeqHelper::Parallel<
73 FFLAS::CuttingStrategy::Block,
74 FFLAS::StrategyParameter::Threads> ParHelper(threads);
75
76 chrono.clear();
77 if (p){
78 chrono.start();
79 F.assign(d, fdot(F, N, A, 1U, B, 1U, ParHelper));
80 chrono.stop();
81 } else {
82 chrono.start();
83 F.assign(d, fdot(F, N, A, 1U, B, 1U, FFLAS::ParSeqHelper::Sequential()));
84 chrono.stop();
85 }
86
87
88 // std::cerr << chrono
89 // << " Gfops: " << ((double(2*N)/1000.)/1000.)/(1000.*chrono.realtime())
90 // << std::endl;
91
92 time+=chrono;
93 FFLAS::fflas_delete(A);
94 FFLAS::fflas_delete(B);
95 }
96 // -----------
97 // Standard output for benchmark
98 std::cout << "Time: " << time.realtime()/iter
99 << " Gfops: " << ((double(2*N)/1000.)/1000.)/(1000.*time.realtime())* double(iter);
100
101 // F.write(std::cerr, d) << std::endl;
102 return d;
103 }
104
105 int main(int argc, char** argv) {
106
107 #ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS
108 openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS);
109 #endif
110
111 size_t iter = 20; // to get nonzero time
112 size_t N = 5000;
113 uint64_t BS = 5000;
114 int q = 131071101;
115 size_t p =0;
116 size_t maxallowed_threads; PAR_BLOCK { maxallowed_threads=NUM_THREADS; }
117 size_t threads=maxallowed_threads;
118 uint64_t seed = FFLAS::getSeed();
119
120 Argument as[] = {
121 { 'n', "-n N", "Set the dimension of the matrix C.",TYPE_INT , &N },
122 { 'q', "-q Q", "Set the field characteristic (0 for the integers).", TYPE_INT , &q },
123 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
124 { 'b', "-b B", "Set the bitsize of the random elements.", TYPE_INT , &BS},
125 { 'p', "-p P", "0 for sequential, 1 for parallel.", TYPE_INT , &p },
126 { 't', "-t T", "number of virtual threads to drive the partition.", TYPE_INT , &threads },
127 { 's', "-s S", "Sets seed.", TYPE_INT , &seed },
128 END_OF_ARGUMENTS
129 };
130
131 FFLAS::parseArguments(argc,argv,as);
132
133 if (q > 0){
134 BS = Givaro::Integer(q).bitsize();
135 double d = run_with_field<Givaro::ModularBalanced<double> >(q, iter, N, BS, p, threads, seed);
136 std::cout << " d: " << d;
137 } else {
138 auto d = run_with_field<Givaro::ZRing<Givaro::Integer> > (q, iter, N, BS, p, threads, seed);
139 std::cout << " size: " << logtwo(d>0?d:-d);
140 }
141
142 FFLAS::writeCommandString(std::cout, as) << std::endl;
143 return 0;
144 }
145 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
146 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s