StatMech
Loading...
Searching...
No Matches
ObjectOnGPU_EigenMatrix_test.cu File Reference

Classes

class  MagmaController
 
class  Dummy
 

Functions

template<typename RealScalar >
double MeanLevelSpasingsRatio (Eigen::VectorX< RealScalar > const &eigvecs)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
54 {
55 if(argc != 3) {
56 std::cerr << "Usage: 1.(This) 2.(rows) 3.(cols)\n"
57 << " argc=" << argc << std::endl;
58 std::exit(EXIT_FAILURE);
59 }
60 int const rows = std::atoi(argv[1]);
61 int const cols = std::atoi(argv[2]);
62
63 std::mt19937 mt;
64 std::normal_distribution<double> Gaussian;
65
67 cuCHECK(cudaDeviceSetLimit(cudaLimitMallocHeapSize, size_t(16) * size_t(1024 * 1024 * 1024)));
68
69 // Testing Default constructor
70 {
72 // std::cout << dMat << std::endl;
73 std::cout << "Passed the test point 1.\n" << std::endl;
74 }
75 {
76 Dummy dummy(rows, cols);
77 std::cout << "Passed the test point 3.\n" << std::endl;
78 }
79
80 // Testing constructor from CPU matrix and Copy & Move constructors
81 {
83 Eigen::MatrixX<Scalar> hMat = Eigen::MatrixX<Scalar>::NullaryExpr(
84 rows, cols, [&]() { return Complex_t<double>(Gaussian(mt), Gaussian(mt)); });
86 // ObjectOnGPU< Eigen::MatrixX<Scalar> > dMat2(dMat1); // Shoule give a compile-time error
87 ObjectOnGPU< Eigen::MatrixX<Scalar> > dMat2(std::move(dMat1));
88 std::cout << "Passed the test point 4 (Move).\n" << std::endl;
89 }
90
91 // Testing EigenSolver< ObjectOnGPU<Eigen::MatrixX<...>> >
92 {
94 Eigen::MatrixX<Scalar> hMat = Eigen::MatrixX<Scalar>::NullaryExpr(
95 rows, cols, [&]() { return Complex_t<double>(Gaussian(mt), Gaussian(mt)); });
97
98 MatrixUtils::EigenSolver< decltype(dMat) > eigsolver(std::move(dMat));
99 std::cout << "Level spasings ratio = " << MeanLevelSpasingsRatio(eigsolver.eigenvalues())
100 << std::endl;
101 std::cout << "Passed the test point 5.\n" << std::endl;
102 }
103
104 {
106 Eigen::MatrixX<Scalar> hMat = Eigen::MatrixX<Scalar>::NullaryExpr(
107 rows, cols, [&]() { return Complex_t<double>(Gaussian(mt), Gaussian(mt)); });
108 hMat = (hMat + hMat.adjoint().eval()) / 2.0;
110
111 hMat = Eigen::MatrixX<Scalar>::NullaryExpr(
112 rows, cols, [&]() { return Complex_t<double>(Gaussian(mt), Gaussian(mt)); });
113 hMat = (hMat + hMat.adjoint().eval()) / 2.0;
115
116 std::cout << dMat1 << std::endl;
117 std::cout << dMat2 << std::endl;
118 std::cout << "After multiplication\n" << dMat1 * dMat2 << std::endl;
119 std::cout << "Passed the test point 5.\n" << std::endl;
120 }
121
122 return EXIT_SUCCESS;
123}
double MeanLevelSpasingsRatio(Eigen::VectorX< RealScalar > const &eigvecs)
Definition ObjectOnGPU_EigenMatrix_test.cu:37
Definition mytypes.hpp:147
Definition ObjectOnGPU_EigenMatrix_test.cu:28
static MagmaController & getInstance()
Definition ObjectOnGPU_EigenMatrix_test.cu:14
Definition MatrixUtils.hpp:20
Definition ObjectOnGPU.cuh:149
cuCHECK(cudaFuncGetAttributes(&attr, MatrixElementsInSector))
__constant__ int cols
Definition testEigenOnGPU.cu:6
__constant__ int rows
Definition testEigenOnGPU.cu:5

◆ MeanLevelSpasingsRatio()

template<typename RealScalar >
double MeanLevelSpasingsRatio ( Eigen::VectorX< RealScalar > const &  eigvecs)
37 {
38 if(eigvecs.size() <= 2) {
39 std::cout << "Error: "
40 << "eigvecs.size() = " << eigvecs.size() << "should be larger than 2."
41 << std::endl;
42 std::exit(EXIT_FAILURE);
43 }
44 double res = 0;
45 for(auto j = 1; j < eigvecs.size() - 1; ++j) {
46 double temp1 = eigvecs[j] - eigvecs[j - 1];
47 double temp2 = eigvecs[j + 1] - eigvecs[j];
48 res += (temp1 < temp2 ? temp1 / temp2 : temp2 / temp1);
49 }
50 res /= (eigvecs.size() - 2);
51 return res;
52}