ergo
random_matrices.h
Go to the documentation of this file.
1 /* Ergo, version 3.8, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
41 #ifndef HEADER_RANDOM_MATRICES
42 #define HEADER_RANDOM_MATRICES
43 
44 
45 #include "matrix_typedefs.h" // definitions of matrix types and interval type (source)
46 #include "realtype.h" // definitions of types (utilities_basic)
47 #include "matrix_utilities.h"
49 #include "SizesAndBlocks.h"
50 #include "Matrix.h"
51 #include "Vector.h"
52 #include "MatrixSymmetric.h"
53 #include "MatrixTriangular.h"
54 #include "MatrixGeneral.h"
55 #include "VectorGeneral.h"
56 #include "output.h"
57 
58 #include "files_dense.h"
59 #include "files_sparse.h"
60 
61 #include <iostream>
62 #include <fstream>
63 #include <sstream>
64 #include <string.h>
65 
66 
67 using namespace std;
68 
69 
70 
75 
76 typedef std::vector<int> VectorTypeInt;
77 
78 #ifdef PRECISION_QUAD_FLT128
79 #define MAX_DOUBLE FLT128_MAX
80 #define MIN_DOUBLE FLT128_MIN
81 #else
82 #define MAX_DOUBLE std::numeric_limits<ergo_real>::max()
83 #define MIN_DOUBLE std::numeric_limits<ergo_real>::min()
84 #endif
85 
86 
87 #define PI 3.14159265 // needed for sprandsym
88 
89 
90 void print_ergo_matrix(const MatrixTypeInner &F);
91 void print_matrix(std::vector<ergo_real> const &A);
92 template<typename Matrix>
93 void init_matrix(Matrix &X, const int N, int blockSizesMultuple = 4);
94 void get_random_symm_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple = 4);
95 void get_random_sparse_blocks_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple = 4, ergo_real probabilityBeingZero = 0);
96 void get_all_eigenvalues_of_matrix(std::vector<ergo_real> & eigvalList, const MatrixTypeInner & M);
97 void sprandsym(int N, MatrixTypeInner &X, MatrixGeneral &Q, vector<ergo_real> &D, const double MATRIX_SPARSITY);
98 int get_matrix_from_sparse(char *filename, MatrixTypeInner &X);
99 int get_matrix_from_sparse_vec(char *filename, std::vector<int> &I, std::vector<int> &J, std::vector<ergo_real> &val);
100 int get_matrix_from_binary(char *filename, MatrixTypeInner &X);
101 int get_matrix_from_binary_vec(char *filename, std::vector<int> &I, std::vector<int> &J, std::vector<ergo_real> &val, int &N);
102 int get_matrix_from_full(char * filename, MatrixTypeInner &X);
103 
104 
110 template<typename Matrix>
111 void init_matrix(Matrix &X, const int N, int blockSizesMultuple /*=4*/)
112 {
113  /********** Initialization of SizesAndBlocks */
114  int size = N;
115  int nlevels = 5;
116  std::vector<int> blockSizes(nlevels);
117  blockSizes[nlevels - 1] = 1; // should always be one
118  for (int ind = nlevels - 2; ind >= 0; ind--)
119  blockSizes[ind] = blockSizes[ind + 1] * blockSizesMultuple;
120  mat::SizesAndBlocks rows(blockSizes, size);
121  mat::SizesAndBlocks cols(blockSizes, size);
122  /********************************************/
123  X.resetSizesAndBlocks(rows,cols);
124 }
125 
126 
127 #endif // HEADER_RANDOM_MATRICES
get_all_eigenvalues_of_matrix
void get_all_eigenvalues_of_matrix(std::vector< ergo_real > &eigvalList, const MatrixTypeInner &M)
Definition: random_matrices.cc:105
files_sparse.h
File containing declarations of functions for reading/writing sparse matrices from/to mtx (MatrixMark...
integral_matrix_wrappers.h
Wrapper routines for different parts of the integral code, including conversion of matrices from/to t...
MatrixTriangular.h
realtype.h
Definition of the main floating-point datatype used; the ergo_real type.
get_matrix_from_sparse_vec
int get_matrix_from_sparse_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< ergo_real > &val)
Definition: random_matrices.cc:421
Vector.h
mat::read_matrix
static void read_matrix(Tmatrix &A, char const *const matrixPath, int const size)
Definition: general.h:115
get_all_eigenvalues_of_matrix
void get_all_eigenvalues_of_matrix(std::vector< ergo_real > &eigvalList, const MatrixTypeInner &M)
Definition: random_matrices.cc:105
get_matrix_from_sparse_vec
int get_matrix_from_sparse_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< ergo_real > &val)
Definition: random_matrices.cc:421
get_matrix_from_full
int get_matrix_from_full(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:480
MatrixTypeInner
symmMatrix MatrixTypeInner
Definition: random_matrices.h:72
ergo_real
double ergo_real
Definition: realtype.h:69
template_blas_cos
Treal template_blas_cos(Treal x)
IntervalType
intervalType IntervalType
Definition: random_matrices.h:71
read_matrix_from_mtx
int read_matrix_from_mtx(const char *filename, std::vector< int > &I, vector< int > &J, vector< real > &val, int &N, int &M)
Definition: files_sparse.cc:48
symmMatrix
MatrixSymmetric< real, matri > symmMatrix
Definition: test_LanczosSeveralLargestEig.cc:69
Matrix.h
init_matrix
void init_matrix(Matrix &X, const int N, int blockSizesMultuple=4)
Create hierarchical matrix structure.
Definition: random_matrices.h:111
get_matrix_from_binary
int get_matrix_from_binary(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:437
rows
mat::SizesAndBlocks rows
Definition: test.cc:51
print_ergo_matrix
void print_ergo_matrix(const MatrixTypeInner &F)
Definition: random_matrices.cc:45
sprandsym
void sprandsym(int N, MatrixTypeInner &X, MatrixGeneral &Q, vector< ergo_real > &D, const double MATRIX_SPARSITY)
Definition: random_matrices.cc:129
normalMatrix
MatrixGeneral< real, matri > normalMatrix
Definition: test_LanczosSeveralLargestEig.cc:71
triangMatrix
MatrixTriangular< real, matri > triangMatrix
Definition: test_LanczosSeveralLargestEig.cc:70
PI
#define PI
Definition: random_matrices.h:87
get_matrix_from_sparse
int get_matrix_from_sparse(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:405
print_ergo_matrix
void print_ergo_matrix(const MatrixTypeInner &F)
Definition: random_matrices.cc:45
get_random_sparse_blocks_matrix
void get_random_sparse_blocks_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple=4, ergo_real probabilityBeingZero=0)
Definition: random_matrices.cc:95
get_matrix_from_binary_vec
int get_matrix_from_binary_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< ergo_real > &val, int &N)
Definition: random_matrices.cc:456
get_matrix_from_full
int get_matrix_from_full(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:480
get_random_symm_matrix
void get_random_symm_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple=4)
Definition: random_matrices.cc:65
VectorTypeInt
std::vector< int > VectorTypeInt
Definition: random_matrices.h:76
matrix_utilities.h
Utilities related to the hierarchical matrix library (HML), including functions for setting up permut...
print_matrix
void print_matrix(std::vector< ergo_real > const &A)
Definition: random_matrices.cc:52
template_blas_sin
Treal template_blas_sin(Treal x)
cols
mat::SizesAndBlocks cols
Definition: test.cc:52
random_matrices.h
Header file containing declarations of functions required for testing purposes. Functions include gen...
A
#define A
matrix_typedefs.h
Header file with typedefs for matrix and vector types. The levels of hierarchic matrices are defined ...
mat::Interval< ergo_real >
get_matrix_from_binary
int get_matrix_from_binary(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:437
get_random_sparse_blocks_matrix
void get_random_sparse_blocks_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple, ergo_real probabilityBeingZero)
Definition: random_matrices.cc:95
print_matrix
void print_matrix(std::vector< ergo_real > const &A)
Definition: random_matrices.cc:52
get_matrix_from_binary_vec
int get_matrix_from_binary_vec(char *filename, std::vector< int > &I, std::vector< int > &J, std::vector< ergo_real > &val, int &N)
Definition: random_matrices.cc:456
get_random_symm_matrix
void get_random_symm_matrix(int N, MatrixTypeInner &X, int blockSizesMultuple)
Definition: random_matrices.cc:65
mat::SizesAndBlocks
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:45
SizesAndBlocks.h
Class used to keep track of the block sizes used at different levels in the hierarchical matrix data ...
TriangMatrixType
triangMatrix TriangMatrixType
Definition: random_matrices.h:73
mat::syev
static void syev(const char *jobz, const char *uplo, const int *n, T *a, const int *lda, T *w, T *work, const int *lwork, int *info)
Definition: mat_gblas.h:382
sprandsym
void sprandsym(int N, MatrixTypeInner &X, MatrixGeneral &Q, vector< ergo_real > &D, const double MATRIX_SPARSITY)
Definition: random_matrices.cc:129
get_matrix_from_sparse
int get_matrix_from_sparse(char *filename, MatrixTypeInner &X)
Definition: random_matrices.cc:405
MatrixSymmetric.h
files_dense.h
File containing declaration of functions for reading/writing dense matrices and vectors.
MatrixGeneral.h
VectorGeneral.h
output.h
Functionality for writing output messages to a text file.
MatrixGeneral
normalMatrix MatrixGeneral
Definition: random_matrices.h:74