2021-02-28 09:28:42 +01:00
|
|
|
#include "hdf5/serial/H5Cpp.h"
|
2021-05-10 14:50:45 +02:00
|
|
|
#include "hdf5/serial/hdf5.h"
|
2021-02-16 10:49:15 +01:00
|
|
|
|
2021-06-04 16:50:49 +02:00
|
|
|
#include "Helpers.hpp"
|
2021-07-12 08:13:58 +02:00
|
|
|
#include "SMWB.hpp"
|
2021-05-07 17:11:04 +02:00
|
|
|
#include "SM_Maponi.hpp"
|
2021-03-05 17:00:48 +01:00
|
|
|
#include "SM_Standard.hpp"
|
2021-06-23 17:28:29 +02:00
|
|
|
#include "Woodbury.hpp"
|
2021-02-16 10:49:15 +01:00
|
|
|
|
2021-07-08 12:53:50 +02:00
|
|
|
#define PERF
|
2021-06-23 17:28:29 +02:00
|
|
|
|
|
|
|
#ifdef PERF
|
|
|
|
unsigned int repetition_number;
|
|
|
|
#endif
|
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
const H5std_string FILE_NAME("dataset.hdf5");
|
2021-02-16 10:49:15 +01:00
|
|
|
|
2021-07-29 12:01:26 +02:00
|
|
|
void read_int(H5::H5File file, std::string key, unsigned int *data) {
|
|
|
|
H5::DataSet ds = file.openDataSet(key);
|
|
|
|
ds.read(data, H5::PredType::STD_U32LE);
|
2021-02-16 10:49:15 +01:00
|
|
|
ds.close();
|
|
|
|
}
|
|
|
|
|
2021-07-29 12:01:26 +02:00
|
|
|
void read_double(H5::H5File file, std::string key, double *data) {
|
|
|
|
H5::DataSet ds = file.openDataSet(key);
|
|
|
|
ds.read(data, H5::PredType::IEEE_F64LE);
|
2021-02-16 10:49:15 +01:00
|
|
|
ds.close();
|
|
|
|
}
|
|
|
|
|
2021-07-29 12:01:26 +02:00
|
|
|
int test_cycle(H5::H5File file, int cycle, std::string version, double breakdown, double tolerance) {
|
2021-02-16 10:49:15 +01:00
|
|
|
|
|
|
|
/* Read the data */
|
|
|
|
|
|
|
|
std::string group = "cycle_" + std::to_string(cycle);
|
|
|
|
|
2021-02-24 18:41:48 +01:00
|
|
|
unsigned int dim, nupdates, col, i, j;
|
2021-07-29 12:01:26 +02:00
|
|
|
|
2021-02-16 10:49:15 +01:00
|
|
|
read_int(file, group + "/slater_matrix_dim", &dim);
|
|
|
|
read_int(file, group + "/nupdates", &nupdates);
|
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
double *slater_matrix = new double[dim * dim];
|
2021-02-16 10:49:15 +01:00
|
|
|
read_double(file, group + "/slater_matrix", slater_matrix);
|
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
double *slater_inverse = new double[dim * dim];
|
2021-02-16 10:49:15 +01:00
|
|
|
read_double(file, group + "/slater_inverse", slater_inverse);
|
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
unsigned int *col_update_index = new unsigned int[nupdates];
|
2021-02-16 10:49:15 +01:00
|
|
|
read_int(file, group + "/col_update_index", col_update_index);
|
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
double *updates = new double[nupdates * dim];
|
2021-02-16 10:49:15 +01:00
|
|
|
read_double(file, group + "/updates", updates);
|
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
double *u = new double[nupdates * dim];
|
2021-03-12 16:18:03 +01:00
|
|
|
|
2021-02-16 10:49:15 +01:00
|
|
|
/* Test */
|
2021-02-24 18:41:48 +01:00
|
|
|
|
2021-04-20 16:08:09 +02:00
|
|
|
// Transform replacement updates in 'updates[]' into additive updates in 'u[]'
|
2021-02-24 18:41:48 +01:00
|
|
|
for (j = 0; j < nupdates; j++) {
|
|
|
|
for (i = 0; i < dim; i++) {
|
|
|
|
col = col_update_index[j];
|
2021-05-10 14:50:45 +02:00
|
|
|
u[i + j * dim] =
|
|
|
|
updates[i + j * dim] - slater_matrix[i * dim + (col - 1)];
|
|
|
|
slater_matrix[i * dim + (col - 1)] = updates[i + j * dim];
|
2021-02-24 18:41:48 +01:00
|
|
|
}
|
|
|
|
}
|
2021-07-29 12:01:26 +02:00
|
|
|
delete[] updates;
|
2021-05-05 11:51:22 +02:00
|
|
|
|
2021-06-23 17:28:29 +02:00
|
|
|
#ifdef PERF
|
|
|
|
std::cout << "# of reps. = " << repetition_number << std::endl;
|
|
|
|
double *slater_inverse_nonpersistent = new double[dim * dim];
|
2021-07-29 12:01:26 +02:00
|
|
|
|
|
|
|
if (version == "sm1") {
|
|
|
|
for (unsigned int i = 0; i < repetition_number; i++) {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
SM1(slater_inverse_nonpersistent, dim, nupdates,
|
|
|
|
u, col_update_index, breakdown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (version == "wb2") {
|
|
|
|
for (unsigned int i = 0; i < repetition_number; i++) {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
WB2(slater_inverse_nonpersistent, dim,
|
|
|
|
u, col_update_index, breakdown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (version == "wb3") {
|
|
|
|
for (unsigned int i = 0; i < repetition_number; i++) {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
WB3(slater_inverse_nonpersistent, dim,
|
|
|
|
u, col_update_index, breakdown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (version == "sm2") {
|
|
|
|
for (unsigned int i = 0; i < repetition_number; i++) {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
SM2(slater_inverse_nonpersistent, dim, nupdates,
|
|
|
|
u, col_update_index, breakdown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (version == "wb2s") {
|
|
|
|
for (unsigned int i = 0; i < repetition_number; i++) {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
WB2s(slater_inverse_nonpersistent, dim, nupdates,
|
|
|
|
u, col_update_index, breakdown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (version == "wb3s") {
|
|
|
|
for (unsigned int i = 0; i < repetition_number; i++) {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
WB3s(slater_inverse_nonpersistent, dim, nupdates,
|
|
|
|
u, col_update_index, breakdown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (version == "wb32s") {
|
|
|
|
for (unsigned int i = 0; i < repetition_number; i++) {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_inverse,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
WB32s(slater_inverse_nonpersistent, dim, nupdates,
|
|
|
|
u, col_update_index, breakdown);
|
|
|
|
}
|
|
|
|
}
|
2021-06-23 17:28:29 +02:00
|
|
|
#ifdef MKL
|
2021-07-29 12:01:26 +02:00
|
|
|
else if (version == "lapack") {
|
|
|
|
memcpy(slater_inverse_nonpersistent, slater_matrix,
|
|
|
|
dim * dim * sizeof(double));
|
|
|
|
inverse(slater_inverse_nonpersistent, dim);
|
|
|
|
}
|
2021-06-23 17:28:29 +02:00
|
|
|
#endif // MKL
|
2021-07-29 12:01:26 +02:00
|
|
|
else {
|
|
|
|
std::cerr << "Unknown version " << version << std::endl;
|
|
|
|
exit(1);
|
2021-06-23 17:28:29 +02:00
|
|
|
}
|
2021-07-12 08:13:58 +02:00
|
|
|
std::memcpy(slater_inverse, slater_inverse_nonpersistent,
|
|
|
|
dim * dim * sizeof(double));
|
2021-06-23 17:28:29 +02:00
|
|
|
delete[] slater_inverse_nonpersistent;
|
|
|
|
#else
|
2021-03-15 15:59:20 +01:00
|
|
|
if (version == "maponia3") {
|
|
|
|
MaponiA3(slater_inverse, dim, nupdates, u, col_update_index);
|
2021-04-14 17:18:31 +02:00
|
|
|
} else if (version == "maponia3s") {
|
|
|
|
MaponiA3S(slater_inverse, dim, nupdates, u, col_update_index);
|
2021-03-15 15:59:20 +01:00
|
|
|
} else if (version == "sm1") {
|
|
|
|
SM1(slater_inverse, dim, nupdates, u, col_update_index);
|
|
|
|
} else if (version == "sm2") {
|
|
|
|
SM2(slater_inverse, dim, nupdates, u, col_update_index);
|
|
|
|
} else if (version == "sm3") {
|
|
|
|
SM3(slater_inverse, dim, nupdates, u, col_update_index);
|
2021-05-06 10:51:42 +02:00
|
|
|
} else if (version == "sm4") {
|
|
|
|
SM4(slater_inverse, dim, nupdates, u, col_update_index);
|
2021-06-23 17:28:29 +02:00
|
|
|
} else if (version == "wb2") {
|
|
|
|
WB2(slater_inverse, dim, u, col_update_index);
|
|
|
|
} else if (version == "wb3") {
|
|
|
|
WB3(slater_inverse, dim, u, col_update_index);
|
2021-07-29 12:01:26 +02:00
|
|
|
} else if (version == "wb2s") {
|
|
|
|
WB2s(slater_inverse, dim, nupdates, u, col_update_index);
|
|
|
|
} else if (version == "wb3s") {
|
|
|
|
WB3s(slater_inverse, dim, nupdates, u, col_update_index);
|
|
|
|
} else if (version == "wb32s") {
|
|
|
|
WB32s(slater_inverse, dim, nupdates, u, col_update_index);
|
2021-05-21 11:54:57 +02:00
|
|
|
#ifdef MKL
|
2021-05-20 19:21:59 +02:00
|
|
|
} else if (version == "lapack") {
|
|
|
|
memcpy(slater_inverse, slater_matrix, dim * dim * sizeof(double));
|
|
|
|
inverse(slater_inverse, dim);
|
2021-06-23 17:28:29 +02:00
|
|
|
#endif // MKL
|
2021-03-15 15:59:20 +01:00
|
|
|
} else {
|
|
|
|
std::cerr << "Unknown version " << version << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2021-06-23 17:28:29 +02:00
|
|
|
#endif // PERF
|
2021-07-29 12:01:26 +02:00
|
|
|
delete[] u, col_update_index;
|
2021-03-15 15:59:20 +01:00
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
double *res = new double[dim * dim]{0};
|
2021-07-30 11:51:04 +02:00
|
|
|
matMul2(slater_matrix, slater_inverse, res, dim, dim, dim);
|
2021-05-05 11:51:22 +02:00
|
|
|
bool ok = is_identity(res, dim, tolerance);
|
2021-03-18 14:05:58 +01:00
|
|
|
double res_max = residual_max(res, dim);
|
2021-05-07 17:11:04 +02:00
|
|
|
double res2 = residual_frobenius2(res, dim);
|
2021-06-23 17:28:29 +02:00
|
|
|
|
2021-05-10 14:50:45 +02:00
|
|
|
std::cout << "Residual = " << version << " " << cycle << " " << res_max << " "
|
|
|
|
<< res2 << std::endl;
|
2021-02-16 10:49:15 +01:00
|
|
|
|
2021-06-21 14:29:24 +02:00
|
|
|
#ifdef DEBUG2
|
2021-02-16 10:49:15 +01:00
|
|
|
showMatrix(res, dim, "Result");
|
|
|
|
#endif
|
|
|
|
|
2021-07-29 12:01:26 +02:00
|
|
|
delete[] res, slater_matrix, slater_inverse;
|
2021-02-16 10:49:15 +01:00
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2021-06-23 17:28:29 +02:00
|
|
|
#ifdef PERF
|
2021-07-29 12:01:26 +02:00
|
|
|
if (argc != 7) {
|
2021-07-17 11:40:59 +02:00
|
|
|
std::cerr << "Execute from within 'datasets/'" << std::endl;
|
|
|
|
std::cerr
|
2021-07-29 12:01:26 +02:00
|
|
|
<< "usage: test_h5 <version> <start cycle> <stop cycle> <break-down threshold> <tolerance> <number of reps.>"
|
2021-07-17 11:40:59 +02:00
|
|
|
<< std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2021-06-23 17:28:29 +02:00
|
|
|
#else
|
2021-07-29 12:01:26 +02:00
|
|
|
if (argc != 6) {
|
2021-02-28 09:28:42 +01:00
|
|
|
std::cerr << "Execute from within 'datasets/'" << std::endl;
|
2021-05-10 14:50:45 +02:00
|
|
|
std::cerr
|
2021-07-29 12:01:26 +02:00
|
|
|
<< "usage: test_h5 <version> <start cycle> <stop cycle> <break-down threshold> <tolerance>"
|
2021-05-10 14:50:45 +02:00
|
|
|
<< std::endl;
|
2021-02-16 10:49:15 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2021-07-17 11:40:59 +02:00
|
|
|
#endif
|
|
|
|
|
2021-03-15 15:59:20 +01:00
|
|
|
std::string version(argv[1]);
|
|
|
|
int start_cycle = std::stoi(argv[2]);
|
|
|
|
int stop_cycle = std::stoi(argv[3]);
|
2021-07-29 12:01:26 +02:00
|
|
|
double breakdown = std::stod(argv[4]);
|
|
|
|
double tolerance = std::stod(argv[5]);
|
|
|
|
H5::H5File file(FILE_NAME, H5F_ACC_RDONLY);
|
2021-02-16 10:49:15 +01:00
|
|
|
|
2021-06-23 17:28:29 +02:00
|
|
|
#ifdef PERF
|
2021-07-29 12:01:26 +02:00
|
|
|
repetition_number = std::stoi(argv[6]);
|
2021-06-23 17:28:29 +02:00
|
|
|
#endif
|
|
|
|
|
2021-02-28 09:28:42 +01:00
|
|
|
bool ok;
|
2021-05-10 14:50:45 +02:00
|
|
|
for (int cycle = start_cycle; cycle < stop_cycle + 1; cycle++) {
|
2021-07-29 12:01:26 +02:00
|
|
|
ok = test_cycle(file, cycle, version, breakdown, tolerance);
|
2021-02-28 09:28:42 +01:00
|
|
|
if (ok) {
|
2021-05-10 14:50:45 +02:00
|
|
|
std::cerr << "ok -- cycle " << std::to_string(cycle) << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cerr << "failed -- cycle " << std::to_string(cycle) << std::endl;
|
2021-02-28 09:28:42 +01:00
|
|
|
}
|
2021-02-16 10:49:15 +01:00
|
|
|
}
|
2021-02-28 09:28:42 +01:00
|
|
|
|
2021-02-16 10:49:15 +01:00
|
|
|
return ok;
|
|
|
|
}
|