我有这样的代码
double ***arrayInit(int nz, int nx, int ny) {
double ***u3d;
u3d = new double **[nz];
for (int k = 0; k < nz; k++) {
u3d[k] = new double *[nx];
for (int i = 0; i < nx; i++) {
u3d[k][i] = new double[ny];
for (int j = 0; j < ny; ++j)
u3d[k][i][j] = 0;
}
}
return u3d;
}
int main(int argc, char *argv[])
{
int size(0);
int rank = 0;
Coefficients coefs; //structure with some coefficients for calculation
map<string, string> config;
coefs = fillCoefficients(config);
auto rho0niz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto T0niz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto p0niz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
for (int k = 0; k < coefs.H1p1; ++k) {
for (int i = 0; i < coefs.Lp1; ++i) {
for (int j = 0; j < coefs.Mp1; ++j) {
rho0niz[k][i][j] =
pow(1.0 - coefs.Lh * (k - 1 + 1) * coefs.h, coefs.nu - 1);
T0niz[k][i][j] =
1.0 - coefs.Lh * (k - 1 + 1) * coefs.h; //Степень +1 к индексу
p0niz[k][i][j] = rho0niz[k][i][j] * T0niz[k][i][j];
}
}
}
auto u0niz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto v0niz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto w0niz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto rhoniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto uniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto vniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto wniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto Tniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto pniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto rhotniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto utniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto vtniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto wtniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto Ttniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
auto ptniz = arrayInit(coefs.H1p1, coefs.Lp1, coefs.Mp1);
for (int k = 0; k < coefs.H1p1; ++k)
for (int i = 0; i < coefs.Lp1; ++i)
for (int j = 0; j < coefs.Mp1; ++j) {
rhoniz[k][i][j] = rho0niz[k][i][j];
uniz[k][i][j] = u0niz[k][i][j];
vniz[k][i][j] = v0niz[k][i][j];
wniz[k][i][j] = w0niz[k][i][j];
Tniz[k][i][j] = T0niz[k][i][j];
pniz[k][i][j] = rho0niz[k][i][j] * T0niz[k][i][j];
rhotniz[k][i][j] = rho0niz[k][i][j];
utniz[k][i][j] = u0niz[k][i][j];
vtniz[k][i][j] = v0niz[k][i][j];
wtniz[k][i][j] = w0niz[k][i][j];
Ttniz[k][i][j] = T0niz[k][i][j];
ptniz[k][i][j] = rho0niz[k][i][j] * T0niz[k][i][j];
}
double rd = 0;
int timestamp_count = 10000;
std::cout << "start" << std::endl;
double utniz_res = -1, vtniz_res = -1, wtniz_res = -1, rhotniz_res = -1, Ttniz_res = -1;
for (int n = 1; n <= timestamp_count; ++n)
{
cout << "=============================== n " << n << endl;
#pragma omp parallel for private(utniz_res, vtniz_res, wtniz_res, rhotniz_res,Ttniz_res)
for (int k = 1; k < coefs.H1; ++k) {
utniz_res = -1;
vtniz_res = -1;
wtniz_res = -1;
rhotniz_res = -1;
Ttniz_res = -1;
for (int i = 1; i < coefs.L; ++i)
{
for (int j = 1; j < coefs.M; ++j)
{
utniz_res = f_u(coefs, uniz, tniz,rhoniz,vniz,wniw,pniz);
vtniz_res = f_v(coefs, uniz, tniz,rhoniz,vniz,wniw,pniz);
wtniz_res = f_w(coefs, uniz, tniz,rhoniz,vniz,wniw,pniz);
rhotniz_res = f_rho(coefs, uniz, tniz,rhoniz,vniz,wniw,pniz);;
Ttniz_res = f_t(coefs, uniz, tniz,rhoniz,vniz,wniw,pniz);
#pragma omp critical
{
utniz[k][i][j] = utniz_res;
vtniz[k][i][j] = vtniz_res;
wtniz[k][i][j] = wtniz_res;
rhotniz[k][i][j] = rhotniz_res;
Ttniz[k][i][j] = Ttniz_res;
}
}
}
}
return 0;
}
但omp parallel并不会创建任何aditional线程。我做错了什么? 当我查看线程数时,我看到1个值。 计算函数取决于存储在附加数组中的先前数据结果。
主要问题:我应该如何定义pragme omp parallel以使用动态数组进行计算。 E.G每个阵列应为50x400x40。