| 1 |
/* Copyright (c) FFLAS-FFPACK |
| 2 |
* Written by Clement 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 |
//#define __FFLASFFPACK_ARITHPROG_PROFILING |
| 22 |
|
| 23 |
#define __FFLASFFPACK_OPENBLAS_NT_ALREADY_SET 1 |
| 24 |
|
| 25 |
#include "fflas-ffpack/fflas-ffpack-config.h" |
| 26 |
#include <iostream> |
| 27 |
#include <givaro/modular.h> |
| 28 |
#include <givaro/givpoly1.h> |
| 29 |
|
| 30 |
#include "fflas-ffpack/fflas-ffpack.h" |
| 31 |
#include "fflas-ffpack/utils/timer.h" |
| 32 |
#include "fflas-ffpack/utils/test-utils.h" |
| 33 |
#include "fflas-ffpack/utils/fflas_randommatrix.h" |
| 34 |
#include "fflas-ffpack/utils/fflas_io.h" |
| 35 |
#include "fflas-ffpack/utils/args-parser.h" |
| 36 |
|
| 37 |
|
| 38 |
using namespace std; |
| 39 |
using namespace FFPACK; |
| 40 |
|
| 41 |
template<class Field> |
| 42 |
void run_with_field(int q, uint64_t bits, size_t n, size_t d, size_t iter, std::string file, int variant, uint64_t seed){ |
| 43 |
Field F(q); |
| 44 |
typedef typename Field::Element Element; |
| 45 |
FFPACK::FFPACK_CHARPOLY_TAG CT; |
| 46 |
switch (variant){ |
| 47 |
case 0: CT = FfpackAuto; break; |
| 48 |
case 1: CT = FfpackDanilevski; break; |
| 49 |
case 2: CT = FfpackLUK; break; |
| 50 |
case 3: CT = FfpackArithProgKrylovPrecond; break; |
| 51 |
case 4: CT = FfpackArithProg; break; |
| 52 |
case 5: CT = FfpackKG; break; |
| 53 |
case 6: CT = FfpackKGFast; break; |
| 54 |
case 7: CT = FfpackHybrid; break; |
| 55 |
case 8: CT = FfpackKGFastG; break; |
| 56 |
default: CT = FfpackAuto; break; |
| 57 |
} |
| 58 |
FFLAS::Timer chrono; |
| 59 |
Element *A; |
| 60 |
double time_charp=0; |
| 61 |
for (size_t i=0;i<iter;++i){ |
| 62 |
if (!file.empty()){ |
| 63 |
FFLAS::ReadMatrix (file, F, n, n, A); |
| 64 |
} |
| 65 |
else{ |
| 66 |
A = FFLAS::fflas_new (F, n, n); |
| 67 |
Givaro::Integer samplesize(1); samplesize <<= bits; |
| 68 |
typename Field::RandIter G (F, seed, samplesize); |
| 69 |
FFPACK::RandomMatrix (F, n, n, A, n, G); |
| 70 |
} |
| 71 |
typename Givaro::Poly1Dom<Field>::Element cpol(n+1); |
| 72 |
typename Givaro::Poly1Dom<Field> R(F); |
| 73 |
chrono.clear(); |
| 74 |
chrono.start(); |
| 75 |
FFPACK::CharPoly (R, cpol, n, A, n, CT, d); |
| 76 |
chrono.stop(); |
| 77 |
|
| 78 |
time_charp+=chrono.usertime(); |
| 79 |
|
| 80 |
FFLAS::fflas_delete( A); |
| 81 |
} |
| 82 |
// ----------- |
| 83 |
// Standard output for benchmark - Alexis Breust 2014/11/14 |
| 84 |
std::cout << "Time: " << time_charp / double(iter) |
| 85 |
<< " Gfops: " << (2.*double(n)/1000.*double(n)/1000.*double(n)/1000.0) / time_charp * double(iter); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
int main(int argc, char** argv) { |
| 90 |
|
| 91 |
#ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS |
| 92 |
openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); |
| 93 |
#endif |
| 94 |
|
| 95 |
size_t iter = 1; |
| 96 |
int q = 131071; |
| 97 |
uint64_t bits = 10; |
| 98 |
size_t n = 1000; |
| 99 |
size_t d = __FFLASFFPACK_ARITHPROG_THRESHOLD; |
| 100 |
std::string file = ""; |
| 101 |
uint64_t seed = FFLAS::getSeed(); |
| 102 |
int variant = 0; |
| 103 |
|
| 104 |
Argument as[] = { |
| 105 |
{ 'q', "-q Q", "Set the field characteristic (-1 for the ring ZZ).", TYPE_INT , &q }, |
| 106 |
{ 'b', "-b B", "Set the bitsize of the random elements.", TYPE_INT , &bits}, |
| 107 |
{ 'n', "-n N", "Set the dimension of the matrix.", TYPE_INT , &n }, |
| 108 |
{ 'd', "-d D", "Set the degree of the preconditionner (for ArithProg variant).", TYPE_INT , &d }, |
| 109 |
{ 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter }, |
| 110 |
{ 'f', "-f FILE", "Set the input file (empty for random).", TYPE_STR , &file }, |
| 111 |
{ 'a', "-a algorithm", "Set the algorithmic variant", TYPE_INT, &variant }, |
| 112 |
{ 's', "-s S", "Sets seed.", TYPE_INT , &seed }, |
| 113 |
END_OF_ARGUMENTS |
| 114 |
}; |
| 115 |
|
| 116 |
FFLAS::parseArguments(argc,argv,as); |
| 117 |
|
| 118 |
if (q > 0){ |
| 119 |
bits = Givaro::Integer(q).bitsize(); |
| 120 |
run_with_field<Givaro::ModularBalanced<double> >(q, bits, n , d, iter, file, variant,seed); |
| 121 |
} else |
| 122 |
run_with_field<Givaro::ZRing<Givaro::Integer> > (q, bits, n , d, iter, file, variant,seed); |
| 123 |
|
| 124 |
FFLAS::writeCommandString(std::cout, as) << std::endl; |
| 125 |
return 0; |
| 126 |
} |
| 127 |
|
| 128 |
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 129 |
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s |