       globalBmus[i]=bmus[i];
     }
 #endif
+    delete [] bmus;
     delete [] localNumerator;
     delete [] localDenominator;
 }

 * @param nVectorsPerRank - the number of data points assigned to this GPU
 */

void getBmusOnGpu(int *bmus, float *codebook, int nSomX, int nSomY, int nDimensions, int nVectorsPerRank)
{
    deviceCodebook = thrust::device_vector<float>(codebook, codebook+nSomX*nSomY*nDimensions);
    deviceCodebookNorms = normsOfRowSpace<float>(deviceCodebook, nSomX*nSomY, nDimensions);
    thrust::device_vector<float> deviceGramMatrix(nSomX*nSomY*nVectorsPerRank, 0);

    //Calculate the inner products of the data vectors and the weight vectors

    float alpha = 1.0f;

#ifdef _WIN32
	int* bmus = (int *)alloca(sizeof(int) * nVectorsPerRank * 2);
#else
    unsigned int *bmus = new unsigned int[nVectorsPerRank*2];
#endif
    getBmusOnGpu(bmus, codebook, nSomX, nSomY, nDimensions, nVectorsPerRank);
    float *localNumerator = new float[nSomY*nSomX*nDimensions];
    float *localDenominator = new float[nSomY*nSomX];

