mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-08-25 14:41:45 +02:00
commit
7399010a42
5
Makefile
5
Makefile
@ -28,7 +28,7 @@ FLIBS = -lstdc++
|
|||||||
|
|
||||||
## Includes and dependencies
|
## Includes and dependencies
|
||||||
INCLUDE = -I $(INC_DIR)/
|
INCLUDE = -I $(INC_DIR)/
|
||||||
DEPS_CXX = $(OBJ_DIR)/SM_MaponiA3.o $(OBJ_DIR)/SM_Standard.o
|
DEPS_CXX = $(OBJ_DIR)/SM_MaponiA3.o $(OBJ_DIR)/SM_Standard.o $(OBJ_DIR)/SM_Helpers.o
|
||||||
DEPS_F = $(DEPS_CXX) $(OBJ_DIR)/SM_MaponiA3_mod.o $(OBJ_DIR)/Helpers_mod.o
|
DEPS_F = $(DEPS_CXX) $(OBJ_DIR)/SM_MaponiA3_mod.o $(OBJ_DIR)/Helpers_mod.o
|
||||||
|
|
||||||
## Directory structure
|
## Directory structure
|
||||||
@ -66,6 +66,9 @@ $(BIN_DIR) $(OBJ_DIR):
|
|||||||
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||||
$(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $<
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||||
|
$(CXX) $(CXXFLAGS) -fPIE $(INCLUDE) -c -o $@ $<
|
||||||
|
|
||||||
## HDF5/C++ objects
|
## HDF5/C++ objects
|
||||||
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||||
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $<
|
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $<
|
||||||
|
@ -9,7 +9,7 @@ CXXFLAGS = -O0 -g $(H5FLAGS)
|
|||||||
FFLAGS = -O0 -g $(H5FLAGS)
|
FFLAGS = -O0 -g $(H5FLAGS)
|
||||||
|
|
||||||
INCLUDE = -I $(INC_DIR)/
|
INCLUDE = -I $(INC_DIR)/
|
||||||
DEPS_CXX = $(OBJ_DIR)/SM_MaponiA3.o $(OBJ_DIR)/SM_Standard.o
|
DEPS_CXX = $(OBJ_DIR)/SM_MaponiA3.o $(OBJ_DIR)/SM_Standard.o $(OBJ_DIR)/SM_Helpers.o
|
||||||
DEPS_F = $(DEPS_CXX) $(OBJ_DIR)/SM_MaponiA3_mod.o $(OBJ_DIR)/Helpers_mod.o
|
DEPS_F = $(DEPS_CXX) $(OBJ_DIR)/SM_MaponiA3_mod.o $(OBJ_DIR)/Helpers_mod.o
|
||||||
FLIBS = -lstdc++
|
FLIBS = -lstdc++
|
||||||
|
|
||||||
@ -49,6 +49,9 @@ $(BIN_DIR) $(OBJ_DIR):
|
|||||||
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||||
$(CXX) $(CXXFLAGS) $(ARCH) $(INCLUDE) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) $(ARCH) $(INCLUDE) -c -o $@ $<
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||||
|
$(CXX) $(CXXFLAGS) -fPIE $(INCLUDE) -c -o $@ $<
|
||||||
|
|
||||||
## HDF5/C++ objects
|
## HDF5/C++ objects
|
||||||
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
|
||||||
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $<
|
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $<
|
||||||
|
@ -1,43 +1,48 @@
|
|||||||
// Helpers.hpp
|
// SM_Helpers.hpp
|
||||||
// Some usefull helper functions to support the Maponi algorithm.
|
// Some usefull helper functions to support the Maponi algorithm.
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
using namespace std;
|
#include <cmath>
|
||||||
|
|
||||||
|
void Switch(unsigned int *p, unsigned int l, unsigned int lbar);
|
||||||
|
|
||||||
|
void selectLargestDenominator(unsigned int l, unsigned int N_updates,
|
||||||
|
unsigned int *Updates_index, unsigned int *p,
|
||||||
|
double ***ylk);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void showScalar(T scalar, string name) {
|
void showScalar(T scalar, std::string name) {
|
||||||
cout << name << " = " << scalar << endl << endl;
|
std::cout << name << " = " << scalar << std::endl << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void showVector(T *vector, unsigned int size, string name) {
|
void showVector(T *vector, unsigned int size, std::string name) {
|
||||||
cout << name << " = " << endl;
|
std::cout << name << " = " << std::endl;
|
||||||
for (unsigned int i = 0; i < size; i++) {
|
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>
|
template<typename T>
|
||||||
void showMatrix(T *matrix, unsigned int M, string name) {
|
void showMatrix(T *matrix, unsigned int M, std::string name) {
|
||||||
cout.precision(17);
|
std::cout.precision(17);
|
||||||
cout << name << " = [" << endl;
|
std::cout << name << " = [" << std::endl;
|
||||||
for (unsigned int i = 0; i < M; i++) {
|
for (unsigned int i = 0; i < M; i++) {
|
||||||
cout << "[";
|
std::cout << "[";
|
||||||
for (unsigned int j = 0; j < M; j++) {
|
for (unsigned int j = 0; j < M; j++) {
|
||||||
if (matrix[i*M + j] >= 0) {
|
if (matrix[i*M + j] >= 0) {
|
||||||
cout << " " << matrix[i*M + j] << ",";
|
std::cout << " " << matrix[i*M + j] << ",";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cout << " " << matrix[i*M + j] << "," ;
|
std::cout << " " << matrix[i*M + j] << "," ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout << " ]," << endl;
|
std::cout << " ]," << std::endl;
|
||||||
}
|
}
|
||||||
cout << "]" << endl;
|
std::cout << "]" << std::endl;
|
||||||
cout << endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
@ -43,7 +43,7 @@ case $ENV in
|
|||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown environment descriptor given."
|
echo "Unknown environment descriptor given."
|
||||||
echo "Usage: source smvars.sh {intel | llvm | gnu}"
|
echo "Usage: source smvars.sh {intel | llvm | vfc | gnu}"
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
31
src/SM_Helpers.cpp
Normal file
31
src/SM_Helpers.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "SM_Helpers.hpp"
|
||||||
|
|
||||||
|
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;
|
||||||
|
unsigned int index = 0, component = 0;
|
||||||
|
unsigned int tmp = 0;
|
||||||
|
double breakdown = 0;
|
||||||
|
for (unsigned int j = lbar; j < N_updates + 1; j++) {
|
||||||
|
index = p[j];
|
||||||
|
component = Updates_index[index - 1];
|
||||||
|
breakdown = abs(1 + ylk[l][index][component]);
|
||||||
|
#ifdef DEBUG
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Switch(p, l, lbar);
|
||||||
|
}
|
@ -2,33 +2,9 @@
|
|||||||
// Algorithm 3 from P. Maponi,
|
// Algorithm 3 from P. Maponi,
|
||||||
// p. 283, doi:10.1016/j.laa.2006.07.007
|
// p. 283, doi:10.1016/j.laa.2006.07.007
|
||||||
#include "SM_MaponiA3.hpp"
|
#include "SM_MaponiA3.hpp"
|
||||||
#include "Helpers.hpp"
|
#include "SM_Helpers.hpp"
|
||||||
|
|
||||||
void selectBestUpdate(unsigned int l, unsigned int N_updates,
|
// #define DEBUG
|
||||||
unsigned int *Updates_index, unsigned int *p,
|
|
||||||
double ***ylk) {
|
|
||||||
unsigned int lbar = l+1, max =0;
|
|
||||||
unsigned int index = 0, component = 0;
|
|
||||||
unsigned int tmp = 0;
|
|
||||||
double breakdown = 0;
|
|
||||||
for (unsigned int j = lbar; j < N_updates + 1; j++) {
|
|
||||||
index = p[j];
|
|
||||||
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;
|
|
||||||
#endif
|
|
||||||
if (breakdown > max) {
|
|
||||||
max = breakdown;
|
|
||||||
lbar = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tmp = p[l+1];
|
|
||||||
p[l+1] = p[lbar];
|
|
||||||
p[lbar] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MaponiA3(double *Slater_inv, unsigned int Dim,
|
void MaponiA3(double *Slater_inv, unsigned int Dim,
|
||||||
unsigned int N_updates, double *Updates,
|
unsigned int N_updates, double *Updates,
|
||||||
@ -68,9 +44,9 @@ void MaponiA3(double *Slater_inv, unsigned int Dim,
|
|||||||
// Calculate the {y_{0,k}}
|
// Calculate the {y_{0,k}}
|
||||||
for (k = 1; k < N_updates + 1; k++) {
|
for (k = 1; k < N_updates + 1; k++) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Compute y0k: " << endl;
|
std::cout << "Compute y0k: " << std::endl;
|
||||||
cout << "ylk[0][" << k << "][:]";
|
std::cout << "ylk[0][" << k << "][:]";
|
||||||
cout << endl;
|
std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
for (i = 1; i < Dim + 1; i++) {
|
for (i = 1; i < Dim + 1; i++) {
|
||||||
for (j = 1; j < Dim + 1; j++) {
|
for (j = 1; j < Dim + 1; j++) {
|
||||||
@ -86,33 +62,33 @@ void MaponiA3(double *Slater_inv, unsigned int Dim,
|
|||||||
// Calculate the {y_{l,k}} from the {y_{0,k}}
|
// Calculate the {y_{l,k}} from the {y_{0,k}}
|
||||||
for (l = 0; l < N_updates; l++) {
|
for (l = 0; l < N_updates; l++) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "In outer compute-ylk-loop: l = " << l << endl;
|
std::cout << "In outer compute-ylk-loop: l = " << l << std::endl;
|
||||||
cout << endl;
|
std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For given l select intermediate update with largest break-down val
|
// 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.
|
// Select component and comp. bd-condition.
|
||||||
component = Updates_index[p[l+1] - 1];
|
component = Updates_index[p[l+1] - 1];
|
||||||
beta = 1 + ylk[l][p[l+1]][component];
|
beta = 1 + ylk[l][p[l+1]][component];
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "p[l+1] = " << p[l+1] << endl;
|
std::cout << "p[l+1] = " << p[l+1] << std::endl;
|
||||||
cout << "component = " << component << endl;
|
std::cout << "component = " << component << std::endl;
|
||||||
cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "] = " << beta << endl;
|
std::cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "] = " << beta << std::endl;
|
||||||
cout << endl;
|
std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (fabs(beta) < 1e-3) {
|
if (fabs(beta) < 1e-3) {
|
||||||
cerr << "Break-down occured." << endl;
|
std::cerr << "Break-down occured." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute intermediate update to Slater_inv
|
// Compute intermediate update to Slater_inv
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Compute intermediate update to Slater_inv" << endl;
|
std::cout << "Compute intermediate update to Slater_inv" << std::endl;
|
||||||
cout << "component = " << component << endl;
|
std::cout << "component = " << component << std::endl;
|
||||||
cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "]" << endl;
|
std::cout << "beta = 1 + ylk[" << l << "][" << p[l+1] << "][" << component << "]" << std::endl;
|
||||||
cout << "ylk[l][p[k]][:] = ylk[" << l << "][" << p[l+1] << "][:]" << endl;
|
std::cout << "ylk[l][p[k]][:] = ylk[" << l << "][" << p[l+1] << "][:]" << std::endl;
|
||||||
cout << endl;
|
std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
for (i = 0; i < Dim; i++) {
|
for (i = 0; i < Dim; i++) {
|
||||||
for (j = 0; j < Dim; j++) {
|
for (j = 0; j < Dim; j++) {
|
||||||
@ -132,9 +108,9 @@ void MaponiA3(double *Slater_inv, unsigned int Dim,
|
|||||||
for (k = l+2; k < N_updates+1; k++) {
|
for (k = l+2; k < N_updates+1; k++) {
|
||||||
alpha = ylk[l][p[k]][component] / beta;
|
alpha = ylk[l][p[k]][component] / beta;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "Inside k-loop: k = " << k << endl;
|
std::cout << "Inside k-loop: k = " << k << std::endl;
|
||||||
cout << "ylk[" << l+1 << "][" << p[k] << "][:]" << endl;
|
std::cout << "ylk[" << l+1 << "][" << p[k] << "][:]" << std::endl;
|
||||||
cout << endl;
|
std::cout << std::endl;
|
||||||
#endif
|
#endif
|
||||||
for (i = 1; i < Dim + 1; i++) {
|
for (i = 1; i < Dim + 1; i++) {
|
||||||
ylk[l+1][p[k]][i] = ylk[l][p[k]][i]
|
ylk[l+1][p[k]][i] = ylk[l][p[k]][i]
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// SM-Standard.cpp
|
// SM-Standard.cpp
|
||||||
// Standard Sherman Morrison with multiple updates
|
// Standard Sherman Morrison with multiple updates
|
||||||
#include "SM_Standard.hpp"
|
#include "SM_Standard.hpp"
|
||||||
#include "Helpers.hpp"
|
#include "SM_Helpers.hpp"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Set common break-down threshold
|
// Set common break-down threshold
|
||||||
double threshold() {
|
double threshold() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// main.cpp
|
// main.cpp
|
||||||
#include "SM_MaponiA3.hpp"
|
#include "SM_MaponiA3.hpp"
|
||||||
#include "Helpers.hpp"
|
#include "SM_Helpers.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include "hdf5/serial/hdf5.h"
|
#include "hdf5/serial/hdf5.h"
|
||||||
#include "hdf5/serial/H5Cpp.h"
|
#include "hdf5/serial/H5Cpp.h"
|
||||||
|
|
||||||
#include "SM_MaponiA3.hpp"
|
#include "SM_MaponiA3.hpp"
|
||||||
#include "SM_Standard.hpp"
|
#include "SM_Standard.hpp"
|
||||||
#include "Helpers.hpp"
|
#include "SM_Helpers.hpp"
|
||||||
|
|
||||||
using namespace H5;
|
using namespace H5;
|
||||||
// #define DEBUG
|
// #define DEBUG
|
||||||
|
Loading…
Reference in New Issue
Block a user