Last active
August 29, 2015 14:23
-
-
Save firegurafiku/221c3a2e94e706260308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Coompilation: | |
// g++ -I/usr/include/eigen3 -O3 -march=native -fopenmp -o test-eigen-lu test-eigen-lu.cpp | |
// | |
// Run: | |
// export OMP_NUM_THREADS=N ; time ./test-eigen-lu | |
//#include <iostream> | |
#include <Eigen/Dense> | |
#include <Eigen/Core> | |
using namespace std; | |
using namespace Eigen; | |
int main() { | |
Eigen::initParallel(); | |
MatrixXd A = MatrixXd::Random(8000, 8000); | |
VectorXd B = VectorXd::Random(8000); | |
//cout << "Here is the invertible matrix A:" << endl << A << endl; | |
//cout << "Here is the matrix B:" << endl << B << endl; | |
VectorXd X = A.lu().solve(B); | |
//cout << "Here is the (unique) solution X to the equation AX=B:" << endl << X << endl; | |
//cout << "Relative error: " << (A*X-B).norm() / B.norm() << endl; | |
} |
Run in a cycle with 8000×8000 matrices:
$ for i in {1..10} ; do
> echo "THREADS=1" ; export OMP_NUM_THREADS=1 ; command time ./test-eigen-lu
> echo "THREADS=2" ; export OMP_NUM_THREADS=2 ; command time ./test-eigen-lu
> echo "THREADS=3" ; export OMP_NUM_THREADS=3 ; command time ./test-eigen-lu
> echo "THREADS=4" ; export OMP_NUM_THREADS=4 ; command time ./test-eigen-lu
> done
(output edited manually to make it more terse)
THREADS=1: 33.41user 0.52system 0:34.11elapsed 99%CPU
THREADS=2: 38.01user 0.38system 0:21.66elapsed 177%CPU
THREADS=3: 54.56user 0.52system 0:23.14elapsed 238%CPU
THREADS=4: 67.61user 0.47system 0:22.41elapsed 303%CPU
THREADS=1: 33.43user 0.40system 0:33.89elapsed 99%CPU
THREADS=2: 41.22user 0.38system 0:23.31elapsed 178%CPU
THREADS=3: 55.22user 0.43system 0:23.61elapsed 235%CPU
THREADS=4: 67.43user 0.67system 0:22.75elapsed 299%CPU
THREADS=1: 33.57user 0.29system 0:33.92elapsed 99%CPU
THREADS=2: 40.62user 0.52system 0:23.11elapsed 178%CPU
THREADS=3: 55.07user 0.39system 0:23.58elapsed 235%CPU
THREADS=4: 67.88user 0.46system 0:22.96elapsed 297%CPU
THREADS=1: 33.45user 0.63system 0:34.32elapsed 99%CPU
THREADS=2: 39.39user 0.35system 0:22.20elapsed 179%CPU
THREADS=3: 56.28user 0.41system 0:23.80elapsed 238%CPU
THREADS=4: 67.34user 0.53system 0:22.70elapsed 298%CPU
THREADS=1: 33.55user 0.41system 0:34.07elapsed 99%CPU
THREADS=2: 40.40user 0.37system 0:23.00elapsed 177%CPU
THREADS=3: 55.33user 0.57system 0:23.90elapsed 233%CPU
THREADS=4: 68.02user 0.43system 0:23.05elapsed 296%CPU
THREADS=1: 34.39user 0.35system 0:34.81elapsed 99%CPU
THREADS=2: 41.68user 0.56system 0:23.50elapsed 179%CPU
THREADS=3: 54.78user 0.39system 0:23.39elapsed 235%CPU
THREADS=4: 67.47user 0.49system 0:22.99elapsed 295%CPU
THREADS=1: 33.57user 0.44system 0:33.99elapsed 100%CPU
THREADS=2: 42.08user 0.50system 0:23.59elapsed 180%CPU
THREADS=3: 54.63user 0.46system 0:23.40elapsed 235%CPU
THREADS=4: 67.51user 0.47system 0:22.03elapsed 308%CPU
THREADS=1: 33.38user 0.36system 0:33.88elapsed 99%CPU
THREADS=2: 40.27user 0.47system 0:22.68elapsed 179%CPU
THREADS=3: 55.34user 0.52system 0:23.67elapsed 236%CPU
THREADS=4: 66.96user 0.45system 0:22.24elapsed 303%CPU
THREADS=1: 33.44user 0.40system 0:33.90elapsed 99%CPU
THREADS=2: 40.18user 0.39system 0:22.67elapsed 178%CPU
THREADS=3: 54.46user 0.41system 0:23.31elapsed 235%CPU
THREADS=4: 67.54user 0.58system 0:22.93elapsed 297%CPU
THREADS=1: 33.40user 0.44system 0:34.01elapsed 99%CPU
THREADS=2: 42.29user 0.38system 0:23.74elapsed 179%CPU
THREADS=3: 54.81user 0.52system 0:23.59elapsed 234%CPU
THREADS=4: 66.57user 0.56system 0:22.76elapsed 294%CPU
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test results with no IO: