Add progressbar to single/multi system
This commit is contained in:
parent
2d473b8255
commit
296dc98e01
|
@ -85,7 +85,6 @@ fn main() {
|
||||||
initial_conditions,
|
initial_conditions,
|
||||||
opt.output.clone(),
|
opt.output.clone(),
|
||||||
);
|
);
|
||||||
// System::new(grids, grid_connections, operators);
|
|
||||||
|
|
||||||
let mut sys = if opt.distribute {
|
let mut sys = if opt.distribute {
|
||||||
basesystem.create_distributed()
|
basesystem.create_distributed()
|
||||||
|
@ -103,11 +102,10 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
sys.output(0);
|
sys.output(0);
|
||||||
//let output = File::create(&opt.output, sys.grids.as_slice(), names).unwrap();
|
|
||||||
//let mut output = OutputThread::new(output);
|
|
||||||
//output.add_timestep(0, &sys.fnow);
|
|
||||||
|
|
||||||
let progressbar = progressbar(opt.no_progressbar, ntime);
|
if !opt.no_progressbar {
|
||||||
|
sys.add_progressbar(ntime)
|
||||||
|
}
|
||||||
|
|
||||||
let timer = if opt.timings {
|
let timer = if opt.timings {
|
||||||
Some(std::time::Instant::now())
|
Some(std::time::Instant::now())
|
||||||
|
@ -118,22 +116,18 @@ fn main() {
|
||||||
let mut itime = 0;
|
let mut itime = 0;
|
||||||
while itime < ntime {
|
while itime < ntime {
|
||||||
sys.advance(steps_between_outputs);
|
sys.advance(steps_between_outputs);
|
||||||
progressbar.inc(1);
|
|
||||||
|
|
||||||
itime += steps_between_outputs;
|
itime += steps_between_outputs;
|
||||||
sys.output(itime);
|
sys.output(itime);
|
||||||
}
|
}
|
||||||
|
if itime != ntime {
|
||||||
/*
|
sys.advance(ntime - itime);
|
||||||
for itime in 0..ntime {
|
sys.output(ntime);
|
||||||
if should_output(itime) {
|
}
|
||||||
output.add_timestep(itime, &sys.fnow);
|
|
||||||
}
|
if !opt.no_progressbar {
|
||||||
progressbar.inc(1);
|
sys.finish_progressbar();
|
||||||
sys.advance(dt);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
progressbar.finish_and_clear();
|
|
||||||
|
|
||||||
let mut outinfo = OutputInformation {
|
let mut outinfo = OutputInformation {
|
||||||
filename: opt.output,
|
filename: opt.output,
|
||||||
|
@ -181,14 +175,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn progressbar(dummy: bool, ntime: u64) -> indicatif::ProgressBar {
|
fn progressbar(ntime: u64) -> indicatif::ProgressBar {
|
||||||
if dummy {
|
let progressbar = indicatif::ProgressBar::new(ntime);
|
||||||
indicatif::ProgressBar::hidden()
|
progressbar.with_style(
|
||||||
} else {
|
indicatif::ProgressStyle::default_bar()
|
||||||
let progressbar = indicatif::ProgressBar::new(ntime);
|
.template("{wide_bar:.cyan/blue} {pos}/{len} ({eta})"),
|
||||||
progressbar.with_style(
|
)
|
||||||
indicatif::ProgressStyle::default_bar()
|
|
||||||
.template("{wide_bar:.cyan/blue} {pos}/{len} ({eta})"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ impl BaseSystem {
|
||||||
dt: Float::NAN,
|
dt: Float::NAN,
|
||||||
operators: self.operators,
|
operators: self.operators,
|
||||||
output: (self.output, outputs),
|
output: (self.output, outputs),
|
||||||
|
progressbar: None,
|
||||||
};
|
};
|
||||||
match &self.initial_conditions {
|
match &self.initial_conditions {
|
||||||
/*
|
/*
|
||||||
|
@ -330,6 +331,7 @@ impl BaseSystem {
|
||||||
recv: master_recv,
|
recv: master_recv,
|
||||||
send: communicators,
|
send: communicators,
|
||||||
output: self.output,
|
output: self.output,
|
||||||
|
progressbar: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,6 +385,24 @@ impl System {
|
||||||
Self::MultiThreaded(sys) => sys.output(ntime),
|
Self::MultiThreaded(sys) => sys.output(ntime),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn add_progressbar(&mut self, ntime: u64) {
|
||||||
|
match self {
|
||||||
|
Self::SingleThreaded(sys) => sys.progressbar = Some(super::progressbar(ntime)),
|
||||||
|
Self::MultiThreaded(sys) => sys.attach_progressbar(ntime),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn finish_progressbar(&mut self) {
|
||||||
|
match self {
|
||||||
|
Self::SingleThreaded(sys) => sys.progressbar.take().unwrap().finish_and_clear(),
|
||||||
|
Self::MultiThreaded(sys) => {
|
||||||
|
let (target, pbs) = sys.progressbar.take().unwrap();
|
||||||
|
for pb in pbs.into_iter() {
|
||||||
|
pb.finish_and_clear()
|
||||||
|
}
|
||||||
|
target.join_and_clear().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SingleThreadedSystem {
|
pub struct SingleThreadedSystem {
|
||||||
|
@ -398,6 +418,7 @@ pub struct SingleThreadedSystem {
|
||||||
pub dt: Float,
|
pub dt: Float,
|
||||||
pub operators: Vec<Box<dyn SbpOperator2d>>,
|
pub operators: Vec<Box<dyn SbpOperator2d>>,
|
||||||
pub output: (hdf5::File, Vec<hdf5::Group>),
|
pub output: (hdf5::File, Vec<hdf5::Group>),
|
||||||
|
pub progressbar: Option<indicatif::ProgressBar>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl integrate::Integrable for SingleThreadedSystem {
|
impl integrate::Integrable for SingleThreadedSystem {
|
||||||
|
@ -420,7 +441,10 @@ impl SingleThreadedSystem {
|
||||||
|
|
||||||
pub fn advance(&mut self, nsteps: u64) {
|
pub fn advance(&mut self, nsteps: u64) {
|
||||||
for _ in 0..nsteps {
|
for _ in 0..nsteps {
|
||||||
self.advance_single_step(self.dt)
|
self.advance_single_step(self.dt);
|
||||||
|
if let Some(pbar) = &self.progressbar {
|
||||||
|
pbar.inc(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,6 +574,7 @@ pub struct DistributedSystem {
|
||||||
/// All threads should be joined to mark the end of the computation
|
/// All threads should be joined to mark the end of the computation
|
||||||
sys: Vec<std::thread::JoinHandle<()>>,
|
sys: Vec<std::thread::JoinHandle<()>>,
|
||||||
output: hdf5::File,
|
output: hdf5::File,
|
||||||
|
progressbar: Option<(indicatif::MultiProgress, Vec<indicatif::ProgressBar>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DistributedSystem {
|
impl DistributedSystem {
|
||||||
|
@ -557,6 +582,17 @@ impl DistributedSystem {
|
||||||
for tid in &self.send {
|
for tid in &self.send {
|
||||||
tid.send(MsgFromHost::Advance(ntime)).unwrap();
|
tid.send(MsgFromHost::Advance(ntime)).unwrap();
|
||||||
}
|
}
|
||||||
|
if let Some(pbar) = &self.progressbar {
|
||||||
|
let expected_messages = ntime * self.sys.len() as u64;
|
||||||
|
for _i in 0..expected_messages {
|
||||||
|
match self.recv.recv().unwrap() {
|
||||||
|
(i, MsgToHost::CurrentTimestep(_)) => {
|
||||||
|
pbar.1[i].inc(1);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn output(&self, ntime: u64) {
|
pub fn output(&self, ntime: u64) {
|
||||||
for tid in &self.send {
|
for tid in &self.send {
|
||||||
|
@ -568,6 +604,16 @@ impl DistributedSystem {
|
||||||
tds.write_slice(&[ntime], ndarray::s![tpos..tpos + 1])
|
tds.write_slice(&[ntime], ndarray::s![tpos..tpos + 1])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
pub fn attach_progressbar(&mut self, ntime: u64) {
|
||||||
|
let target = indicatif::MultiProgress::new();
|
||||||
|
let mut progressbars = Vec::with_capacity(self.sys.len());
|
||||||
|
for _ in 0..self.sys.len() {
|
||||||
|
let pb = super::progressbar(ntime);
|
||||||
|
progressbars.push(target.add(pb));
|
||||||
|
}
|
||||||
|
target.set_move_cursor(true);
|
||||||
|
self.progressbar = Some((target, progressbars));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for DistributedSystem {
|
impl Drop for DistributedSystem {
|
||||||
|
|
Loading…
Reference in New Issue