Skip to content

Commit f213731

Browse files
committed
Show progress bar also in fe-bubble calculation
1 parent 0313761 commit f213731

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

anphon/thermodynamics.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
#include "constants.h"
1616
#include "dynamical.h"
1717
#include "kpoint.h"
18-
#include "mathfunctions.h"
1918
#include "memory.h"
2019
#include "mpi_common.h"
2120
#include "phonon_dos.h"
2221
#include "pointers.h"
2322
#include "relaxation.h"
24-
#include "scph.h"
2523
#include "system.h"
24+
#include "progress_bar.h"
2625

2726
using namespace PHON_NS;
2827

@@ -559,6 +558,10 @@ void Thermodynamics::compute_FE_bubble_SCPH(double ***eval_in, std::complex<doub
559558
}
560559
}
561560

561+
auto startTime = std::chrono::system_clock::now();
562+
auto lastUpdate = startTime;
563+
bool isConsole = isOutputToConsole();
564+
562565
unsigned int nk_tmp;
563566

564567
if (nks0 % mympi->nprocs != 0) {
@@ -570,6 +573,9 @@ void Thermodynamics::compute_FE_bubble_SCPH(double ***eval_in, std::complex<doub
570573
vks_l.push_back(-1);
571574
}
572575

576+
auto nks_tmp = vks_l.size();
577+
578+
573579
for (iT = 0; iT < NT; ++iT)
574580
FE_local[iT] = 0.0;
575581

@@ -654,6 +660,16 @@ void Thermodynamics::compute_FE_bubble_SCPH(double ***eval_in, std::complex<doub
654660
for (iT = 0; iT < NT; ++iT)
655661
FE_local[iT] += FE_tmp[iT] * weight;
656662
}
663+
if (mympi->my_rank == 0) {
664+
auto currentTime = std::chrono::system_clock::now();
665+
long long totalElapsedTime =
666+
std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startTime).count();
667+
long long avgTimePerStep = (i0 == 0) ? 0 : totalElapsedTime / i0;
668+
long long timeRemaining = (i0 == 0) ? 0 : avgTimePerStep * (nks_tmp - i0 - 1);
669+
displayProgressBar(i0, nks_tmp - 1, std::cout, timeRemaining, isConsole, "Fe-bubble");
670+
lastUpdate = currentTime;
671+
if (i0 == nk_tmp - 1) std::cout << "\n done. \n\n" << std::flush;
672+
}
657673
}
658674

659675
MPI_Allreduce(&FE_local[0], &FE_bubble[0], NT, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);

include/progress_bar.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
#include <unistd.h> // POSIX header for isatty()
1818
#endif
1919

20-
auto isOutputToConsole() -> bool
20+
inline auto isOutputToConsole() -> bool
2121
{
2222
// File descriptor 1 is stdout
2323
bool isConsoleOutput = getenv("FORCE_CONSOLE_OUTPUT") != nullptr;
2424
return isConsoleOutput;
2525
//return isConsoleOutput || isatty(fileno(stdout));
2626
}
2727

28-
auto displayProgressBar(int current, int total, std::ostream& out, long long timeRemaining, bool isConsoleOutput,
29-
const std::string prefix = "3ph", const int width = 40) -> void
28+
inline auto displayProgressBar(int current, int total, std::ostream& out, long long timeRemaining, bool isConsoleOutput,
29+
const std::string prefix = "3ph", const int width = 40) -> void
3030
{
3131

3232
float progress = (float)current / total;

0 commit comments

Comments
 (0)