Cleans up a bit, adds options for iterations
This commit is contained in:
parent
64ceeac46c
commit
28f7497e0a
1 changed files with 23 additions and 41 deletions
|
@ -7,7 +7,7 @@
|
||||||
#include "wavelet_parallel.hpp"
|
#include "wavelet_parallel.hpp"
|
||||||
|
|
||||||
// Number of iterations to improve time measurements
|
// Number of iterations to improve time measurements
|
||||||
const unsigned int ITERS = 1;
|
static unsigned int ITERS = 1;
|
||||||
|
|
||||||
// Static :(, will be set in main
|
// Static :(, will be set in main
|
||||||
static unsigned int P;
|
static unsigned int P;
|
||||||
|
@ -101,46 +101,20 @@ static void seq_wavelet(){
|
||||||
std::copy(v.begin(), v.end(), seq_result.begin());
|
std::copy(v.begin(), v.end(), seq_result.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks whether seq and par agree
|
// square difference, used to calculate root mean squared error
|
||||||
// NOTE: modifies the global par_result
|
static double sq_diff(double x, double y){ return (x-y)*(x-y); }
|
||||||
static void check_equality(double threshold){
|
|
||||||
if(par_result == seq_result){
|
static void compare_results(std::vector<double> const & lh, std::vector<double> const & rh, double threshold){
|
||||||
std::cout << colors::green("SUCCES:") << " Results are bitwise equal" << std::endl;
|
if(lh == rh){
|
||||||
} else {
|
std::cout << colors::green("SUCCES:") << " bitwise qual" << std::endl;
|
||||||
for(unsigned int i = 0; i < N; ++i){
|
return;
|
||||||
auto sq = par_result[i] - seq_result[i];
|
|
||||||
par_result[i] = sq*sq;
|
|
||||||
}
|
|
||||||
auto rmse = std::sqrt(std::accumulate(par_result.begin(), par_result.end(), 0.0) / N);
|
|
||||||
if(rmse <= threshold){
|
|
||||||
std::cout << colors::green("SUCCES:") << " Results are almost the same: rmse = " << rmse << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cout << colors::red("FAIL:") << " Results differ: rmse = " << rmse << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks whether inverse gives us the data back
|
double rmse = std::sqrt(std::inner_product(lh.begin(), lh.end(), rh.begin(), 0.0, std::plus<double>(), &sq_diff) / lh.size());
|
||||||
// NOTE: modifies the global seq_result
|
|
||||||
static void check_inverse(double threshold){
|
|
||||||
for(unsigned int i = 0; i < ITERS; ++i){
|
|
||||||
wvlt::unwavelet(seq_result.data(), seq_result.size(), 1);
|
|
||||||
}
|
|
||||||
bool same = true;
|
|
||||||
for(unsigned int i = 0; i < N; ++i){
|
|
||||||
if(data(i) != seq_result[i]) same = false;
|
|
||||||
auto sq = data(i) - seq_result[i];
|
|
||||||
seq_result[i] = sq*sq;
|
|
||||||
}
|
|
||||||
auto rmse = std::sqrt(std::accumulate(seq_result.begin(), seq_result.end(), 0.0) / N);
|
|
||||||
if(same){
|
|
||||||
std::cout << colors::green("SUCCES:") << " Inverse is bitwise correct" << std::endl;
|
|
||||||
} else {
|
|
||||||
if(rmse <= threshold){
|
if(rmse <= threshold){
|
||||||
std::cout << colors::green("SUCCES:") << " Inverse is almost correct: rmse = " << rmse << std::endl;
|
std::cout << colors::green("SUCCES:") << " error within threshold, rmse = " << rmse << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << colors::red("FAIL:") << " Inverse seems wrong: rmse = " << rmse << std::endl;
|
std::cout << colors::red("FAIL:") << " error to big, rmse = " << rmse << std::endl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +126,9 @@ int main(int argc, char** argv){
|
||||||
opts.add_options()
|
opts.add_options()
|
||||||
("p", po::value<unsigned int>(), "number of processors")
|
("p", po::value<unsigned int>(), "number of processors")
|
||||||
("n", po::value<unsigned int>(), "number of elements")
|
("n", po::value<unsigned int>(), "number of elements")
|
||||||
|
("iterations", po::value<unsigned int>()->default_value(5), "number of iterations")
|
||||||
("help", po::value<bool>(), "show this help")
|
("help", po::value<bool>(), "show this help")
|
||||||
("check", po::value(&should_check), "enables correctness checks");
|
("check", po::value<bool>(), "enables correctness checks");
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
|
|
||||||
// Parse and set options
|
// Parse and set options
|
||||||
|
@ -169,6 +144,7 @@ int main(int argc, char** argv){
|
||||||
|
|
||||||
N = vm["n"].as<unsigned int>();
|
N = vm["n"].as<unsigned int>();
|
||||||
P = vm["p"].as<unsigned int>();
|
P = vm["p"].as<unsigned int>();
|
||||||
|
ITERS = vm["iterations"].as<unsigned int>();
|
||||||
|
|
||||||
if(!is_pow_of_two(N)) throw po::error("n is not a power of two");
|
if(!is_pow_of_two(N)) throw po::error("n is not a power of two");
|
||||||
if(!is_pow_of_two(P)) throw po::error("p is not a power of two");
|
if(!is_pow_of_two(P)) throw po::error("p is not a power of two");
|
||||||
|
@ -190,7 +166,13 @@ int main(int argc, char** argv){
|
||||||
// Checking equality of algorithms
|
// Checking equality of algorithms
|
||||||
if(vm.count("check")){
|
if(vm.count("check")){
|
||||||
double threshold = 1.0e-8;
|
double threshold = 1.0e-8;
|
||||||
check_equality(threshold);
|
std::cout << "Checking results ";
|
||||||
check_inverse(threshold);
|
compare_results(seq_result, par_result, threshold);
|
||||||
|
|
||||||
|
for(int i = 0; i < ITERS; ++i) wvlt::unwavelet(seq_result.data(), seq_result.size(), 1);
|
||||||
|
for(unsigned int i = 0; i < par_result.size(); ++i) par_result[i] = data(i);
|
||||||
|
|
||||||
|
std::cout << "Checking inverse ";
|
||||||
|
compare_results(seq_result, par_result, threshold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue