| 1 |
/* |
| 2 |
* Copyright (C) FFLAS-FFPACK |
| 3 |
* Written by Pascal Giorgi <[email protected]> |
| 4 |
* |
| 5 |
* This file is Free Software and part of FFLAS-FFPACK. |
| 6 |
* |
| 7 |
* ========LICENCE======== |
| 8 |
* This file is part of the library FFLAS-FFPACK. |
| 9 |
* |
| 10 |
* FFLAS-FFPACK is free software: you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU Lesser General Public |
| 12 |
* License as published by the Free Software Foundation; either |
| 13 |
* version 2.1 of the License, or (at your option) any later version. |
| 14 |
* |
| 15 |
* This library is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 |
* Lesser General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU Lesser General Public |
| 21 |
* License along with this library; if not, write to the Free Software |
| 22 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 |
* ========LICENCE======== |
| 24 |
*. |
| 25 |
*/ |
| 26 |
|
| 27 |
// declare that the call to openblas_set_numthread will be made here, hence don't do it |
| 28 |
// everywhere in the call stack |
| 29 |
#define __FFLASFFPACK_OPENBLAS_NT_ALREADY_SET 1 |
| 30 |
|
| 31 |
#include "fflas-ffpack/fflas-ffpack-config.h" |
| 32 |
#include <iostream> |
| 33 |
#include <vector> |
| 34 |
#include <string> |
| 35 |
using namespace std; |
| 36 |
|
| 37 |
#include "fflas-ffpack/utils/timer.h" |
| 38 |
#include "fflas-ffpack/fflas/fflas.h" |
| 39 |
#include "fflas-ffpack/utils/args-parser.h" |
| 40 |
#include "givaro/modular-integer.h" |
| 41 |
|
| 42 |
int main(int argc, char** argv){ |
| 43 |
|
| 44 |
#ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS |
| 45 |
openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); |
| 46 |
#endif |
| 47 |
|
| 48 |
srand((int)time(NULL)); |
| 49 |
srand48(time(NULL)); |
| 50 |
|
| 51 |
static size_t iters = 3 ; |
| 52 |
static Givaro::Integer q = -1 ; |
| 53 |
static unsigned long b = 512 ; |
| 54 |
static size_t m = 512 ; |
| 55 |
static size_t n = 512 ; |
| 56 |
static Argument as[] = { |
| 57 |
{ 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INTEGER , &q }, |
| 58 |
{ 'b', "-b B", "Set the bitsize of the random characteristic.", TYPE_INT , &b }, |
| 59 |
{ 'm', "-m M", "Set the dimension m of the matrix.", TYPE_INT , &m }, |
| 60 |
{ 'n', "-n N", "Set the dimension n of the matrix.", TYPE_INT , &n }, |
| 61 |
{ 'i', "-i R", "Set number of repetitions.", TYPE_INT , &iters }, |
| 62 |
END_OF_ARGUMENTS |
| 63 |
}; |
| 64 |
FFLAS::parseArguments(argc,argv,as); |
| 65 |
|
| 66 |
size_t seed= time(NULL); |
| 67 |
typedef Givaro::Modular<Givaro::Integer> Field; |
| 68 |
FFLAS::Timer chrono; |
| 69 |
double time=0.; |
| 70 |
Givaro::Integer p; |
| 71 |
Givaro::IntPrimeDom IPD; |
| 72 |
|
| 73 |
for (size_t i=0;i<iters;i++) { |
| 74 |
|
| 75 |
Givaro::Integer::random_exact_2exp(p, b); |
| 76 |
IPD.prevprimein(p); |
| 77 |
Field F(p); |
| 78 |
size_t lda,ldb; |
| 79 |
lda=m; |
| 80 |
ldb=n; |
| 81 |
|
| 82 |
typename Field::RandIter Rand(F,seed); |
| 83 |
Field::Element_ptr A,B; |
| 84 |
A= FFLAS::fflas_new(F,m,lda); |
| 85 |
B= FFLAS::fflas_new(F,m,ldb); |
| 86 |
|
| 87 |
for (size_t ii=0;ii<m*m;++ii) |
| 88 |
Rand.random(A[ii]); |
| 89 |
for (size_t ii=0;ii<m*n;++ii) |
| 90 |
Rand.random(B[ii]); |
| 91 |
|
| 92 |
Givaro::Integer alpha; |
| 93 |
alpha=1; |
| 94 |
|
| 95 |
chrono.clear();chrono.start(); |
| 96 |
FFLAS::ftrsm(F,FFLAS::FflasRight, FFLAS::FflasUpper,FFLAS::FflasNoTrans,FFLAS::FflasUnit, m,n,alpha,A,lda,B,ldb); |
| 97 |
chrono.stop(); |
| 98 |
time+=chrono.usertime(); |
| 99 |
|
| 100 |
FFLAS::fflas_delete(A); |
| 101 |
FFLAS::fflas_delete(B); |
| 102 |
} |
| 103 |
double Gflops=(1.*double(m)/1000.*double(m)/1000.*double(n)/1000.0) / chrono.usertime() * double(iters); |
| 104 |
Gflops*=p.bitsize()/16.; |
| 105 |
cout<<"Time: "<<time/iters<<" Gfops: "<<Gflops<<endl; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
return 0; |
| 110 |
} |
| 111 |
|
| 112 |
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 113 |
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s |