Skip to content

Commit e6ff019

Browse files
committed
fixes
1 parent f739836 commit e6ff019

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

debug/unittests/ut3/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,19 @@ int main(){
6060
// this integral will give a wrong answer! This is because the starting point is very bad and initialDecorrelation is skipped (as well as the MRT2step automatic setting)
6161
mci->setX(x);
6262
mci->integrate(NMC, average, error, 0, 0);
63-
std::cout << average[0] << " " << error[0] << std::endl;
6463
assert( abs(average[0]-CORRECT_RESULT) > 2.*error[0] );
6564

6665
// this integral, instead, will provide the right answer
6766
mci->setX(x);
6867
mci->integrate(NMC, average, error, 10, 1000);
69-
std::cout << average[0] << " " << error[0] << std::endl;
7068
assert( abs(average[0]-CORRECT_RESULT) < 2.*error[0] );
7169

7270
// now, doing an integral without finding again the MRT2step and doing the initialDecorrelation will also result in a correct result
7371
mci->integrate(NMC, average, error, 0, 0);
74-
std::cout << average[0] << " " << error[0] << std::endl;
7572
assert( abs(average[0]-CORRECT_RESULT) < 2.*error[0] );
7673

7774
// and using fixed blocking also gives the same result
7875
mci->integrate(NMC, average, error, 0, 0, 15);
79-
std::cout << average[0] << " " << error[0] << std::endl;
8076
assert( abs(average[0]-CORRECT_RESULT) < 2.*error[0] );
8177

8278

src/MCIntegrator.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313

1414
void MCI::integrate(const long &Nmc, double * average, double * error, bool findMRT2step, bool initialdecorrelation, size_t nblocks)
1515
{
16-
MCI::integrate(Nmc, average, error, findMRT2step ? -1 : 0, initialdecorrelation ? -1 : 0, nblocks);
16+
int stepsMRT2 = findMRT2step ? -1 : 0;
17+
int stepsDecorr = initialdecorrelation ? -1 : 0;
18+
MCI::integrate(Nmc, average, error, stepsMRT2, stepsDecorr, nblocks);
1719
}
1820

1921
void MCI::integrate(const long &Nmc, double * average, double * error, int NfindMRT2stepIterations, int NdecorrelationSteps, size_t nblocks)
2022
{
23+
if (Nmc<(long)nblocks) {
24+
throw std::invalid_argument("The specified number of MC steps is smaller than the requested number of blocks.");
25+
}
26+
2127
long i,j;
2228
const bool fixedBlocks = (nblocks>0);
2329
const long stepsPerBlock = fixedBlocks ? Nmc/nblocks : 1;
@@ -151,7 +157,7 @@ void MCI::initialDecorrelation(const int &NdecorrelationSteps)
151157
for (i=0; i<MIN_NMC; ++i){ delete[] *(_datax+i); }
152158
delete [] _datax;
153159
}
154-
else {
160+
else if (NdecorrelationSteps > 0) {
155161
this->sample(NdecorrelationSteps, false);
156162
}
157163
}

src/MPIMCI.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ namespace MPIMCI
6666

6767
// integrate in parallel and accumulate results
6868

69-
void integrate(MCI * const mci, const long &Nmc, double * average, double * error, bool findMRT2step=true, bool initialdecorrelation=true, size_t nblocks=0, bool use_mpi=true) // auto-mode-wrapper
70-
{
71-
integrate(mci, Nmc, average, error, findMRT2step ? -1 : 0, initialdecorrelation ? -1 : 0, nblocks, use_mpi);
72-
}
73-
7469
void integrate(MCI * const mci, const long &Nmc, double * average, double * error, int NfindMRT2stepIterations, int NdecorrelationSteps, size_t nblocks=0, bool use_mpi=true) // by setting use_mpi to false you can use this without requiring MPI
7570
{
7671
if (use_mpi) {
@@ -104,6 +99,14 @@ namespace MPIMCI
10499
}
105100
}
106101

102+
void integrate(MCI * const mci, const long &Nmc, double * average, double * error, bool findMRT2step=true, bool initialdecorrelation=true, size_t nblocks=0, bool use_mpi=true) // auto-mode-wrapper
103+
{
104+
int stepsMRT2 = findMRT2step ? -1 : 0;
105+
int stepsDecorr = initialdecorrelation ? -1 : 0;
106+
integrate(mci, Nmc, average, error, stepsMRT2, stepsDecorr, nblocks, use_mpi);
107+
}
108+
109+
107110
// finalize MPI
108111
void finalize()
109112
{

0 commit comments

Comments
 (0)