>
> > 2. The ExceptionBase::print_stack_trace() function does not print
> > anything if I catch an exception thrown using AssetThrow(cond,
> > dealii::ExcMessage()) or even my own MyException class derived from
> > ExceptionBase. How do I ensure that the stack trace is "populated". I
> > tried using the set_fields() function but it did not help.
>
> Can you illustrate in a small test case what you are trying to do?
>

Sorry, it was my mistake. Just to reassure myself, such a stack-trace is
only printed for Assert() and not for AssertThrow(). I realised this while
creating the attached MWE.

Stacktrace:
-----------
#0  ./mwe-stack-trace: Solve_timeStep()
#1  ./mwe-stack-trace: Simulate()
#2  ./mwe-stack-trace: main
--------------------------------------------------------


>
>
> > 3. Considering the parallelization of stress averaging, how could I do a
> > reduction operation to ensure summation of the thread local stresses
> > into a "global" variable once I have distributed the computation using
> > the idea described on pg-10 pf Video Lecture-40 slides? Is Workstream
> > the only solution, or is there some less involved alternative, since I
> > just need to sum the return values of the Compute_stressSumOnCellRange()
> > function?
>
> It's difficult because you probably don't want the object you want to
> sum into to be thread-local (assuming that it is not just a single
> number). WorkStream was invented to work around exactly these sorts of
> problems. We wrote a whole paper about WorkStream precisely because it
> is not trivial to get right, and any alternative solution I could offer
> would also not be trivial.
>
>  The object could be a scalar or a dealii::Tensor<1,dim,double>. I was
looking for something on the lines of #pragma omp for using globalSum as a
shared variable and a '+' reduction operation.

TensorType globalSum;

// parallel part for each thread;  globalSum is shared , '+' as reduction
{
  TensorType localSum;

   // loop for a sub-range of cells
    localSum += cellContribution;

// have a synchronised reduction operation, i.e. globalSum += localSum,
while avoiding race conditions.
}

// back to serial part

To me it seemed that there would be an openmp equivalent procedure for such
simple reduction tasks.

Best regards,
Paras

-- 
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/CAEU6zmQOaa4-1MAcnbRLTmYwATKBA6no5C2KTZK_3mOzogy%3DtQ%40mail.gmail.com.
#include <deal.II/base/exceptions.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()
{
	static UnsignedIntType timeStepCtr = 0;
	
    // do some nonlinear Newton iteration
	std::cout << "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()
{
	const UnsignedIntType nTimeSteps = 10;
	for(UnsignedIntType timeStepCtr=0; timeStepCtr<nTimeSteps; ++timeStepCtr)
	{
		std::cout << "solving for time-step: " << timeStepCtr << std::endl;
		Solve_timeStep();
	}

}

int main()
{

	try
	{
		Simulate();
	}
	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 << "Let us continue" << std::endl;
	}


	// to hit second exception	
	try
	{
		Simulate();
	}
	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 << "Let us continue" << std::endl;
	}
	
	return 0;
}

Reply via email to