SimFullImplOutput: added future to ensure that write history is accounted for.

This commit is contained in:
Robert Kloefkorn 2016-03-29 15:22:33 +02:00
parent d5c375f297
commit 5044a07e46
2 changed files with 21 additions and 6 deletions

View File

@ -262,22 +262,33 @@ namespace Opm
const WellState wellState_;
const bool substep_;
std::future< bool > asyncWait_;
explicit WriterCall( BlackoilOutputWriter& writer,
const SimulatorTimerInterface& timer,
const SimulatorState& state,
const WellState& wellState,
bool substep)
bool substep,
std::future< bool >&& asyncWait)
: writer_( writer ),
timer_( timer.clone() ),
state_( state ),
wellState_( wellState ),
substep_( substep )
substep_( substep ),
asyncWait_( std::move( asyncWait ) )
{}
// callback to writer's serial writeTimeStep method
void operator () ()
bool operator () ()
{
// wait for previous time step thread to be finished
// to ensure that write history is correct.
if( asyncWait_.valid() ) {
asyncWait_.wait();
}
writer_.writeTimeStepSerial( *timer_, state_, wellState_, substep_ );
return true;
}
};
@ -294,7 +305,7 @@ namespace Opm
vtkWriter_->writeTimeStep( timer, localState, localWellState, false );
}
bool isIORank = true ;
bool isIORank = output_ ;
if( parallelOutput_ && parallelOutput_->isParallel() )
{
// collect all solutions to I/O rank
@ -308,9 +319,11 @@ namespace Opm
if( isIORank )
{
if( asyncOutput_ ) {
// spawn write thread that calls eclWriter.writeTimeStepSerial
WriterCall call( *this, timer, state, wellState, substep );
std::async( std::move( call ) );
// timer, state, and wellState are copied, previous async future is moved
WriterCall call( *this, timer, state, wellState, substep, std::move( asyncWait_ ) );
asyncWait_ = std::move( std::async( std::move( call ) ) );
}
else {
// just write the data to disk

View File

@ -44,6 +44,7 @@
#include <sstream>
#include <iomanip>
#include <fstream>
#include <future>
#include <boost/filesystem.hpp>
@ -262,6 +263,7 @@ namespace Opm
std::unique_ptr< EclipseWriter > eclWriter_;
EclipseStateConstPtr eclipseState_;
const bool asyncOutput_ ;
std::future< bool > asyncWait_;
};