| 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 |
//#define __FFPACK_FSYTRF_BC_RL |
| 23 |
#undef __FFPACK_FSYTRF_BC_RL |
| 24 |
#define __FFPACK_FSYTRF_BC_CROUT |
| 25 |
|
| 26 |
#define __FFLASFFPACK_OPENBLAS_NT_ALREADY_SET 1 |
| 27 |
|
| 28 |
#include "fflas-ffpack/fflas-ffpack-config.h" |
| 29 |
#include <iostream> |
| 30 |
#include <givaro/modular.h> |
| 31 |
|
| 32 |
#include "fflas-ffpack/fflas-ffpack.h" |
| 33 |
#include "fflas-ffpack/utils/timer.h" |
| 34 |
#include "fflas-ffpack/utils/fflas_io.h" |
| 35 |
#include "fflas-ffpack/utils/args-parser.h" |
| 36 |
|
| 37 |
|
| 38 |
using namespace std; |
| 39 |
|
| 40 |
int main(int argc, char** argv) { |
| 41 |
|
| 42 |
#ifdef __FFLASFFPACK_OPENBLAS_NUM_THREADS |
| 43 |
openblas_set_num_threads(__FFLASFFPACK_OPENBLAS_NUM_THREADS); |
| 44 |
#endif |
| 45 |
|
| 46 |
size_t iter = 3; |
| 47 |
int q = 131071; |
| 48 |
size_t n = 1000; |
| 49 |
size_t threshold = 64; |
| 50 |
size_t rank = 500; |
| 51 |
bool up =true; |
| 52 |
bool rpm =true; |
| 53 |
bool grp =true; |
| 54 |
bool par =false; |
| 55 |
int t=MAX_THREADS; |
| 56 |
std::string file = ""; |
| 57 |
|
| 58 |
Argument as[] = { |
| 59 |
{ 'q', "-q Q", "Set the field characteristic (-1 for random).", TYPE_INT , &q }, |
| 60 |
{ 'n', "-n N", "Set the dimension of the matrix.", TYPE_INT , &n }, |
| 61 |
{ 'u', "-u yes/no", "Computes a UTDU (true) or LDLT decomposition (false).", TYPE_BOOL , &up }, |
| 62 |
{ 'm', "-m yes/no", "Use the rank profile matrix revealing algorithm.", TYPE_BOOL , &rpm }, |
| 63 |
{ 'r', "-r R", "Set the rank (for the RPM version).", TYPE_INT , &rank }, |
| 64 |
{ 'g', "-g yes/no", "Matrix with generic rank profile (yes) or random rank profile matrix (no).", TYPE_BOOL , &grp }, |
| 65 |
{ 'i', "-i I", "Set number of repetitions.", TYPE_INT , &iter }, |
| 66 |
{ 'c', "-c C", "Set the cross-over point to the base case.", TYPE_INT , &threshold }, |
| 67 |
{ 'f', "-f FILE", "Set the input file (empty for random).", TYPE_STR , &file }, |
| 68 |
{ 'p', "-p P", "run the parallel fsytrf (only supported when RPM=N)", TYPE_BOOL , &par }, |
| 69 |
{ 't', "-t T", "number of virtual threads to drive the partition.", TYPE_INT , &t }, |
| 70 |
END_OF_ARGUMENTS |
| 71 |
}; |
| 72 |
|
| 73 |
FFLAS::parseArguments(argc,argv,as); |
| 74 |
|
| 75 |
rank=std::min(n,rank); |
| 76 |
|
| 77 |
typedef Givaro::ModularBalanced<double> Field; |
| 78 |
typedef Field::Element Element; |
| 79 |
|
| 80 |
Field F(q); |
| 81 |
Field::Element * A; |
| 82 |
FFLAS::Timer chrono; |
| 83 |
|
| 84 |
FFLAS::FFLAS_UPLO uplo = up?FFLAS::FflasUpper:FFLAS::FflasLower; |
| 85 |
double *time=new double[iter]; |
| 86 |
for (size_t i=0; i<iter; i++) time[i]=0; |
| 87 |
for (size_t i=0;i<=iter;++i){ |
| 88 |
if (!file.empty()){ |
| 89 |
FFLAS::ReadMatrix (file.c_str(),F,n,n,A); |
| 90 |
} |
| 91 |
else { |
| 92 |
A = FFLAS::fflas_new<Element>(n*n); |
| 93 |
Field::RandIter G(F); |
| 94 |
if (grp){ |
| 95 |
size_t * cols = FFLAS::fflas_new<size_t>(n); |
| 96 |
size_t * rows = FFLAS::fflas_new<size_t>(n); |
| 97 |
for (size_t i=0; i<n; ++i) |
| 98 |
cols[i] = rows[i] = i; |
| 99 |
FFPACK::RandomSymmetricMatrixWithRankandRPM (F, n, rank, A, n, rows, cols, G); |
| 100 |
FFLAS::fflas_delete(cols); |
| 101 |
FFLAS::fflas_delete(rows); |
| 102 |
} else |
| 103 |
FFPACK::RandomSymmetricMatrixWithRankandRandomRPM (F, n, rank, A, n, G); |
| 104 |
} |
| 105 |
size_t*P=FFLAS::fflas_new<size_t>(n); |
| 106 |
if (rpm){ |
| 107 |
chrono.clear(); |
| 108 |
if (i) chrono.start(); |
| 109 |
FFPACK::fsytrf_RPM (F, uplo, n, A, n, P, threshold); |
| 110 |
if (i) chrono.stop(); |
| 111 |
}else{ |
| 112 |
if (!par){ |
| 113 |
chrono.clear(); |
| 114 |
if (i) chrono.start(); |
| 115 |
FFPACK::fsytrf (F, uplo, n, A, n, threshold); |
| 116 |
if (i) chrono.stop(); |
| 117 |
}else{ |
| 118 |
chrono.clear(); |
| 119 |
if (i) chrono.start(); |
| 120 |
PAR_BLOCK{ |
| 121 |
FFPACK::fsytrf (F, uplo, n, A, n, SPLITTER(t),threshold); |
| 122 |
} |
| 123 |
if (i) chrono.stop(); |
| 124 |
} |
| 125 |
} |
| 126 |
FFLAS::fflas_delete(P); |
| 127 |
if (i) time[i-1]=chrono.realtime(); |
| 128 |
FFLAS::fflas_delete( A); |
| 129 |
} |
| 130 |
std::sort(time, time+iter); |
| 131 |
double mediantime = time[iter/2]; |
| 132 |
delete[] time; |
| 133 |
|
| 134 |
// ----------- |
| 135 |
// Standard output for benchmark - Alexis Breust 2014/11/14 |
| 136 |
#define CUBE(x) ((x)*(x)*(x)) |
| 137 |
double gfops = 1.0/3.0*CUBE(double(rank)/1000.0) +n/1000.0*n/1000.0*double(rank)/1000.0 - double(rank)/1000.0*double(rank)/1000.0*n/1000; |
| 138 |
|
| 139 |
std::cout << "Time: " << mediantime << " Gfops: " << gfops / mediantime; |
| 140 |
FFLAS::writeCommandString(std::cout, as) << std::endl; |
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 145 |
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s |