int main(int argc, const char * argv[]) { int run; uint64_t inMax_outSum, i; volatile uint64_t serialSum; Remotery* rmt; rmt_CreateGlobalInstance(&rmt); pETS = enkiNewTaskScheduler(); enkiGetProfilerCallbacks( pETS )->threadStart = threadStartCallback; enkiGetProfilerCallbacks( pETS )->waitStart = waitStartCallback; enkiGetProfilerCallbacks( pETS )->waitStop = waitStopCallback; enkiInitTaskScheduler( pETS ); rmt_SetCurrentThreadName("Main"); pPSumTask = enkiCreateTaskSet( pETS, ParallelSumTaskSetFunc ); pPSumReductionTask = enkiCreateTaskSet( pETS, ParallelReductionSumTaskSet ); for (run = 0; run < RUNS; ++run) { rmt_BeginCPUSample(Run); printf("Run %d.....\n", run); rmt_BeginCPUSample(Parallel); inMax_outSum = SUMS; enkiAddTaskSetToPipe(pETS, pPSumReductionTask, &inMax_outSum, 1); enkiWaitForTaskSet(pETS, pPSumReductionTask); rmt_EndCPUSample(); rmt_BeginCPUSample(Serial); serialSum = 0; for (i = 0; i < SUMS; ++i) { serialSum += i + 1; } rmt_EndCPUSample(); rmt_EndCPUSample(); } enkiDeleteTaskScheduler( pETS ); }
void ParallelReductionSumTaskSet( uint32_t start_, uint32_t end, uint32_t threadnum_, void* pArgs_ ) { rmt_BeginCPUSample(Reduce); ParallelSumTaskSetArgs args; uint64_t sum; uint64_t inMax_outSum, i; inMax_outSum = *(uint64_t*)pArgs_; ParallelSumTaskSetArgsInit( &args ); enkiAddTaskSetToPipe( pETS, pPSumTask, &args, (uint32_t)inMax_outSum); enkiWaitForTaskSet( pETS, pPSumTask ); sum = 0; for( i = 0; i < args.numPartialSums; ++i ) { sum += args.pPartialSums[i]; } free( args.pPartialSums ); *(uint64_t*)pArgs_ = sum; rmt_EndCPUSample(); }
void recursiveFunction(int depth) { rmt_BeginCPUSample(recursive, RMTSF_Recursive); if (depth < 5) { recursiveFunction(depth + 1); } rmt_EndCPUSample(); }
double delay() { int i, end; double j = 0; rmt_BeginCPUSample(delay, 0); for( i = 0, end = rand()/100; i < end; ++i ) { j += sin(i); } recursiveFunction(0); aggregateFunction(); aggregateFunction(); aggregateFunction(); rmt_EndCPUSample(); return j; }
void ParallelSumTaskSetFunc( uint32_t start_, uint32_t end, uint32_t threadnum_, void* pArgs_ ) { rmt_BeginCPUSample(Sum); ParallelSumTaskSetArgs args; uint64_t sum, i; args = *(ParallelSumTaskSetArgs*)pArgs_; sum = args.pPartialSums[threadnum_]; for( i = start_; i < end; ++i ) { sum += i + 1; } args.pPartialSums[threadnum_] = sum; rmt_EndCPUSample(); }
void GameLoopSystem::run() { //Main loop flag bool quit = false; //Event handler SDL_Event e; //Enable text input SDL_StartTextInput(); Uint32 currentTime = SDL_GetTicks(); Uint32 t = 0; Uint32 dt = Uint32(1000.0f / m_targetFrameRate); Uint32 accumulator = dt; do { rmt_ScopedCPUSample(GameLoop, 0); Uint32 newTime = SDL_GetTicks(); Uint32 frameTime = newTime - currentTime; if (frameTime > m_maxFrameTime) { frameTime = m_maxFrameTime; } currentTime = newTime; accumulator += frameTime; m_events->fire<"StartFrame"_sh>(); rmt_BeginCPUSample(Simulate, 0); while (accumulator >= dt) { m_events->fire<"StartSimulate"_sh>(); m_events->fire<SimulateEvent>({float(dt)/1000, float(t)/1000}); //Handle events on queue while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = true; } switch (e.type) { case SDL_WINDOWEVENT: m_events->fire<WindowEvent>({ e }); if (e.window.type == SDL_WINDOWEVENT_RESIZED) { m_events->fire<ResizeWindowEvent>(ResizeWindowEvent{ { e.window.data1, e.window.data2 } }); } break; case SDL_KEYDOWN: case SDL_KEYUP: case SDL_TEXTEDITING: case SDL_TEXTINPUT: m_events->fire<KeyboardEvent>({ e }); break; case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEWHEEL: m_events->fire<MouseEvent>({ e }); break; case SDL_JOYAXISMOTION: case SDL_JOYBALLMOTION: case SDL_JOYHATMOTION: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: case SDL_JOYDEVICEADDED: case SDL_JOYDEVICEREMOVED: m_events->fire<JoystickEvent>({ e }); break; case SDL_CONTROLLERAXISMOTION: case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERDEVICEREMAPPED: m_events->fire<ControllerEvent>({ e }); break; case SDL_FINGERDOWN: case SDL_FINGERUP: case SDL_FINGERMOTION: m_events->fire<TouchEvent>({ e }); break; } } m_audio->update(); t += dt; accumulator -= dt; } rmt_EndCPUSample(); rmt_BeginCPUSample(PrepareDraw, 0); const double alpha = double(accumulator) / dt; m_events->fire<PrepareDrawEvent>({ alpha, float(t) / 1000 }); rmt_EndCPUSample(); rmt_BeginCPUSample(Draw, 0); m_events->fire<DrawEvent>({ alpha, float(t) / 1000 }); rmt_EndCPUSample(); rmt_BeginCPUSample(Swap, 0); m_window->swap(); rmt_EndCPUSample(); rmt_BeginCPUSample(EndFrame, 0); m_events->fire<"EndFrame"_sh>(); rmt_EndCPUSample(); } // Check if the window was closed while (!quit); }
void waitStopCallback( uint32_t threadnum_ ) { rmt_EndCPUSample(); }
void aggregateFunction() { rmt_BeginCPUSample(aggregate, RMTSF_Aggregate); rmt_EndCPUSample(); }