小编rfl*_*500的帖子

在展开的链表上运行大约占代码运行时的40% - 是否有任何明显的优化方法?

我是一个名为vampire(http://github.com/richard-evans/vampire)的开源科学代码的作者,并且计算密集型意味着代码性能的任何改进都可以显着增加可以完成的研究.此代码的典型运行时可能是数百个核心小时,因此我一直在寻找改进代码性能关键部分的方法.但是,我有点陷入以下相对无害的代码中,这占了运行时的40%左右:

for (int atom = start_index; atom < end_index; atom++){
    register double Hx = 0.0;
    register double Hy = 0.0;
    register double Hz = 0.0;
    const int start = atoms::neighbour_list_start_index[atom];
    const int end = atoms::neighbour_list_end_index[atom] + 1;
    for (int nn = start; nn < end; nn++){
        const int natom = atoms::neighbour_list_array[nn];
        const double Jij = atoms::i_exchange_list[atoms::neighbour_interaction_type_array[nn]].Jij;
        Hx -= Jij * atoms::x_spin_array[natom];
        Hy -= Jij * atoms::y_spin_array[natom];
        Hz -= Jij * atoms::z_spin_array[natom];
    }
    atoms::x_total_spin_field_array[atom] += Hx;
    atoms::y_total_spin_field_array[atom] += Hy; …
Run Code Online (Sandbox Code Playgroud)

c++ optimization performance

14
推荐指数
2
解决办法
537
查看次数

标签 统计

c++ ×1

optimization ×1

performance ×1