Move array extraction to comm module

This commit is contained in:
Jan Eitzinger 2024-01-10 09:42:03 +01:00
parent 1fcddc91b7
commit d53da89b95
2 changed files with 41 additions and 55 deletions

View File

@ -312,11 +312,11 @@ void commCollectResult(Comm* c,
int jmax,
int imax)
{
#if defined(_MPI)
int imaxLocal = c->imaxLocal;
int jmaxLocal = c->jmaxLocal;
int kmaxLocal = c->kmaxLocal;
#if defined(_MPI)
int offset[c->size * NDIMS];
int imaxLocalAll[c->size];
int jmaxLocalAll[c->size];
@ -439,6 +439,46 @@ void commCollectResult(Comm* c,
imax);
free(tmp);
#else
int idx = 0;
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
pg[idx++] = G(s->p, i, j, k);
}
}
}
idx = 0;
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
ug[idx++] = (G(s->u, i, j, k) + G(s->u, i - 1, j, k)) / 2.0;
}
}
}
idx = 0;
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
vg[idx++] = (G(s->v, i, j, k) + G(s->v, i, j - 1, k)) / 2.0;
}
}
}
idx = 0;
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
wg[idx++] = (G(s->w, i, j, k) + G(s->w, i, j, k - 1)) / 2.0;
}
}
}
#endif
}

View File

@ -18,56 +18,6 @@
#include "timing.h"
#include "vtkWriter.h"
#ifndef _MPI
#define G(v, i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
static void createBulkArrays(Solver* s, double* pg, double* ug, double* vg, double* wg)
{
int imax = s->grid.imax;
int jmax = s->grid.jmax;
int kmax = s->grid.kmax;
int idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
pg[idx++] = G(s->p, i, j, k);
}
}
}
idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
ug[idx++] = (G(s->u, i, j, k) + G(s->u, i - 1, j, k)) / 2.0;
}
}
}
idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
vg[idx++] = (G(s->v, i, j, k) + G(s->v, i, j - 1, k)) / 2.0;
}
}
}
idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
wg[idx++] = (G(s->w, i, j, k) + G(s->w, i, j, k - 1)) / 2.0;
}
}
}
}
#endif /* ifndef _MPI */
int main(int argc, char** argv)
{
double timeStart, timeStop;
@ -134,7 +84,6 @@ int main(int argc, char** argv)
wg = allocate(64, bytesize);
}
#ifdef _MPI
commCollectResult(&s.comm,
ug,
vg,
@ -147,9 +96,6 @@ int main(int argc, char** argv)
s.grid.kmax,
s.grid.jmax,
s.grid.imax);
#else
createBulkArrays(&s, pg, ug, vg, wg);
#endif /* ifdef _MPI */
if (commIsMaster(&s.comm)) {
VtkOptions opts = { .grid = s.grid };