在一个线程中运行的C中打开MP并行for循环

时间:2017-01-27 21:18:36

标签: c openmp parallel-for

我有一部分代码正在读取结构的2D数组,对它们进行一些数学计算,将结果放入第二个2D数组:

#pragma omp parallel for private (n, i, j) schedule(dynamic)
for(n = 0; n < frames_read; n++){   
    for (i = 0; i < atoms_total; i++)
    {
    for(j = 0; j < atoms_total; j++)
    {

        if (timestep_array[i][n].atom_id == timestep_array[j][m].atom_id)
        {
            // calculates the vector magnitude and stores it in the created array MSD
            double temp1_x = timestep_array[i][n].normalized_x_position + timestep_array[i][n].x_box;
            double temp2_x = timestep_array[j][n+1].normalized_x_position + timestep_array[j][n+1].x_box;
            double temp3_x = temp2_x - temp1_x;
            double temp4_x = temp3_x * box_bound_x;
            double temp5_x = pow(temp4_x, 2);


            double temp1_y = timestep_array[i][n].normalized_y_position + timestep_array[i][n].y_box;
            double temp2_y = timestep_array[j][n+1].normalized_y_position + timestep_array[j][n+1].y_box;
            double temp3_y = temp2_y - temp1_y;
            double temp4_y = temp3_y * box_bound_y;
            double temp5_y = pow(temp4_y, 2);


            double temp1_z = timestep_array[i][n].normalized_z_position + timestep_array[i][n].z_box;
            double temp2_z = timestep_array[j][n+1].normalized_z_position + timestep_array[j][n+1].z_box;
            double temp3_z = temp2_z - temp1_z;
            double temp4_z = temp3_z * box_bound_z;
            double temp5_z = pow(temp4_z, 2);



            double temp = temp5_x + temp5_y + temp5_z;
            double temp2 = sqrt(temp);
            int atom_number = timestep_array[i][n].atom_id;


            MSD[atom_number][n].msd = sqrt(temp2);
            MSD[atom_number][n].atom_type = timestep_array[i][n].atom_type;

            MSD[atom_number][n].time_in_picoseconds = timestep_array[i][n].timestep / picoseconds;


            }


    }

}

}

我已经尝试了很多#pragma语句的组合(包括将更多变量设置为私有。)没有任何结果导致a.out文件运行多个线程。我做错了什么?

0 个答案:

没有答案