| 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 |
// For the moment, please manually uncomment these defines when your BLAS provide these symbols (waiting to autodect them in a near future) |
| 23 |
// #define __FFLASFFPACK_HAVE_LAPACK2_DSYTRF |
| 24 |
// #define __FFLASFFPACK_HAVE_LAPACK2_DSYTRF_AA |
| 25 |
// #define __FFLASFFPACK_HAVE_LAPACK2_DSYTRF_ROOK |
| 26 |
// #define __FFLASFFPACK_HAVE_LAPACK2_DSYTRF_RK |
| 27 |
|
| 28 |
#include "fflas-ffpack/fflas-ffpack-config.h" |
| 29 |
|
| 30 |
#include <iostream> |
| 31 |
#include <vector> |
| 32 |
#include <givaro/modular.h> |
| 33 |
|
| 34 |
#include "fflas-ffpack/fflas-ffpack.h" |
| 35 |
#include "fflas-ffpack/utils/timer.h" |
| 36 |
#include "fflas-ffpack/utils/fflas_io.h" |
| 37 |
#include "fflas-ffpack/utils/args-parser.h" |
| 38 |
|
| 39 |
|
| 40 |
using namespace std; |
| 41 |
|
| 42 |
#ifdef __FFLASFFPACK_USE_OPENMP |
| 43 |
typedef FFLAS::OMPTimer TTimer; |
| 44 |
#else |
| 45 |
typedef FFLAS::Timer TTimer; |
| 46 |
#endif |
| 47 |
|
| 48 |
#define EFFGFF(n,t,i) ( (double(n)/1000.*double(n)/1000.*double(n)/1000.0) / double(t) * double(i) / 3.) |
| 49 |
|
| 50 |
int main(int argc, char** argv) { |
| 51 |
|
| 52 |
size_t iter = 3; |
| 53 |
int q = 1009; |
| 54 |
int algo = 1; |
| 55 |
size_t n = 2000; |
| 56 |
std::string file = ""; |
| 57 |
|
| 58 |
size_t NBK = MAX_THREADS; |
| 59 |
|
| 60 |
Argument as[] = { |
| 61 |
{ 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q }, |
| 62 |
{ 'n', "-n N", "Set the dimension of the matrix.", TYPE_INT , &n }, |
| 63 |
{ 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iter }, |
| 64 |
{ 'f', "-f FILE", "Set the input file (empty for random).", TYPE_STR , &file }, |
| 65 |
{ 'a', "-a Algorithm", "Set the algorithm (0 for default, 1 for Aasen, 2 for rook, 3 for rk.", TYPE_INT , &algo }, |
| 66 |
END_OF_ARGUMENTS |
| 67 |
}; |
| 68 |
|
| 69 |
FFLAS::parseArguments(argc,argv,as); |
| 70 |
|
| 71 |
typedef Givaro::Modular<double> Field; |
| 72 |
typedef Field::Element Element; |
| 73 |
|
| 74 |
Field F(q); |
| 75 |
Field::Element * A; |
| 76 |
|
| 77 |
TTimer chrono; |
| 78 |
double *time=new double[iter]; |
| 79 |
|
| 80 |
std::vector<int> Piv(n,0); |
| 81 |
std::vector<double> Diag(n,0.0); |
| 82 |
for (size_t it=0;it <= iter;++it){ |
| 83 |
if (!file.empty()){ |
| 84 |
FFLAS::ReadMatrix (file.c_str(),F,n,n,A); |
| 85 |
} |
| 86 |
else { |
| 87 |
A = FFLAS::fflas_new<Element>(n*n); |
| 88 |
Field::RandIter G(F); |
| 89 |
PAR_BLOCK{ FFLAS::pfrand(F,G,n,n,A,n/NBK); } |
| 90 |
} |
| 91 |
|
| 92 |
chrono.clear(); |
| 93 |
switch(algo) { |
| 94 |
case 0: |
| 95 |
if (it) chrono.start(); |
| 96 |
#ifdef __FFLASFFPACK_HAVE_LAPACK2_DSYTRF |
| 97 |
LAPACKE_dsytrf(101,'U',n,A,n,&Piv[0]); |
| 98 |
#endif |
| 99 |
if (it) chrono.stop(); |
| 100 |
break; |
| 101 |
case 1: |
| 102 |
if (it) chrono.start(); |
| 103 |
#ifdef __FFLASFFPACK_HAVE_LAPACK2_DSYTRF_AA |
| 104 |
LAPACKE_dsytrf_aa(101,'U',n,A,n,&Piv[0]); |
| 105 |
#endif |
| 106 |
if (it) chrono.stop(); |
| 107 |
break; |
| 108 |
case 2: |
| 109 |
if (it) chrono.start(); |
| 110 |
#ifdef __FFLASFFPACK_HAVE_LAPACK2_DSYTRF_ROOK |
| 111 |
LAPACKE_dsytrf_rook(101,'U',n,A,n,&Piv[0]); |
| 112 |
#endif |
| 113 |
if (it) chrono.stop(); |
| 114 |
break; |
| 115 |
default: |
| 116 |
if (it) chrono.start(); |
| 117 |
#ifdef __FFLASFFPACK_HAVE_LAPACK2_DSYTRF_RK |
| 118 |
LAPACKE_dsytrf_rk(101,'U',n,A,n,&Diag[0],&Piv[0]); |
| 119 |
#endif |
| 120 |
if (it) chrono.stop(); |
| 121 |
} |
| 122 |
if (it) time[it-1] = chrono.realtime(); |
| 123 |
FFLAS::fflas_delete( A); |
| 124 |
} |
| 125 |
|
| 126 |
std::sort(time, time+iter); |
| 127 |
double mediantime = time[iter/2]; |
| 128 |
delete[] time; |
| 129 |
|
| 130 |
double gfops = EFFGFF(n,mediantime,1); |
| 131 |
if (mediantime<0.001){mediantime=0; gfops=0;} |
| 132 |
std::cout << "Time: " << mediantime |
| 133 |
<< " Gfops: " << gfops; |
| 134 |
FFLAS::writeCommandString(std::cout, as) << std::endl; |
| 135 |
|
| 136 |
return 0; |
| 137 |
} |
| 138 |
|
| 139 |
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 140 |
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s |