RavenNetSchedulerTest.cpp 5.3 KB
Newer Older
1
2
3
4
5
6
#include <iostream>
#include <string>

#include <ITASimulationScheduler/Raven/RavenNetClient.h>
#include <ITASimulationScheduler/Raven/RavenNetServer.h>

7
8
#include <ITASimulationScheduler/LocalScheduler.h>
#include <ITASimulationScheduler/Utils.h>
9
10
11
12
13
14
15
16
17
18
19
20
21

#include <ITAStringUtils.h>
#include <ITAStopWatch.h>

using namespace std;

void normalize_0dB( ITASampleFrame* );

void test()
{

	std::string sServerName = "localhost";
	unsigned int uiPort = 12480;
22
23
    ITASimulationScheduler::RAVEN::IRavenNetServer::tPortList liFreePorts;
    liFreePorts.push_back( ITASimulationScheduler::RAVEN::IRavenNetServer::tPortRange( uiPort + 1, 12499 ) );
24
25
26
27
28
29

	std::cout << "This is the RavenNet simulation server" << std::endl;
	std::cout << "Waiting for connections to " << sServerName << " on port " << uiPort << std::endl << std::endl;

	// Create and set up Standalone Raven Simulator
	std::string sRavenDataPath = "../../../VAData";
30
    ITASimulationScheduler::CLocalScheduler::CConfiguration oConf;
31
	oConf.sRavenDataBasePath = sRavenDataPath;
32
    ITASimulationScheduler::CLocalScheduler* pScheduler = new ITASimulationScheduler::CLocalScheduler( oConf );
33
34

	// Create server and connect Raven instance
35
36
    ITASimulationScheduler::RAVEN::IRavenNetServer* pServer = ITASimulationScheduler::RAVEN::IRavenNetServer::Create();
    pServer->SetRavenSimulationScheduler( ( ITASimulationScheduler::ISimulationSchedulerInterface* ) pScheduler );
37

38
39
    int err = pServer->Initialize( sServerName, ( int ) uiPort, liFreePorts, ITASimulationScheduler::RAVEN::IRavenNetServer::SCHEDULER );
    if( err != ITASimulationScheduler::RAVEN::IRavenNetServer::RAVEN_NO_ERROR ) {
40
41
42
43
44
45
46
47
48
49
50
51
		std::cout << "Could not initialize Raven simulation server" << std::endl;
	}
	else {
		std::cout << "Successfully initialized Raven simulation server" << std::endl;
	}

	if( pServer->IsRavenSimulationScheduler() )
		std::cout << "Raven simulation server provides scheduler (SchedulerInterface)" << std::endl;
	if( pServer->IsRavenSimulator() )
		std::cout << "Raven simulation server provides (serial) simulator (SimulationInterface)" << std::endl;


52
    ITASimulationScheduler::RAVEN::IRavenNetClient* pClient = ITASimulationScheduler::RAVEN::IRavenNetClient::Create();
53
54
	pClient->Initialize( sServerName );

55
    ITASimulationScheduler::ISimulationSchedulerInterface* pRemoteScheduler = pClient->GetRavenSimulationScheduler();
56
57
58

	pRemoteScheduler->Reset();

59
    ITASimulationScheduler::CSimulationResultDumper oResultDumper( "./Output" );
60
61
	pRemoteScheduler->AttachSimulationResultHandler( &oResultDumper );

62
    ITASimulationScheduler::CSimulationTask oTask;
63
64
65
	oTask.oConfig.oGeometry.sSceneFileName = "$(RavenDataBasePath)/Models/San Juan/SJ Double-Chapel Centered.ac";
	oTask.oConfig.SetDefaults();
	oTask.oScene.AddReceiver( 0 );
66
    ITASimulationScheduler::RAVEN::CSourceState oState;
67
68
69
70
71
72
	oTask.oScene.AddSource( 0 );
	oState.vPos.init( 2, 1.7f, 2 );
	oTask.oScene.SetSourceState( 0, oState );

	unsigned int uiIDCounter = 0;

73
    ITASimulationScheduler::CSimulationTask oTask1( oTask );
74
	oTask1.uiID = uiIDCounter++;
75
    oTask1.iSimulationType = ITASimulationScheduler::CSimulationTask::SIM_DS;
76

77
    ITASimulationScheduler::CSimulationTask oTask2( oTask );
78
	oTask2.uiID = uiIDCounter++;
79
    oTask2.iSimulationType = ITASimulationScheduler::CSimulationTask::SIM_ER_IS;
80

81
    ITASimulationScheduler::CSimulationTask oTask3( oTask );
82
	oTask3.uiID = uiIDCounter++;
83
    oTask3.iSimulationType = ITASimulationScheduler::CSimulationTask::SIM_DD_RT;
84
85
86
87
88
89
90
91
92
93
94

	ITAStopWatch sw1;
	for( int i = 0; i < 10000; i++ )
	{
		oTask1.uiID = uiIDCounter++;
		sw1.start();
		pRemoteScheduler->AddTask( &oTask1 );
		sw1.stop();
	}
	std::cout << "Added 10k DS tasks in " << sw1.ToString() << std::endl;

95
    ITASimulationScheduler::ISimulationSchedulerInterface::CProfiler oProfilerState;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	if( pRemoteScheduler->GetProfilerStatus( oProfilerState ) )
	{
		cout << oProfilerState.oAll.dTaskComputeAvrg << endl;
		cout << oProfilerState.oAll.dTaskTurnaroundDiscarded << endl;
		cout << oProfilerState.oAll.dTaskTurnaroundFinished << endl;
		cout << oProfilerState.oAll.uiTasksDiscarded << endl;
		cout << oProfilerState.oAll.uiTasksFinished << endl;
	}

	ITAStopWatch sw2;
	for( int i = 0; i < 1000; i++ )
	{
		oTask1.uiID = uiIDCounter++;
		sw2.start();
		pRemoteScheduler->AddTask( &oTask2 );
		sw2.stop();
	}
	std::cout << "Added 1k IS tasks in " << sw2.ToString() << std::endl;

	ITAStopWatch sw3;
	for( int i = 0; i < 100; i++ )
	{
		oTask1.uiID = uiIDCounter++;
		sw3.start();
		pRemoteScheduler->AddTask( &oTask2 );
		sw3.stop();
	}
	std::cout << "Added 100 RT tasks in " << sw3.ToString() << std::endl;


	int iAnyKey;
	std::cout << std::endl << "Hit any key then enter to quit" << std::endl << std::endl;
	std::cin >> iAnyKey;

	pRemoteScheduler->DetachSimulationResultHandler( &oResultDumper );

	pServer->Finalize(); // Lscht auch den Simulator/Scheduler
}

int main( int argc, char** argv ) {
	try
	{
		test();
	}
	catch( ITAException& e ) {
		std::cout << e << std::endl;
	}

	return 0;
}

void normalize_0dB( ITASampleFrame* p ) {
	float fGlobalPeak = 0.0f;
	for( int i = 0; i < p->length(); i++ ) {
		ITASampleBuffer& p1 = ( *p )[ 0 ];
		ITASampleBuffer& p2 = ( *p )[ 1 ];
		float fSample1 = p1[ i ];
		float fSample2 = p2[ i ];
		fGlobalPeak = std::max( fGlobalPeak, fSample1 );
		fGlobalPeak = std::max( fGlobalPeak, fSample2 );
	}
	if( fGlobalPeak != 0.0f )
		p->mul_scalar( 1 / fGlobalPeak );
}