I have this code, but I need help to use OpenMP
Код: Выделить всё
#pragmaКод: Выделить всё
forКод: Выделить всё
iКод: Выделить всё
jКод: Выделить всё
nКод: Выделить всё
mКод: Выделить всё
n = 1000Код: Выделить всё
m = 500My code:
Код: Выделить всё
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
matrix[i][j] = {static_cast(distribution(gen)),
static_cast(distribution(gen))};
}
}
#pragma omp parallel
{
n = 50;
m = 50;
ReS = 0;
ImS = 0;
for (int nu = 0; nu < 1; nu++) {
#pragma omp for num_threads(4)
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;
for (double theta = 0; theta < PI; theta += theta_plus) {
for (double phi = 0; phi < 2 * PI; phi += theta_plus) {
double angle = *matrixPtr * cos(phi) * sin(theta) +
*matrixPtrSecond * sin(phi) * sin(theta);
ReS += cos(angle);
ImS += sin(angle);
}
}
}
}
}
}
Источник: https://stackoverflow.com/questions/781 ... pragma-for