Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/niklwors/OMCompiler
- Loading branch information
Showing
13 changed files
with
226 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
SimulationRuntime/cpp/Include/Core/DataExchange/DefaultContainerManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
/** @addtogroup dataexchange | ||
* | ||
* @{ | ||
*/ | ||
#include <Core/Modelica.h> | ||
#include <Core/ModelicaDefine.h> | ||
|
||
/** | ||
* A container manager that is designed for single threaded write output. It has just one container that can | ||
* be filled with values and written directly. | ||
*/ | ||
class DefaultContainerManager : public Writer | ||
{ | ||
private: | ||
write_data_t _container; | ||
|
||
protected: | ||
/** | ||
* Write the given container to the result file. | ||
* @param container The container that should be written. | ||
*/ | ||
void writeContainer(const write_data_t& container) | ||
{ | ||
write(get<0>(container),get<1>(container)); | ||
} | ||
|
||
public: | ||
DefaultContainerManager() : | ||
_container() | ||
{ | ||
} | ||
|
||
virtual ~DefaultContainerManager() | ||
{ | ||
} | ||
/** | ||
* Get the internal container. It is always the same. | ||
* @return A reference to the internal container that can be filled with values. | ||
*/ | ||
write_data_t& getFreeContainer() | ||
{ | ||
return _container; | ||
}; | ||
/** | ||
* Write the given container to the result file. | ||
* @param container The container that should be written. | ||
*/ | ||
void addContainerToWriteQueue(const write_data_t& container) | ||
{ | ||
writeContainer(container); | ||
}; | ||
}; | ||
/** @} */ // end of dataexchange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
SimulationRuntime/cpp/Include/Core/DataExchange/FactoryPolicy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** @addtogroup dataexchange | ||
* | ||
* @{ | ||
*/ | ||
#if defined USE_PARALLEL_OUTPUT && defined USE_BOOST_THREAD | ||
#include <Core/DataExchange/ParallelContainerManager.h> | ||
typedef ParallelContainerManager ContainerManager; | ||
#else | ||
#include <Core/DataExchange/DefaultContainerManager.h> | ||
typedef DefaultContainerManager ContainerManager; | ||
#endif | ||
/** @} */ |
101 changes: 101 additions & 0 deletions
101
SimulationRuntime/cpp/Include/Core/DataExchange/ParallelContainerManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#pragma once | ||
/** @addtogroup dataexchange | ||
* | ||
* @{ | ||
*/ | ||
#include <Core/Modelica.h> | ||
#include <Core/ModelicaDefine.h> | ||
|
||
#define CONTAINER_COUNT 3 | ||
|
||
/** | ||
* This container manager is designed to write simulation results in parallel. It has multiple data containers that | ||
* can be filled with values. The write routine works asynchronously with the help of a consumer-producer-queue. | ||
*/ | ||
class ParallelContainerManager : public Writer | ||
{ | ||
private: | ||
deque<write_data_t > _writeContainers; | ||
deque<write_data_t > _freeContainers; | ||
semaphore _freeContainerMutex; | ||
semaphore _writeContainerMutex; | ||
semaphore _nempty; | ||
thread _writerThread; | ||
bool _threadWorkDone; | ||
|
||
protected: | ||
void writeThread() | ||
{ | ||
std::cerr << "Parallel writer thread used" << std::endl; | ||
while(!_threadWorkDone) | ||
writeContainer(); | ||
|
||
while(!_writeContainers.empty()) | ||
writeContainer(); | ||
} | ||
|
||
void writeContainer() | ||
{ | ||
const write_data_t* container; | ||
|
||
_writeContainerMutex.wait(); | ||
if (!_writeContainers.empty()) | ||
container = &_writeContainers.front(); | ||
|
||
_writeContainerMutex.post(); | ||
|
||
if (!container) | ||
{ | ||
usleep(5); | ||
return; | ||
} | ||
|
||
write(get<0>(*container),get<1>(*container)); | ||
|
||
_writeContainerMutex.wait(); | ||
_writeContainers.pop_front(); | ||
_writeContainerMutex.post(); | ||
|
||
_freeContainerMutex.wait(); | ||
_freeContainers.push_back(*container); | ||
_freeContainerMutex.post(); | ||
_nempty.post(); | ||
} | ||
|
||
public: | ||
ParallelContainerManager() : Writer() | ||
, _writeContainers() | ||
,_freeContainers() | ||
,_freeContainerMutex(1) | ||
,_writeContainerMutex(1) | ||
,_nempty(CONTAINER_COUNT) | ||
,_writerThread(&ParallelContainerManager::writeThread, this) | ||
,_threadWorkDone(false) | ||
{ | ||
} | ||
|
||
virtual ~ParallelContainerManager() | ||
{ | ||
_threadWorkDone = true; | ||
_writerThread.join(); | ||
} | ||
|
||
write_data_t& getFreeContainer() | ||
{ | ||
_nempty.wait(); | ||
_freeContainerMutex.wait(); | ||
|
||
write_data_t& container = _freeContainers.front(); | ||
_freeContainers.pop_front(); | ||
_freeContainerMutex.post(); | ||
|
||
return container; | ||
}; | ||
|
||
void addContainerToWriteQueue(const write_data_t& container) | ||
{ | ||
_writeContainers.push_back(container); | ||
}; | ||
}; | ||
/** @} */ // end of dataexchange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.