Commit 700ddfa2 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Remove the old implementation

parent 25043441
/*
* ----------------------------------------------------------------
*
* ITA simulation scheduler
* (c) Copyright Institute of Technical Acoustics (ITA)
* RWTH Aachen University, Germany, 2019-2020
*
* ----------------------------------------------------------------
* ____ __________ _______
* // / //__ ___/ // _ |
* // / // / // /_| |
* // / // / // ___ |
* //__/ //__/ //__/ |__|
*
* ----------------------------------------------------------------
*
*/
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_DEFINITIONS
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_DEFINITIONS
#if ( defined WIN32 ) && !( defined ITA_SIMULATION_SCHEDULER_STATIC )
#ifdef ITA_SIMULATION_SCHEDULER_EXPORT
#define ITA_SIMULATION_SCHEDULER_API __declspec( dllexport )
#else
#define ITA_SIMULATION_SCHEDULER_API __declspec( dllimport )
#endif
#else
#define ITA_SIMULATION_SCHEDULER_API
#endif
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_DEFINITIONS
/*
* RAVEN Interface
*
* (c) Copyright Institut fr Technische Akustik (ITA)
* RWTH Aachen (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* Datei: R_Raven.h
*
* Zweck: Interface to RAVEN
*
* Autor(en): Jonas Stienen (stienen@akustik.rwth-aachen.de)
* Frank Wefers (fwe@akustik.rwth-aachen.de)
* Snke Pelzer (spe@akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*/
// $Id: R_Raven.h 2732 2012-06-26 13:38:17Z stienen $
#ifndef __ITA_SIMULATION_SCHEDULER_INTERFACES_H__
#define __ITA_SIMULATION_SCHEDULER_INTERFACES_H__
// API includes
#include <ITASimulationScheduler/Definitions.h>
// Raven includes
#include <RG_Vector.h>
#include <ITASimulationScheduler/Raven/Scene.h>
#include <ITASimulationScheduler/Raven/Config.h>
// ITA includes
#include <ITAException.h>
#include <ITASampleFrame.h>
// STL includes
#include <map>
#include <stdio.h>
#include <vector>
namespace ITASimulationScheduler
{
//! Statistics class
/**
* This class holds information on statistical values such as
* average and deviation.
*/
class ITA_SIMULATION_SCHEDULER_API CStatistics
{
public:
//! Constructor, sets internal values to zero
CStatistics()
{
Reset();
};
//! Set all internal values to zero
void Reset()
{
dMean = 0;
dStdDev = 0;
dMin = 0;
dMax = 0;
uiCycles = 0;
};
double dMean; //!< Mean/Average
double dStdDev; //!< Standard deviation
double dMin; //!< Maximum
double dMax; //!< Minimum
unsigned long int uiCycles; //!< Number of cycles/elements
std::string sName; //!< Short name
};
//! Simulation task
/**
* Enthlt Informationen ber Auftragstyp, virtuelle Szene und Konfiguration der Simulation.
* Datenpfade sollten mit dem Makro $(RavenDataBasePath) beginnen, um den (entfernten) Simulator
* anzuweisen, den fr sich eingestellten Datenpfad zu verwenden.
*/
class ITA_SIMULATION_SCHEDULER_API CSimulationTask
{
public:
//!< Simulation types
enum
{
SIM_DS = 1 << 0, //!< Direct sound
SIM_ER_IS = 1 << 1, //!< Early reflections using Image Sources
SIM_DD_RT = 1 << 2, //!< Diffuse decay using Ray Tracing
SIM_DD_AR = 1 << 3, //!< Diffuse decay using Artificial Reverberation
};
CSimulationTask() {};
virtual ~CSimulationTask() {};
unsigned long int uiID; //!< Unique Identifier fr diesen Task
unsigned long int uiReferenceID; //!< Referenz-Identifier (fr den Benutzer)
int iSimulationType; //!< Type of simulation, one of 'simulation types'
RAVEN::CScene oScene; //!< Scene, die komplett simuliert wird (smtliche Quellen, Portale und Empfnger)
RAVEN::CConfig oConfig; //!< Konfiguration fr den Simulationsauftrag
//! Task profiler status
struct CProfiler
{
//! Discard reasons
enum
{
UNSPECIFIED = 0, //!< Unkown or unspecified reason
RESET_INDICATED, //!< Discarded due to reset request
REPLACED_BY_NEWER, //!< Task was replaced by a newer task with same reference id
REPLACED_BY_PREFERRED, //!< Task was replaced by a preferred task
UNHANDABLE, //!< Task could not be handled by scheduler
};
double dCreationTime;
double dSchedulerEnqueTime;
double dSchedulerTurnaroundTime;
double dComputeTime;
int iDiscardReason;
};
CProfiler oProfiler; //!< Task Profiler
//! Perform some sanity checks
inline bool IsValid() const
{
if (iSimulationType < 0)
return false;
if (oConfig.Validate() != 0)
return false;
return true;
};
};
//! Container for simulation results
class ITA_SIMULATION_SCHEDULER_API CSimulationResult
{
public:
//! Complex sound path of a sender-receiver-pair
class ComplexSimulationSoundPath
{
public:
ComplexSimulationSoundPath();
virtual ~ComplexSimulationSoundPath();
//! Art des komplexen Schallpfades
enum
{
S2R = 0, //!< Quelle zu Empfnger
P2R, //!< Portal zu Empfnger
S2P, //!< Quelle zu Portal
P2P, //!< Portal zu Portal
};
int iType; //!< Art des komplexen Schallpfades
int iReceiverID; //!< ID des Empfngerobjekts (Hrer oder Portal)
int iSenderID; //!< ID des Senderobjekts (Quelle oder Portal)
int iNumChannels; //!< Anzahl der Kanle
bool bDirectSoundAudible; //!< True, wenn Direktschall hrbar ist (nicht verdeckt)
bool bEntitiesInSameRoom; //!< True, if source and receiver are in sme room
bool bEmpty; //!< True, wenn die Impulsantwort leer ist
int iLeadingZeros; //!< Anzahl an Null-Samples am Anfang der eigentlichen Impulsantwort
int iTailingZeros; //!< Anzahl an Null-Samples am Ende der generierten Impulsantwort
bool bZerosStripped; //!< Indicated, if zeros are stripped from result container (true) or still included (false)
ITASampleFrame* psfResult; //!< Zeiger auf Impulsantwort des komplexen Schallpfades
};
//! Constructor
CSimulationResult();
//! Destructor
virtual ~CSimulationResult();
//! Deletes all accumulated complex simulation sound paths
virtual void Clear();
std::vector< ComplexSimulationSoundPath* > vcspResult; //!< Result container
};
//! Abstract RAVEN simulation interface
/**
* This abstract Interface to RAVEN embraces the
* functional methods that every Raven simulator
* has to implement.
*
*/
class ITA_SIMULATION_SCHEDULER_API ISimulationInterface
{
public:
virtual ~ISimulationInterface() {};
//! Reset
/**
* Perform an entire reset of the RAVEN instance, i.e. clear all objects and geometry (scene)
*/
virtual void Reset() = 0;
//! Load a scene (RPF)
/**
* \param sFileName Path to the Raven Project File (RPF), use with macro $(RavenDataBasePath)
*
* \note will become irrelevant one day ... load via special task
*/
virtual void LoadScene(const std::string& sFileName) = 0;
//! Perform a simulation of a task and provide result
/**
* This call will perform a simulation of the required task and will present the result.
* This call is blocking, i.e. depending on the complexity of the scene and the geometry,
* the computation might take a couple of seconds.
*
* \param pTask Simulation task with a scene and a configuration, profiler status will be modified
* \param pResult Pointer to an existing simulation result container. Results will initialized and appended to the container.
*/
virtual void Compute(CSimulationTask* pTask, CSimulationResult* pResult) = 0;
//! Simulator profiler
struct CProfiler
{
unsigned int uiNumLoadScenes; //!< Number of (forced) scene reloads
unsigned int uiNumResets; //!< Number of (forced) resets
CStatistics oCompute; //!< Statistics on overall compute (incl. config and scene adaption and simulation)
CStatistics oSimulateDS; //!< Statistics on simulation of DS
CStatistics oSimulateIS; //!< Statistics on simulation of IS
CStatistics oSimulateRT; //!< Statistics on simulation of RT
CStatistics oSimulateAR; //!< Statistics on simulation of AR
};
//! Return current profiler status
/**
* \param oStatus Status information, only if profile availabele
*
* \return TRUE, if profile information available, false otherwise (check this!)
*/
virtual bool GetProfilerStatus(CProfiler& oStatus) = 0;
protected:
//! Protected standard constructor
ISimulationInterface() {};
};
// Forward declaration of result handler
class ISimulationSchedulerResultHandler;
//! Abstract RAVEN simulation scheduler interface
/**
* This abstract Interface to a RAVEN scheduler embraces the
* functional methods that every RAVEN scheduler has to implement.
*
* A Raven simulation scheduler receives tasks and either
* discards the computation or accepts and in latter case
* returns a simulation result.
*
*/
class ITA_SIMULATION_SCHEDULER_API ISimulationSchedulerInterface
{
public:
//! Destructor
virtual ~ISimulationSchedulerInterface() {};
// stienen: vielleicht brauchen wir den fr Handle-Hooks, i.e. fr RavenNet
//virtual void SetTaskHandler(IRavenSimulationSchedulerTaskHandler*)=0;
//! Reset the Scheduler and its simulators
/**
* \note This call will go into a blocking wait until all nodes have
* signaled that they sucessfully performed a reset. In worst case
* this means, that the scheduler will wait for an entire simulation task
* to be performed (i.e. up to some hundred milliseconds, if Ray Tracing is used)
*/
virtual void Reset() = 0;
//! Add a task to the scheduler queue
/**
* \param pTask Simulation task with a scene and a configuration, task profiler status will be modified
*/
virtual void AddTask(CSimulationTask* pTask) = 0;
//! Advise the scheduler to load a geometry file
/**
* \param sFileName Path to the geometry file (.ac), use with macro $(RavenDataBasePath)
*/
virtual void LoadScene(const std::string& sFileName) = 0;
//! Attach a Simulation Result Handler that will be called when Task is finished or discarded
/**
* \return True, if attach possible, false if already present in internal list
*/
virtual bool AttachSimulationResultHandler(ISimulationSchedulerResultHandler*) = 0;
//! Detach a Simulation Result Handler
/**
* \return True, if detach possible, false if already present in internal list
*/
virtual bool DetachSimulationResultHandler(ISimulationSchedulerResultHandler*) = 0;
//! Scheduler profiler
struct CProfiler
{
public:
// Tasks
struct CProfilerSimType
{
unsigned long int uiTasksAdded; //!< Total number of added tasks
unsigned long int uiTasksDiscarded; //!< Total number of discarded tasks
unsigned long int uiTasksFinished; //!< Total number of finished tasks
unsigned long int uiTasksPending; //!< Total number of pending tasks
double dTaskTurnaroundDiscarded; //!< Average time for turnaround if task was discarded
double dTaskTurnaroundFinished; //!< Average time for turnaround if task was finished
double dTaskComputeAvrg; //!< Average time that has been spend on compute
};
CProfilerSimType oAll;
CProfilerSimType oDS;
CProfilerSimType oER_IS;
CProfilerSimType oDD_RT;
CProfilerSimType oDD_AR;
};
//! Return current profiler status
/**
* \param oStatus Status information, only if profile availabele
*
* \return TRUE, if profile information available, false otherwise (check this!)
*/
virtual bool GetProfilerStatus(CProfiler& oStatus) = 0;
protected:
//! Protected standard constructor
ISimulationSchedulerInterface() {};
};
//! Abstracter Handler, der einem Scheduler hinzugefgt werden kann und welcher dann mit Resultaten bedient wird
class ITA_SIMULATION_SCHEDULER_API ISimulationSchedulerResultHandler
{
public:
enum
{
COMPUTE_TASK = 0,
DISCARD_TASK = 1,
};
enum
{
DELETE_TASK = 0,
PRESERVE_TASK = 1,
};
virtual ~ISimulationSchedulerResultHandler() {};
//! Hook: Wird aufgerufen nachdem ein Task dem Scheduler hinzugefgt wurde
// VIELLEICHT: virtual void PostTaskAdded(Scheduler*, Task*) {};
//! Hook: Wird vor der tatschlichen Ausfhrung des Task aufgerufen
/**
* Der Handler kann den Aufruf dazu nutzen den Task zu verndern
* (z.B. zwischenzeitlich aktualisierte Positionsdaten) oder diesen
* zu verwerfen (hierzu wird der Rckgabewert genutzt, COMPUTE_TASK|DISCARD_TASK).
*/
virtual int PreTaskStart(ISimulationSchedulerInterface*, CSimulationTask*) = 0;
//! Hook: Wird aufgerufen nachdem ein Task abgeschlossen wurde
/**
* \return Ein Wert aus #TaskDeletion
*/
virtual int PostTaskFinished(ISimulationSchedulerInterface*, const CSimulationTask*, CSimulationResult*) = 0;
//! Hook: wird aufgerufen, nachdem ein Task abgewiesen/ersetzt wurde
/**
* \return Ein Wert aus #TaskDeletion
*/
virtual int PostTaskDiscarded(ISimulationSchedulerInterface*, const CSimulationTask*) = 0;
protected:
//! Protected standard constructor
ISimulationSchedulerResultHandler() {};
};
}
#endif // __ITA_SIMULATION_SCHEDULER_INTERFACES_H__
/*
* RAVEN Interface
*
* (c) Copyright Institute of Technical Acoustic (ITA)
* RWTH Aachen University (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* File: R_RavenLocalScheduler.h
*
* Purpose: Raven simulation scheduler, that is running local simulation instances
* using threads and manages tasks based on priority and desired update rates
*
* Author(s): Jonas Stienen (stienen@akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*/
// $Id: RavenTest.cpp 2732 2012-06-26 13:38:17Z stienen $
#ifndef __ITA_SIMULATION_SCHEDULER_LOCAL_SCHEDULER_H__
#define __ITA_SIMULATION_SCHEDULER_LOCAL_SCHEDULER_H__
// API includes
#include <ITASimulationScheduler/Definitions.h>
// Raven includes
#include <ITASimulationScheduler/Interfaces.h>
// ITA includes
#include <ITAAtomicPrimitives.h>
#include <ITADataLog.h>
#include <ITASampleFrame.h>
#include <ITAStopWatch.h>
// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadEvent.h>
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Concurrency/VistaPriority.h>
// 3rdParty includes
#include <tbb/concurrent_queue.h>
// STL includes
#include <assert.h>
#include <list>
#include <vector>
namespace ITASimulationScheduler
{
//! Lokaler Scheduler fr Raven-Simulationsauftrge
/**
* Dieser lokal arbeitende Scheduler erzeugt mehrere Threads fr Raven-Simulatoren und verteilt
* eingehende Tasks auf diese. Dabei arbeitet er so, dass die Threads mit unterschiedlichen
* Priorisierungen laufen und jeweils unterschiedliche Simulationsauftrge abarbeiten (DS, DS+IS, IS und RT).
* Andere Typen sind nicht erlaubt, und die Anzahl der verfgbaren Entitten (Receiver, Sources, Portals)
* hngt von der Einstellung der Raven-Simulatoren (CRavenSimulator) ab.
* Der lokale Scheduler verwirft smtliche Tasks, die nicht abgearbeitet werden konnten und von einem
* neuen Task unter folgenden auflagen verdngt wurden:
*
* 1. Exakt identische Konfiguration (CConfig)
* 2. Identischer Auftragstyp (DS, DS+ER, ER oder DD)
* 3. Gleiche Szene (CScene), d.h. smtliche Entitten identisch, aber mglicherweise unterschiedlicher State (CRaven*State)
*
* \todo Eventuell den Scheduler so einstellbar machen, dass er sich auch anders verhlt, z.B. NIE verdrngt. Dies
* knnte dann sinnvoll sein, wenn man den Scheduler als "Task-Queue" verwendet, um z.B. Trajektorien abzufahren und
* Impulsantworten zu generieren.
*/
class ITA_SIMULATION_SCHEDULER_API CLocalScheduler : public ISimulationSchedulerInterface, public VistaThreadLoop
{
public:
//! Scheduler configuration
class ITA_SIMULATION_SCHEDULER_API CConfiguration
{
public:
//! Thread configuration
class ITA_SIMULATION_SCHEDULER_API CThreadConfiguration
{
public:
//! Process task assignment
enum
{
TIMEOUT = 0, //!< Update task assignment using a timeout
EVENTSYNC, //!< Update task assignment when added (may use entire ressources)
CONTINUOUS //!< Update tasks continuously (uses entire ressources)
};
int iTaskProcessingMode; //!< One of \TaskAssignmentProcessing
int iFieldOfDuty; //!< Field of duty for this thread (DS, ER, DD)
float fUpdateRate; //!< Desired update rate for this thread in Hz
int iPriority; //!< Thread priority, careful with this parameter!
std::string sRavenDataBasePath; //!< Raven data base path
};
std::string sRavenDataBasePath; //!< Local path to RAVEN data, can be absolute or relative to executable
std::vector< CThreadConfiguration > voThreads; //!< List of thread configurations
std::string ToString() const;
};
//! Constructor with configuration
/**
* Creates a scheduler based on given configuration
*
* \param oConf Local scheduler configuration, see \Configuration
*
*/
CLocalScheduler(const CConfiguration& oConf);
//! Destructor
virtual ~CLocalScheduler();
//! Alles RAVEN-artige intern abrumen und neu aufsetzen
/**
* \note Non-reentrant! Es darf wrend dieses Aufrufs keine andere Funktion parallel betreten werden
*/
virtual void Reset();
//! Laden der Geometrien aus einer Scene
/**
* \note Non-reentrant! Es darf wrend dieses Aufrufs keine andere Funktion parallel betreten werden
*/
virtual void AddTask(CSimulationTask* pTask);
//! Preload geometry
virtual void LoadScene(const std::string&);
virtual void HandleTaskFinished(CSimulationTask* pTask, CSimulationResult* pResult, int iErrorcode);
virtual void HandleTaskDiscarded(CSimulationTask* pTask);
virtual bool AttachSimulationResultHandler(ISimulationSchedulerResultHandler*);
virtual bool DetachSimulationResultHandler(ISimulationSchedulerResultHandler*);
virtual bool GetProfilerStatus(ISimulationSchedulerInterface::CProfiler& oStatus);
// --= Schnittstelle "VistaCoreThread" =--
virtual bool LoopBody();
class CSimulationThread : public VistaThreadLoop
{
public:
//! Erzeugt einen eigenstndigen Simulationsthread mit einer Raven-Instanz
CSimulationThread(CLocalScheduler* pScheduler, const CConfiguration::CThreadConfiguration& oConf);
virtual ~CSimulationThread();
//! Gibt true zurck, wenn kein Task bearbeitet wird
virtual bool IsIdle();
//! Gibt true zurck, wenn die Scene geladen ist
virtual bool IsSceneLoaded() const;
//! Gibt den aktuellen Task oder NULL (Idle) zurck
/**
* \note Es gibt keine Garantie, dass der Task weiterhin existiert
*/
virtual CSimulationTask* GetCurrentTask() const;
//! Task retrieval loop
virtual bool LoopBody();
//! Performs compute of given task
virtual void Compute(CSimulationTask* pTask);
//! Preloads geometry
virtual void LoadScene(const std::string& sFilename);
//! Performs reset of instance
virtual void Reset();
//! Get configuration
const CConfiguration::CThreadConfiguration& GetConfiguration() const;
protected:
ITAStopWatch swCompute;
private:
VistaThreadEvent m_evTrigger;
ITAAtomicPtr< CSimulationTask > m_pTask;
CLocalScheduler* m_pParentScheduler;
ISimulationInterface* m_pRavenSimulator;
ITAAtomicBool m_bSceneLoaded;
ITAAtomicBool m_bStop;
ITAAtomicBool m_bIndicateStop;
ITAAtomicBool m_bReset;
ITASampleFrame m_oLatestResult;