在一个线程中运行的C中的openmp并行for循环

在一个线程中运行的C中的openmp并行for循环,c,openmp,parallel-for,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

我有一段代码,它读取一个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;


            }


    }

}
#专用(n,i,j)计划的pragma omp并行(动态)
对于(n=0;n
}


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

您是否正确编译,使用了正确的语法来启用
openmp
?让我们具体了解您使用的编译器。上次我检查了GCC4.3.4,编译时需要执行
-fopenmp
。如果您使用的是英特尔编译器,则此语法不相同。我尝试过使用“gcc-6-fopenmp”和“clang-openmp”
#pragma omp
而不是
#pragma opm
,这是一个愚蠢的键入lol。仍然只有一个线程:(您是否设置了OMP_NUM_线程?您是否正确编译,是否使用了启用
openmp
的正确语法?请明确告诉我们您使用的编译器。上次我检查了gcc 4.3.4,编译时您需要执行
-fopenmp
。如果您使用的是英特尔编译器,则此语法不同。我尝试过使用“gcc-6”-fopenmp'和'clang-openmp'
#pragma omp
不是
#pragma opm
这是一个愚蠢的打字错误。仍然只有一个线程。:(你设置了omp#u NUM(线程数)?