#pragma omp for/parallel problems

36 Views Asked by At
for (int nu = 0; nu < 20; nu++) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            double matrixPtr = matrix[i][j].first;
            double matrixPtrSecond = matrix[i][j].second;
            double localReS1 = 0.0;
            double localImS1 = 0.0;
            for (double theta = 0; theta < 2 * M_PI; theta += theta_plus) {
                for (double phi = 0; phi < M_PI; phi += theta_plus) {
                    double angle = matrixPtr * cosPhi * sintheta +
                                   matrixPtrSecond * sinPhi * sintheta;
                    localReS1 += cos(angle);
                    localImS1 += sin(angle);
                }
            }

#pragma omp critical
            {
                ReS += localReS1;
                ImS += localImS1;
            }
        }
    }
}

You can see my code above, please help me, how can I parallelize the Phi and theta loops, because they eat a lot of space, and they must be inside the i,j loops, the nu loop cannot be removed, it must always be present. If you have any ideas how to speed up this code by a factor of 2 at least, I would be glad to hear your answers. I haven't tried parallelizing on CUDA yet, because I'm trying to solve the problem without it, in the extreme case I'll probably do it with its application.

0

There are 0 best solutions below