#include <complex>
#include <array>
#include <vector>
#include <iomanip>
#include <iostream>
#include <string>
template <typename nt_t>
void bench(
const std::string filename) {
std::cout << "# Librsb initialized with " << rnt << " threads." << std::endl;
if(mhis.size())
std::cout << "# detected custom memory hierarchy info: " << mhis << std::endl;
const bool is_cpx = false;
const long long nnz_ops = ( is_sym ? 2 : 1 ) * ( mtx._is_complex() ? 8 : 2 );
const rsb_real_t mtxocc = mtx._get_storage_bytes();
const std::string mtxname {filename.begin()+(filename.find_last_of("/\\")?filename.find_last_of("/\\")+1:0),filename.begin()+filename.rfind(".mtx")};
std::cout << "# Read matrix " << std::quoted(mtxname) << " : " << mtx._info() << std::endl << "#" << std::endl;
std::cout << "# Matrix file " << std::quoted(filename) << " read in " << dt << " s " << std::endl;
std::cout << "# Matrix occupies " << mtxocc << " bytes " << std::endl;
const rsb_real_t opocc =
sizeof(nt_t)*nrhs*(mtx.cols()+mtx.rows());
std::cout << "#" << std::endl << "# Operands occupy " << opocc << " bytes now ( with " << nrhs << " nrhs )" << std::endl;
#if defined(RSB_LIBRSB_VER_DATE) && (RSB_LIBRSB_VER_DATE)
#endif
} )
{
const std::vector<nt_t> B(nrhs*mtx.cols(),1.);
std::vector<nt_t> C(nrhs*mtx.rows(),0.);
const nt_t alpha { 1.}, beta { 1.};
const std::string tag { std::string() + mtx.rsbtype() + ':' + std::to_string(nrhs) + '-' + oc + ':' + mtxname };
dt = std::numeric_limits<decltype(dt)>::max();
do {
mtx.spmm(transA,&alpha,nrhs,order,B.data(),ldB,&beta,C.data(),ldC);
++its;
}
while ( its < minits || (
rsb_time()-t0 < mindt && its < maxits) );
const auto flops_u = (nnz_ops*nnzA*nrhs) / dt;
std::cout << "# rsb_spmm-" << nrhs << "-" << oc << " took " << dt << " s, for " << nnzA/dt << " nnz/s, " << flops_u << " flops/s on " << its << " samples\n";
std::cout << tag << "\t" << flops_u << std::endl;
}
}
std::cout << "# Done." << std::endl;
}
auto main(
const int argc,
char * argv[]) ->
int {
const std::string filename{ argc > 1 ? argv[1] : "../A.mtx"};
std::cout << "MTX"<< "\t" << "FLOPS" << std::endl;
#ifdef RSB_NUMERICAL_TYPE_FLOAT
bench<float>(filename);
#endif
#ifdef RSB_NUMERICAL_TYPE_DOUBLE
bench<double>(filename);
#endif
#ifdef RSB_NUMERICAL_TYPE_FLOAT_COMPLEX
bench<std::complex<float>>(filename);
#endif
#ifdef RSB_NUMERICAL_TYPE_DOUBLE_COMPLEX
bench<std::complex<double>>(filename);
#endif
}