-
Soeren Peters authoredSoeren Peters authored
CalculationManager.cpp 4.91 KiB
#include "CalculationManager.h"
#include <boost/thread.hpp>
#include "CalculatorFactory.h"
#include <Calculator.h>
#include <MPICalculator.h>
#if defined VF_FETOL
#include <FETOLCalculator.h>
#endif
#include <Communicator.h>
#include "TimeAveragedValuesCoProcessor.h"
#include "Grid3D.h"
#include "LoadBalancer.h"
//////////////////////////////////////////////////////////////////////////
CalculationManager::CalculationManager(Grid3DPtr grid, int numOfThreads, double endTime, std::shared_ptr<CalculatorFactory> calculatorFactory, CalculatorType type)
: grid(grid),
numOfThreads(numOfThreads),
endTime(endTime),
calculatorFactory(calculatorFactory),
type(type)
{
this->initCalcThreads();
}
//////////////////////////////////////////////////////////////////////////
CalculationManager::CalculationManager(Grid3DPtr grid, int numOfThreads, double endTime, CommunicatorPtr comm, int endDir, std::shared_ptr<CalculatorFactory> calculatorFactory)
: grid(grid),
numOfThreads(numOfThreads),
endTime(endTime),
calculatorFactory(calculatorFactory),
type(type)
{
this->initCalcThreads();
loadBalancer = LoadBalancerPtr(new LoadBalancer(grid, comm, endDir));
}
//////////////////////////////////////////////////////////////////////////
CalculationManager::~CalculationManager()
{
}
//////////////////////////////////////////////////////////////////////////
void CalculationManager::calculate()
{
if (type == CalculatorType::MPI)
{
try
{
std::dynamic_pointer_cast<MPICalculator>(calcThreads[0])->calculate(endTime, shared_from_this());
}
catch (std::exception& e)
{
UBLOG(logERROR, e.what());
//throw e;
exit(EXIT_FAILURE);
}
}
else
{
try
{
boost::thread_group threads;
boost::exception_ptr error;
for (int i = 1; i < calcThreads.size(); i++)
threads.create_thread(boost::bind(&Calculator::calculate, calcThreads[i], endTime, shared_from_this(), boost::ref(error)));