mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-08-25 14:41:45 +02:00
Small restructuring and cleaning up spurious includes and and namespaces.
This commit is contained in:
parent
bc1fcc1ce9
commit
ab9d13180a
@ -1,43 +1,42 @@
|
||||
// Helpers.hpp
|
||||
// SM_Helpers.hpp
|
||||
// Some usefull helper functions to support the Maponi algorithm.
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
#include <cmath>
|
||||
|
||||
template<typename T>
|
||||
void showScalar(T scalar, string name) {
|
||||
cout << name << " = " << scalar << endl << endl;
|
||||
void showScalar(T scalar, std::string name) {
|
||||
std::cout << name << " = " << scalar << std::endl << std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void showVector(T *vector, unsigned int size, string name) {
|
||||
cout << name << " = " << endl;
|
||||
void showVector(T *vector, unsigned int size, std::string name) {
|
||||
std::cout << name << " = " << std::endl;
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
cout << "[ " << vector[i] << " ]" << endl;
|
||||
std::cout << "[ " << vector[i] << " ]" << std::endl;
|
||||
}
|
||||
cout << endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void showMatrix(T *matrix, unsigned int M, string name) {
|
||||
cout.precision(17);
|
||||
cout << name << " = [" << endl;
|
||||
void showMatrix(T *matrix, unsigned int M, std::string name) {
|
||||
std::cout.precision(17);
|
||||
std::cout << name << " = [" << std::endl;
|
||||
for (unsigned int i = 0; i < M; i++) {
|
||||
cout << "[";
|
||||
std::cout << "[";
|
||||
for (unsigned int j = 0; j < M; j++) {
|
||||
if (matrix[i*M + j] >= 0) {
|
||||
cout << " " << matrix[i*M + j] << ",";
|
||||
std::cout << " " << matrix[i*M + j] << ",";
|
||||
}
|
||||
else {
|
||||
cout << " " << matrix[i*M + j] << "," ;
|
||||
std::cout << " " << matrix[i*M + j] << "," ;
|
||||
}
|
||||
}
|
||||
cout << " ]," << endl;
|
||||
std::cout << " ]," << std::endl;
|
||||
}
|
||||
cout << "]" << endl;
|
||||
cout << endl;
|
||||
std::cout << "]" << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
@ -43,7 +43,7 @@ case $ENV in
|
||||
;;
|
||||
*)
|
||||
echo "Unknown environment descriptor given."
|
||||
echo "Usage: source smvars.sh {intel | llvm | gnu}"
|
||||
echo "Usage: source smvars.sh {intel | llvm | vfc | gnu}"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
@ -2,9 +2,17 @@
|
||||
// Algorithm 3 from P. Maponi,
|
||||
// p. 283, doi:10.1016/j.laa.2006.07.007
|
||||
#include "SM_MaponiA3.hpp"
|
||||
#include "Helpers.hpp"
|
||||
#include "SM_Helpers.hpp"
|
||||
|
||||
void selectBestUpdate(unsigned int l, unsigned int N_updates,
|
||||
// #define DEBUG
|
||||
|
||||
void Switch(unsigned int *p, unsigned int l, unsigned int lbar) {
|
||||
unsigned int tmp = p[l+1];
|
||||
p[l+1] = p[lbar];
|
||||
p[lbar] = tmp;
|
||||
}
|
||||
|
||||
void selectLargestDenominator(unsigned int l, unsigned int N_updates,
|
||||
unsigned int *Updates_index, unsigned int *p,
|
||||
double ***ylk) {
|
||||
unsigned int lbar = l+1, max =0;
|
||||
@ -16,18 +24,16 @@ void selectBestUpdate(unsigned int l, unsigned int N_updates,
|
||||
component = Updates_index[index - 1];
|
||||
breakdown = abs(1 + ylk[l][index][component]);
|
||||
#ifdef DEBUG
|
||||
cout << "Inside selectBestUpdate()" << endl;
|
||||
cout << "breakdown = abs(1 + ylk[" << l << "][" << index << "][" << component << "]) = " << breakdown << endl;
|
||||
cout << endl;
|
||||
std::cout << "Inside selectLargestDenominator()" << std::endl;
|
||||
std::cout << "breakdown = abs(1 + ylk[" << l << "][" << index << "][" << component << "]) = " << breakdown << std::endl;
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
if (breakdown > max) {
|
||||
max = breakdown;
|
||||
lbar = j;
|
||||
}
|
||||
}
|
||||
tmp = p[l+1];
|
||||
p[l+1] = p[lbar];
|
||||
p[lbar] = tmp;
|
||||
Switch(p, l, lbar);
|
||||
}
|
||||
|
||||
void MaponiA3(double *Slater_inv, unsigned int Dim,
|
||||
@ -68,9 +74,9 @@ void MaponiA3(double *Slater_inv, unsigned int Dim,
|
||||
// Calculate the {y_{0,k}}
|
||||
for (k = 1; k < N_updates + 1; k++) {
|
||||
#ifdef DEBUG
|
||||
cout << "Compute y0k: " << endl;
|
||||
cout << "ylk[0][" << k << "][:]";
|
||||
cout << endl;
|
||||
std::cout << "Compute y0k: " << std::endl;
|
||||
std::cout << "ylk[0][" << k << "][:]";
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
for (i = 1; i < Dim + 1; i++) {
|
||||
for (j = 1; j < Dim + 1; j++) {
|
||||
@ -86,33 +92,33 @@ void MaponiA3(double *Slater_inv, unsigned int Dim,
|
||||
// Calculate the {y_{l,k}} from the {y_{0,k}}
|
||||
for (l = 0; l < N_updates; l++) {
|
||||
#ifdef DEBUG
|
||||
cout << "In outer compute-ylk-loop: l = " << l << endl;
|
||||
cout << endl;
|
||||
std::cout << "In outer compute-ylk-loop: l = " << l << std::endl;
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
|
||||
// For given l select intermediate update with largest break-down val
|
||||
selectBestUpdate(l, N_updates, Updates_index, p, ylk);
|
||||
selectLargestDenominator(l, N_updates, Updates_index, p, ylk);
|
||||
|
||||
// Select component and comp. bd-condition.
|
||||
component = Updates_index[p[l+1] - 1];
|
||||
beta = 1 + ylk[l][p[l+1]][component];
|
||||
#ifdef DEBUG
|
||||
cout << "p[l+1] = " << p[l+1] << endl;
|
||||
cout << "component = " << component << endl;
|
||||
cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "] = " << beta << endl;
|
||||
cout << endl;
|
||||
std::cout << "p[l+1] = " << p[l+1] << std::endl;
|
||||
std::cout << "component = " << component << std::endl;
|
||||
std::cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "] = " << beta << std::endl;
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
if (fabs(beta) < 1e-3) {
|
||||
cerr << "Break-down occured." << endl;
|
||||
std::cerr << "Break-down occured." << std::endl;
|
||||
}
|
||||
|
||||
// Compute intermediate update to Slater_inv
|
||||
#ifdef DEBUG
|
||||
cout << "Compute intermediate update to Slater_inv" << endl;
|
||||
cout << "component = " << component << endl;
|
||||
cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "]" << endl;
|
||||
cout << "ylk[l][p[k]][:] = ylk[" << l << "][" << p[l+1] << "][:]" << endl;
|
||||
cout << endl;
|
||||
std::cout << "Compute intermediate update to Slater_inv" << std::endl;
|
||||
std::cout << "component = " << component << std::endl;
|
||||
std::cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "]" << std::endl;
|
||||
std::cout << "ylk[l][p[k]][:] = ylk[" << l << "][" << p[l+1] << "][:]" << std::endl;
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
for (i = 0; i < Dim; i++) {
|
||||
for (j = 0; j < Dim; j++) {
|
||||
@ -132,9 +138,9 @@ void MaponiA3(double *Slater_inv, unsigned int Dim,
|
||||
for (k = l+2; k < N_updates+1; k++) {
|
||||
alpha = ylk[l][p[k]][component] / beta;
|
||||
#ifdef DEBUG
|
||||
cout << "Inside k-loop: k = " << k << endl;
|
||||
cout << "ylk[" << l+1 << "][" << p[k] << "][:]" << endl;
|
||||
cout << endl;
|
||||
std::cout << "Inside k-loop: k = " << k << std::endl;
|
||||
std::cout << "ylk[" << l+1 << "][" << p[k] << "][:]" << std::endl;
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
for (i = 1; i < Dim + 1; i++) {
|
||||
ylk[l+1][p[k]][i] = ylk[l][p[k]][i]
|
||||
|
@ -1,8 +1,7 @@
|
||||
// SM-Standard.cpp
|
||||
// Standard Sherman Morrison with multiple updates
|
||||
#include "SM_Standard.hpp"
|
||||
#include "Helpers.hpp"
|
||||
#include <iostream>
|
||||
#include "SM_Helpers.hpp"
|
||||
|
||||
// Set common break-down threshold
|
||||
double threshold() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// main.cpp
|
||||
#include "SM_MaponiA3.hpp"
|
||||
#include "Helpers.hpp"
|
||||
#include "SM_Helpers.hpp"
|
||||
|
||||
int main() {
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "hdf5/serial/hdf5.h"
|
||||
#include "hdf5/serial/H5Cpp.h"
|
||||
|
||||
#include "SM_MaponiA3.hpp"
|
||||
#include "SM_Standard.hpp"
|
||||
#include "Helpers.hpp"
|
||||
#include "SM_Helpers.hpp"
|
||||
|
||||
using namespace H5;
|
||||
// #define DEBUG
|
||||
|
Loading…
Reference in New Issue
Block a user