首页 > 解决方案 > 如何应用循环平铺?

问题描述

我正在尝试应用代码平铺,但我不太了解它,我看过有关内循环的事情,但我没有任何内循环。谁能给我解释一下?我正在使用 gcc 编译器。

  
  #pragma omp parallel for reduction (+:outputBins)
  for (int i = 0; i < inputData.numDataPoints; i++) { 
    // Transforming from cylindrical to Cartesian coordinates:
    const FTYPE x = inputData.r[i]*COS(inputData.phi[i]);
    const FTYPE y = inputData.r[i]*SIN(inputData.phi[i]);

    // Calculating the bin numbers for these coordinates:
    const int iX = int((x - xMin)*binsPerUnitX);
    const int iY = int((y - yMin)*binsPerUnitY);

    // Incrementing the appropriate bin in the counter
    ++outputBins[iX][iY];
  }
}
/// I tried this, but doent do re correct thing because it messes with paralelization
  const int N = 20000;
  
  #pragma omp parallel for reduction (+:outputBins)
  for (int j=0; j < inputData.numDataPoints; j+=N){

    for (int i = j; i < (j+N); i++) { 
      // Transforming from cylindrical to Cartesian coordinates:
      const FTYPE x = inputData.r[j]*COS(inputData.phi[j]);
      const FTYPE y = inputData.r[j]*SIN(inputData.phi[j]);

      // Calculating the bin numbers for these coordinates:
      const int iX = int((x - xMin)*binsPerUnitX);
      const int iY = int((y - yMin)*binsPerUnitY);

      // Incrementing the appropriate bin in the counter
      ++outputBins[iX][iY];
    }
  }

标签: cloopsgccopenmptiling

解决方案


推荐阅读