Merge pull request #27 from fmgjcoppens/restructure

Restructure
This commit is contained in:
François Coppens 2021-04-14 16:54:09 +02:00 committed by GitHub
commit 7399010a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 87 additions and 72 deletions

View File

@ -28,7 +28,7 @@ FLIBS = -lstdc++
## Includes and dependencies
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
## Directory structure
@ -66,6 +66,9 @@ $(BIN_DIR) $(OBJ_DIR):
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c -o $@ $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
$(CXX) $(CXXFLAGS) -fPIE $(INCLUDE) -c -o $@ $<
## HDF5/C++ objects
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $<

View File

@ -9,7 +9,7 @@ CXXFLAGS = -O0 -g $(H5FLAGS)
FFLAGS = -O0 -g $(H5FLAGS)
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
FLIBS = -lstdc++
@ -49,6 +49,9 @@ $(BIN_DIR) $(OBJ_DIR):
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cpp $(INC_DIR)/* | $(OBJ_DIR)
$(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
$(OBJ_DIR)/%_h5.o: $(TST_DIR)/%_h5.cpp $(INC_DIR)/* | $(OBJ_DIR)
$(H5CXX) $(H5CXXFLAGS) $(INCLUDE) -c -o $@ $<

View File

@ -1,43 +1,48 @@
// 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>
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>
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>

View File

@ -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

31
src/SM_Helpers.cpp Normal file
View 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);
}

View File

@ -2,33 +2,9 @@
// 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,
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;
}
// #define DEBUG
void MaponiA3(double *Slater_inv, unsigned int Dim,
unsigned int N_updates, double *Updates,
@ -68,9 +44,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 +62,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 +108,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]

View File

@ -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() {

View File

@ -1,6 +1,6 @@
// main.cpp
#include "SM_MaponiA3.hpp"
#include "Helpers.hpp"
#include "SM_Helpers.hpp"
int main() {

View File

@ -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