我想比較在犰狳中使用spsolve()
時SuperLu的稀疏求解器的速度和使用LaPack的密度版本的速度。因此,我寫了這個程序:使用armadillo進行基準測試時SuperLu和LaPack的比較失敗
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <armadillo\armadillo>
#define SIZE 2500
#define ROUNDS 2500
int main()
{
//Time measurement stuff
LARGE_INTEGER frequency;
LARGE_INTEGER t1, t2, t3, t4;
QueryPerformanceFrequency(&frequency);
//Other stuff
arma::cx_colvec b = arma::randu<arma::cx_colvec>(SIZE);
arma::cx_colvec b1 = b, b2 = b;
arma::sp_cx_mat A = arma::sp_cx_mat(SIZE, SIZE);
A.diag(-2).fill(-1);
A.diag(-1).fill(16);
A.diag(0).fill(-30);
A.diag(1).fill(16);
A.diag(2).fill(-1);
arma::cx_colvec c = arma::zeros<arma::cx_colvec>(SIZE), d = arma::zeros<arma::cx_colvec>(SIZE);
QueryPerformanceCounter(&t1);
for (size_t i = 0; i < ROUNDS; i++)
{
if(arma::spsolve(c, A, b1, "superlu") == false)
{
std::cout << "Error in round 1\n";
break;
}
b1 = c;
}
QueryPerformanceCounter(&t2);
QueryPerformanceCounter(&t3);
for (size_t i = 0; i < ROUNDS; i++)
{
if(arma::spsolve(d, A, b2, "lapack") == false)
{
std::cout << "Error in round 2\n";
break;
}
b2 = d;
}
QueryPerformanceCounter(&t4);
std::cout << "Superlu took " << (t2.QuadPart - t1.QuadPart)*1000.0/frequency.QuadPart << '\n';
std::cout << "Lapack took " << (t4.QuadPart - t3.QuadPart)*1000.0/frequency.QuadPart << '\n';
std::cout << "Both results are equal: " << arma::approx_equal(b1, b2, "abstol", 1e-5) << '\n';
return 0;
}
現在爲SIZE
和ROUND
approx_equal
返回true,則函數值較小,但對於較大值的結果b1
和b2
不等於再根據approx_equal
。爲什麼?問題是我的超級圖書館工作不正常?