我被告知要寻找循环携带的依赖,但我仍然不清楚其定义以及如何找到它。如果有人可以给我提示或提示。我只需要指明正确的方向。
void Count sort(int a[], int n) {
int i, j, count;
int* temp = malloc(n*sizeof(int));
for (i = 0; i < n; i++) {
count = 0;
for (j = 0; j < n; j++)
if (a[j] < a[i])
count++;
else if (a[j] == a[i] && j < i)
count++;
temp[count] = a[i];
}
memcpy(a, temp, n*sizeof(int));
free(temp);
} /* Count sort */
最佳答案
我不想说显而易见的事情,但是可以[google]搜索“循环携带依赖”。您将获得大约 6000 个结果,但从以下位置开始:https://en.wikipedia.org/wiki/Loop_dependence_analysis
阅读整个页面[很短]以获取术语,然后重点关注具有您想要的定义的“分类”部分(该小节是“循环依赖性”)。
我确实相信,因为您正在访问 a[i]
和 a[j]
和 i!=j
那就是当您获取“循环携带依赖性”(即距离非零)
关于c - 循环携带的依赖性(如果存在的话)在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33358675/