Debian Codegraph @

benchmarks/benchmark-fadd-lvl2.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
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
36 using namespace std;
37 using namespace FFLAS;
38 using namespace FFPACK;
39 int main(int argc, char** argv) {
40
41 #ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS
42 openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS);
43 #endif
44
45 size_t iter = 3;
46 int q = 131071;
47 size_t rows = 5000;
48 size_t cols = 5000;
49 double a = 1.0;
50 // size_t threshold = 64;
51 std::string file = "";
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 matrix C.", TYPE_INT , &rows },
56 { 'n', "-n N", "Set the column dimension of the matrix C.", TYPE_INT , &cols },
57 { 'a', "-a A", "Set the value of the coefficient alpha for alpha * B.", TYPE_DOUBLE , &a},
58 { 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter },
59 END_OF_ARGUMENTS
60 };
61
62 FFLAS::parseArguments(argc,argv,as);
63
64 // typedef Givaro::Modular<double> Field;
65 // typedef Givaro::Modular<float> Field;
66 // typedef Givaro::ZRing<int64_t> Field;
67 // typedef Givaro::ZRing<float> Field;
68 // typedef Givaro::ZRing<double> Field;
69 typedef Givaro::Modular<int64_t> Field;
70
71 typedef Field::Element Element;
72
73 Field F(q);
74 Field::Element_ptr A, B;
75 Field::Element_ptr C;
76 Element alpha;
77 F.init(alpha, a);
78
79
80 FFLAS::Timer chrono;
81 double *time=new double[iter];
82
83 A = fflas_new(F, rows, cols);
84 size_t lda = cols;
85 B = fflas_new(F, rows, cols);
86 size_t ldb = cols;
87 C = fflas_new(F, rows, cols);
88 size_t ldc = cols;
89 Field::RandIter G(F);
90 RandomMatrix (F, rows, cols, A, lda, G);
91 RandomMatrix (F, rows, cols, B, ldb, G);
92
93 for (size_t i=0;i<=iter;++i){
94 chrono.clear();
95 if (i) chrono.start();
96 fadd(F, rows, cols, A, lda, alpha, B, ldb, C, ldc);
97 if (i) {chrono.stop(); time[i-1] = chrono.usertime();}
98 }
99 FFLAS::fflas_delete(A);
100 FFLAS::fflas_delete(B);
101 FFLAS::fflas_delete(C);
102 std::sort(time, time+iter);
103 double mediantime = time[iter/2];
104 delete[] time;
105
106 // -----------
107 // Standard output for benchmark - Alexis Breust 2014/11/14
108 std::cout << "Time: " << mediantime
109 << " Gfops: " << ((double(rows)/1000)*(double(cols)/1000))/(1000*mediantime); //(n^2/1000^3)/time * iter
110 FFLAS::writeCommandString(std::cout, as) << std::endl;
111 return 0;
112 }
113 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
114 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s