Thanks, Daniel that helped. Attached is the adapted mwe for others.

d.arnd...@gmail.com schrieb am Montag, 9. Mai 2022 um 12:37:35 UTC+2:

> Maurice,
>
> You could try to wrap the calls that might throw in a try-catch block to 
> deal with the exception yourself (including ignoring it).
>
> Best,
> Daniel
>
> On Mon, May 9, 2022 at 11:14 AM 'maurice rohracker' via deal.II User Group 
> <dea...@googlegroups.com> wrote:
>
>> 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+un...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/dealii/c68d2663-d1a7-4670-a632-9a51abae3d6fn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/dealii/c68d2663-d1a7-4670-a632-9a51abae3d6fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/53c7efae-5559-4fb4-b229-0db8c764bb59n%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::TimerOutput *timerOutput, dealii::ConditionalOStream &outStream)
{
	const UnsignedIntType nTimeSteps = 10;
	for(UnsignedIntType timeStepCtr=0; timeStepCtr<nTimeSteps; ++timeStepCtr)
	{
		outStream << "solving for time-step: " << timeStepCtr << std::endl;
		
        timerOutput->enter_subsection("Solve Time-Step");
		Solve_timeStep(outStream);
		timerOutput->leave_subsection();
	}

}

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

	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");
    try
    {
	    Simulate(&timerOutput, pCout);
	}
	catch(dealii::ExceptionBase& exception)
	{
	    pCout << "Exception thrown to main!!" << std::endl;
        pCout << exception.what() << std::endl;
	    pCout << "Stack trace should be printed below!" << std::endl;
        exception.print_stack_trace(std::cout);
        pCout << "End programm" << std::endl;
	}
	
	return 0;
}

Reply via email to