g++ 优化中断 for 循环
g++ optimization breakes for loop
所以,我这里有这个代码片段
for (int t = WILSON_TEMPORAL_START, t_i = 0; t <= WILSON_TEMPORAL_END; t++, t_i++)
{
for (int r = WILSON_SPATIAL_START, r_i = 0; r <= WILSON_SPATIAL_END; r++, r_i++)
{
std::cout << r << " " << WILSON_SPATIAL_END << std::endl;
wilson_loop[conf_id][t_i][r_i] = compute_wilson_loop(t, r, iu1, iu2);
}
}
我运行我的g++编译器有两个不同的优化版本-O1
和-O2
,但是终端输出不同。
和-O1
2 12
3 12
4 12
5 12
6 12
7 12
8 12
9 12
10 12
11 12
12 12
2 12
3 12
4 12
...
和-O2
2 12
3 12
4 12
5 12
6 12
7 12
8 12
9 12
10 12
11 12
12 12
13 12
14 12
15 12
...
如果我将内部循环更改为:
,则代码可以正常工作
for (int t = WILSON_TEMPORAL_START, t_i = 0; t <= WILSON_TEMPORAL_END; t++, t_i++)
{
for (int r = WILSON_SPATIAL_START, r_i = 0; r <= WILSON_SPATIAL_END; r++, r_i++)
{
std::cout << r << " " << WILSON_SPATIAL_END << std::endl;
// wilson_loop[conf_id][t_i][r_i] =
compute_wilson_loop(t, r, iu1, iu2);
}
}
一些有用的定义是:
static double compute_wilson_loop(int time_extend, int space_extend, SUN_mat iu1[VOL][DIM], SUN_mat iu2[VOL][DIM])
void wilson::measure_wilson_loop(SUN_mat pu[VOL][DIM], double wilson_loop[CLEN][TLEN][SLEN], int conf_id) {
...
}
我知道,我可以在这里找到解决方法,但我真的很想了解为什么会这样。
我刚刚解决了这个问题,我在定义预处理器常量时出错了。我仍然不确定,为什么它在使用不同的优化模式时会更改输出,但现在可以使用了:)
所以,我这里有这个代码片段
for (int t = WILSON_TEMPORAL_START, t_i = 0; t <= WILSON_TEMPORAL_END; t++, t_i++)
{
for (int r = WILSON_SPATIAL_START, r_i = 0; r <= WILSON_SPATIAL_END; r++, r_i++)
{
std::cout << r << " " << WILSON_SPATIAL_END << std::endl;
wilson_loop[conf_id][t_i][r_i] = compute_wilson_loop(t, r, iu1, iu2);
}
}
我运行我的g++编译器有两个不同的优化版本-O1
和-O2
,但是终端输出不同。
和-O1
2 12
3 12
4 12
5 12
6 12
7 12
8 12
9 12
10 12
11 12
12 12
2 12
3 12
4 12
...
和-O2
2 12
3 12
4 12
5 12
6 12
7 12
8 12
9 12
10 12
11 12
12 12
13 12
14 12
15 12
...
如果我将内部循环更改为:
,则代码可以正常工作for (int t = WILSON_TEMPORAL_START, t_i = 0; t <= WILSON_TEMPORAL_END; t++, t_i++)
{
for (int r = WILSON_SPATIAL_START, r_i = 0; r <= WILSON_SPATIAL_END; r++, r_i++)
{
std::cout << r << " " << WILSON_SPATIAL_END << std::endl;
// wilson_loop[conf_id][t_i][r_i] =
compute_wilson_loop(t, r, iu1, iu2);
}
}
一些有用的定义是:
static double compute_wilson_loop(int time_extend, int space_extend, SUN_mat iu1[VOL][DIM], SUN_mat iu2[VOL][DIM])
void wilson::measure_wilson_loop(SUN_mat pu[VOL][DIM], double wilson_loop[CLEN][TLEN][SLEN], int conf_id) {
...
}
我知道,我可以在这里找到解决方法,但我真的很想了解为什么会这样。
我刚刚解决了这个问题,我在定义预处理器常量时出错了。我仍然不确定,为什么它在使用不同的优化模式时会更改输出,但现在可以使用了:)