void LoadEqualizer::_computeSplit()
{
    LBASSERT( !_history.empty( ));

    const LBFrameData& frameData = _history.front();
    const Compound* compound = getCompound();
    LBLOG( LOG_LB2 ) << "----- balance " << compound->getChannel()->getName()
                    << " using frame " << frameData.first << " tree "
                     << std::endl << _tree;

    // sort load items for each of the split directions
    LBDatas items( frameData.second );
    _removeEmpty( items );

    LBDatas sortedData[3] = { items, items, items };

    if( getMode() == MODE_DB )
    {
        LBDatas& rangeData = sortedData[ MODE_DB ];
        sort( rangeData.begin(), rangeData.end(), _compareRange );
    }
    else
    {
        LBDatas& xData = sortedData[ MODE_VERTICAL ];
        sort( xData.begin(), xData.end(), _compareX );

        LBDatas& yData = sortedData[ MODE_HORIZONTAL ];
        sort( yData.begin(), yData.end(), _compareY );

#ifndef NDEBUG
        for( LBDatas::const_iterator i = xData.begin(); i != xData.end();
             ++i )
        {
            const Data& data = *i;
            LBLOG( LOG_LB2 ) << "  " << data.vp << ", time " << data.time
                             << " (+" << data.assembleTime << ")" << std::endl;
        }
#endif
    }

    const float time = float( _getTotalTime( ));
    LBLOG( LOG_LB2 ) << "Render time " << time << " for "
                     << _tree->resources << " resources" << std::endl;
    if( _tree->resources > 0.f )
        _computeSplit( _tree, time, sortedData, Viewport(), Range( ));
}
void LoadEqualizer::_updateLeaf( Node* node )
{
    const Compound* compound = node->compound;
    const Channel* channel = compound->getChannel();
    LBASSERT( channel );
    const PixelViewport& pvp = channel->getPixelViewport();
    node->resources = compound->isActive() ? compound->getUsage() : 0.f;
    LBLOG( LOG_LB2 ) << channel->getName() << " active " << compound->isActive()
                     << " using " << node->resources << std::endl;
    LBASSERT( node->resources >= 0.f );

    node->maxSize.x() = pvp.w;
    node->maxSize.y() = pvp.h;
    node->boundaryf = getBoundaryf();
    node->boundary2i = getBoundary2i();
    node->resistancef = getResistancef();
    node->resistance2i = getResistance2i();
    if( !compound->hasDestinationChannel( ))
        return;

    const float nResources = _getTotalResources();
    if( getAssembleOnlyLimit() <= nResources - node->resources )
    {
        node->resources = 0.f;
        return; // OPT
    }

    const float time = float( _getTotalTime( ));
    const float assembleTime = float( _getAssembleTime( ));
    if( assembleTime == 0.f || node->resources == 0.f )
        return;

    const float timePerResource = time / ( nResources - node->resources );
    const float renderTime = timePerResource * node->resources ;

    const float clampedAssembleTime = LB_MIN( assembleTime, renderTime );
    const float newTimePerResource = (time + clampedAssembleTime) / nResources;
    node->resources -= ( clampedAssembleTime / newTimePerResource );
    if( node->resources < 0.f ) // may happen due to fp rounding
        node->resources = 0.f;
}
Exemple #3
0
void LoadEqualizer::_updateLeaf( Node* node )
{
    const Compound* compound = node->compound;
    const Channel* channel = compound->getChannel();
    EQASSERT( channel );
    const PixelViewport& pvp = channel->getPixelViewport();
    node->resources = compound->isRunning() ? compound->getUsage() : 0.f;
    EQASSERT( node->resources >= 0.f );

    node->maxSize.x() = pvp.w; 
    node->maxSize.y() = pvp.h; 
    node->boundaryf = _boundaryf;
    node->boundary2i = _boundary2i;
    if( !compound->hasDestinationChannel( ))
        return;

    const float nResources = _getTotalResources();
    if( _assembleOnlyLimit <= nResources - node->resources )
    {
        node->resources = 0.f;
        return; // OPT
    }

    const float time = float( _getTotalTime( ));
    const float assembleTime = float( _getAssembleTime( ));
    if( assembleTime == 0 || node->resources == 0.f )
        return; 

    const float timePerResource = time / ( nResources - node->resources );
    const float renderTime = timePerResource * node->resources ;

    const float clampedAssembleTime = EQ_MIN( assembleTime, renderTime );
    const float newTimePerResource = (time + clampedAssembleTime) / nResources;
    node->resources -= ( clampedAssembleTime / newTimePerResource );
    if( node->resources < 0.f ) // may happen due to fp rounding
        node->resources = 0.f;
}