Dear all,

In the attached mwe we are facing the issue, that the TimerOutput object 
does not print the resulting table to the screen when an exception is 
thrown and caught within in a MPI based code.

We are aware that some collective routine might be needed.

However, is there a way which can handle this easily, such that TimerOutput 
object prints the resulting table to the screen even if an exception is 
thrown or are we missing something?

We were already able to do so in the serial case.

Thanks in advance.

Best regards,
Maurice

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/c68d2663-d1a7-4670-a632-9a51abae3d6fn%40googlegroups.com.
#include <deal.II/base/conditional_ostream.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/mpi.h>
#include <deal.II/base/timer.h>
#include <string>

using UnsignedIntType = unsigned int;


class MyException : public dealii::ExceptionBase
    {
    public:
		MyException(const std::string &failureLocation)
		: failureLoc_(failureLocation)
		{
		if ((failureLoc_ != "pf") && (failureLoc_ != "disp") &&
		  (failureLoc_ != "outer"))
		Assert(false, dealii::ExcMessage("Invalid failure location string!"));
		}

		virtual ~MyException() noexcept = default;

		virtual void
		print_info(std::ostream &outStream) const
		{
			if (failureLoc_ == "pf")
			outStream << "Non convergence in the pf loop" << std::endl;
			else if (failureLoc_ == "disp")
			outStream << "Non convergence in the disp loop" << std::endl;
			else if (failureLoc_ == "outer")
			outStream << "Non convergence in the outer loop" << std::endl;
		}

        std::string failureLoc_;
};

void Solve_timeStep(dealii::ConditionalOStream &outStream)
{
	static UnsignedIntType timeStepCtr = 0;
	
    // do some nonlinear Newton iteration
	outStream << "local time-step counter: " << timeStepCtr << std::endl;

    // the procedure fails for 4-th time-step
	if(timeStepCtr ==  4)
	{
		++timeStepCtr;
		AssertThrow(false, MyException("pf")); 
	}

	//if(timeStepCtr == 6)
	//	Assert(false, MyException("disp"));

	++timeStepCtr;
}

void Simulate(dealii::ConditionalOStream &outStream)
{
	const UnsignedIntType nTimeSteps = 10;
	for(UnsignedIntType timeStepCtr=0; timeStepCtr<nTimeSteps; ++timeStepCtr)
	{
		outStream << "solving for time-step: " << timeStepCtr << std::endl;
		Solve_timeStep(outStream);
	}

}

int main(int argc, char *argv[])
{

	try
	{
	
        dealii::Utilities::MPI::MPI_InitFinalize mpiInitialization(argc, argv, 1);
        MPI_Comm const &                         mpiCommunicator(MPI_COMM_WORLD);
        UnsignedIntType          processorRank = dealii::Utilities::MPI::this_mpi_process(mpiCommunicator);
        dealii::ConditionalOStream pCout(std::cout, processorRank == 0);
        dealii::TimerOutput timerOutput(mpiCommunicator, pCout, dealii::TimerOutput::summary, dealii::TimerOutput::wall_times);
        dealii::TimerOutput::Scope timer_section(timerOutput, "Simulation");
        timerOutput.enter_subsection("Simulate");
		Simulate(pCout);
		timerOutput.leave_subsection();
	}
	catch(dealii::ExceptionBase& exception)
	{
	  std::cout << "Exception thrown to main!!" << std::endl;
      std::cout << exception.what() << std::endl;
	  std::cout << "Stack trace should be printed below!" << std::endl;
      exception.print_stack_trace(std::cout);
 	  std::cout << "End programm" << std::endl;
	}
	
	return 0;
}
SET(TARGET "mwe-timerOutput-mpi")
SET(TARGET_SRC ${TARGET}.cc)

cmake_minimum_required(VERSION 3.16)

FIND_PACKAGE(deal.II 9.0.0 QUIET HINTS ${deal.II_DIR} ${DEAL_II_DIR} 
$ENV{DEAL_II_DIR})

DEAL_II_INITIALIZE_CACHED_VARIABLES()

PROJECT(${TARGET})
DEAL_II_INVOKE_AUTOPILOT()

Reply via email to