mardi 15 août 2017

Iteration over a big std::vector

I have a C++ vector of tuples. The tuples consist of three doubles and one integer. The vector may contain hundreds of thousands of elements. Even using the C++11 for(auto element : vector){} loop, I manage to iterate over no more than about 100k elements. Is there any other solution for iterating over the whole "big" vector (currently 275k elements)? My code:

    for(auto record : rD)
    {
//      Find indices:
        indxSc  = std::get<2>(record) - 1;
        indxSp  = static_cast<int>( std::get<0>(record)/0.3 );
        if(indxSp > 47 )indxSp = 46;
        indxDir = findSector72( std::get<1>(record) );

//      Increment counts in bins
        ++cntSit[indxSc][indxSp][indxDir];
        ++cntSpeed[indxSp];

//      Add reciprocal of wind speed to sum for <1/u>
        valSpeed[indxSp] = valSpeed[indxSp] + 1./( std::get<0>(record) );
    }

Aucun commentaire:

Enregistrer un commentaire