#include <float.h>
#include <limits.h>
#include <tbb/blocked_range.h>
#include <tbb/parallel_reduce.h>
#include <maya/MIOStream.h>
#include <maya/MSimple.h>
#include <maya/MSelectionList.h>
#include <maya/MGlobal.h>
#include <maya/MFnMesh.h>
#include <maya/MDagPath.h>
#include <maya/MTimer.h>
#include <maya/MFloatPointArray.h>
#include <maya/MThreadUtils.h>
{
    
    const int floatSize = sizeof(float); 
    
    
    
    int spacing = 1;
    if(padding) {
        spacing = 2+(cacheLineSize/floatSize);
    }
    float finalMinX = tbb::parallel_reduce(tbb::blocked_range<int>(0, vertexArray.
length()), 
float(FLT_MAX),
 
        [&](const tbb::blocked_range<int> &br, float myMin) -> float {
        for (int i = br.begin(); i < br.end(); i++) {
            if (p.
x < myMin) myMin = p.
x;
 
        }
        return myMin;
    },
        [&](const float rMin, const float lMin) -> float {
        return rMin < lMin ? rMin : lMin;
    });
    return finalMinX;
}
{
    
    
    
    int numSelected = curSel.
length();
 
    for( int s = 0; s < numSelected; s++ )
    {
        
        
        {
            
            
            cout<<" Error - object is not a polymesh"<<endl;
            stat = MS::kFailure;
            return stat;
        }
        
        if( stat != MS::kSuccess )
        {
            cout<<" Error - unable to create MFnMesh object"<<endl;
            return stat;
        }
        
        
        
        
        stat = fnMesh.getPoints(vertexArray );
        if( stat != MS::kSuccess ) {
            cout<<" Error - unable to retrieve vertices"<<endl;
            return stat;
        }
        float minX1 = 0.0f;
        float minX2 = 0.0f;
        cout<<
"    Poly has "<< vertexArray.
length()<<
" vertices"<<endl;
 
        bool padding = false;
        int numIterations = 100;
        for(int i=0; i<numIterations; i++) {
            minX1 = computeMinX(vertexArray, padding);
        }
        printf(
"Runtime without padding %f\n", timer.
elapsedTime());
 
        padding = true;
        for(int i=0; i<numIterations; i++) {
            minX2 = computeMinX(vertexArray, padding);
        }
        printf(
"Runtime with padding %f\n", timer.
elapsedTime());
 
        
        if(fabs(minX1-minX2)<1e-10) {
            cout << "Boxes match" << endl;
        } else {
            cout << "Boxes do not match" << endl;
            stat = MS::kFailure;
            return stat;
        }
    }
    
    setResult( "threadedBoundingBox completed." );
    return stat;
}