RavenNetSchedulerTest.cpp 4.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>

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

#include <ITASimulationScheduler/Raven/R_RavenLocalScheduler.h>
#include <ITASimulationScheduler/Raven/R_RavenUtils.h>

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

using namespace std;

void normalize_0dB( ITASampleFrame* );

void test()
{

	std::string sServerName = "localhost";
	unsigned int uiPort = 12480;
	IRavenNetServer::tPortList liFreePorts;
	liFreePorts.push_back( IRavenNetServer::tPortRange( uiPort + 1, 12499 ) );

	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";
Pascal Palenda's avatar
Pascal Palenda committed
30
	CLocalScheduler::CConfiguration oConf;
31
	oConf.sRavenDataBasePath = sRavenDataPath;
Pascal Palenda's avatar
Pascal Palenda committed
32
	CLocalScheduler* pScheduler = new CLocalScheduler( oConf );
33
34
35

	// Create server and connect Raven instance
	IRavenNetServer* pServer = IRavenNetServer::Create();
Pascal Palenda's avatar
Pascal Palenda committed
36
	pServer->SetRavenSimulationScheduler( ( ISimulationSchedulerInterface* ) pScheduler );
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

	int err = pServer->Initialize( sServerName, ( int ) uiPort, liFreePorts, IRavenNetServer::SCHEDULER );
	if( err != IRavenNetServer::RAVEN_NO_ERROR ) {
		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;


	IRavenNetClient* pClient = IRavenNetClient::Create();
	pClient->Initialize( sServerName );

Pascal Palenda's avatar
Pascal Palenda committed
55
	ISimulationSchedulerInterface* pRemoteScheduler = pClient->GetRavenSimulationScheduler();
56
57
58
59
60
61

	pRemoteScheduler->Reset();

	CSimulationResultDumper oResultDumper( "./Output" );
	pRemoteScheduler->AttachSimulationResultHandler( &oResultDumper );

Pascal Palenda's avatar
Pascal Palenda committed
62
	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 );
Pascal Palenda's avatar
Pascal Palenda committed
66
	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;

Pascal Palenda's avatar
Pascal Palenda committed
73
	CSimulationTask oTask1( oTask );
74
	oTask1.uiID = uiIDCounter++;
Pascal Palenda's avatar
Pascal Palenda committed
75
	oTask1.iSimulationType = CSimulationTask::SIM_DS;
76

Pascal Palenda's avatar
Pascal Palenda committed
77
	CSimulationTask oTask2( oTask );
78
	oTask2.uiID = uiIDCounter++;
Pascal Palenda's avatar
Pascal Palenda committed
79
	oTask2.iSimulationType = CSimulationTask::SIM_ER_IS;
80

Pascal Palenda's avatar
Pascal Palenda committed
81
	CSimulationTask oTask3( oTask );
82
	oTask3.uiID = uiIDCounter++;
Pascal Palenda's avatar
Pascal Palenda committed
83
	oTask3.iSimulationType = 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;

Pascal Palenda's avatar
Pascal Palenda committed
95
	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 );
}