c - 如何应用循环平铺?
问题描述
我正在尝试应用代码平铺,但我不太了解它,我看过有关内循环的事情,但我没有任何内循环。谁能给我解释一下?我正在使用 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];
}
}
解决方案
推荐阅读
- c++ - 如何限制 Boost.Asio 内存
- php - 我需要使用另一列中的数据更新一列中的数据
- android - 我们应该在 Firebase 中为 ios 和 Android 使用相同的 google-services.json 吗?
- github - 在 GitHub 中显示另一个 md 文件的内容
- linux - 用 bash 计算五分位数
- javascript - 元组究竟是如何进入特定存储桶的?
- django - 请求时未发送 Cookie
- sql - 每x行选择最大值和最小值-postgresql
- python - Numpy 数组错误地具有相同的值?
- mongodb - Mongodb $group 和 $lookup 聚合