#include <float.h>
#include <limits.h>
#ifdef _OPENMP
#include <omp.h>    
#endif
#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);
    }
    
    
    int numThreads = 1;
#ifdef _OPENMP
    numThreads = omp_get_max_threads();
#endif
    
    float* pointArray = new float[numThreads*spacing];
    const int nb = vertexArray.
length();
 
    const int nbStep = nb / numThreads;
    
#ifdef _OPENMP
#pragma omp parallel for
#endif
    for(int i=0; i<numThreads; i++) {
        float& minX = pointArray[i*spacing];
        minX = FLT_MAX;
        const int n1 = i*nbStep;
        const int n2 = (i<(numThreads-1)) ? (i+1)*nbStep : nb;
        for  (int n=n1; n<n2; n++) {
            if(p.
x < minX) minX = p.
x;
 
        }
    }
    float finalMinX = FLT_MAX;
    
    
    for(int i=0; i<numThreads; i++) {
        if(pointArray[i*spacing] < finalMinX) finalMinX = pointArray[i*spacing];
    }
    
    
    delete [] pointArray;
    return finalMinX;
}
{
    
    
    
    int numSelected = curSel.
length();
 
    for( int s = 0; s < numSelected; s++ )
    {
        
        
        {
            
            
            cout<<" Error - object is not a polymesh"<<endl;
            return stat;
        }
        
        {
            cout<<" Error - unable to create MFnMesh object"<<endl;
            return stat;
        }
        
        
        
        
        stat = fnMesh.getPoints(vertexArray );
            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;
            return stat;
        }
    }
    
    setResult( "threadedBoundingBox completed." );
    return stat;
}