Moved common MaponiA3 functions to SM_Helpers.{cpp,hpp} to prepare for MaponiA3+Slagel splitting.

This commit is contained in:
Francois Coppens 2021-04-14 16:19:49 +02:00
parent ab9d13180a
commit 991f40a605
5 changed files with 45 additions and 32 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

@ -5,6 +5,12 @@
#include <cstring>
#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, std::string name) {
std::cout << name << " = " << scalar << std::endl << std::endl;

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

@ -6,36 +6,6 @@
// #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;
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);
}
void MaponiA3(double *Slater_inv, unsigned int Dim,
unsigned int N_updates, double *Updates,
unsigned int *Updates_index) {