49 #define patch(p,i,j,k) (cicPatch[p][patchSize[p].y*patchSize[p].z*i+patchSize[p].z*j+k])
92 lowerPatchCorner[p].
x = INT_MAX;
93 lowerPatchCorner[p].
y = INT_MAX;
95 lowerPatchCorner[p].
z = INT_MAX;
97 lowerPatchCorner[p].
z = 0;
98 upperPatchCorner[p].
x = INT_MIN, upperPatchCorner[p].
y = INT_MIN;
100 upperPatchCorner[p].
z = INT_MIN;
102 upperPatchCorner[p].
z = 0;
106 for (p = 0; p <
MPIsize; p++) {
108 for (c = 0; c <
lnc; c++) {
116 for (ax = 0; ax < 2; ax++)
117 for (ay = 0; ay < 2; ay++)
118 for (az = 0; az < 2; az++) {
126 lowerPatchCorner[p].
x =
127 (lowerPatchCorner[p].
x >
128 cellIdx.
x + ax ? cellIdx.
x +
129 ax : lowerPatchCorner[p].
x);
130 lowerPatchCorner[p].
y =
131 (lowerPatchCorner[p].
y >
132 cellIdx.
y + ay ? cellIdx.
y +
133 ay : lowerPatchCorner[p].
y);
135 lowerPatchCorner[p].
z =
136 (lowerPatchCorner[p].
z >
137 cellIdx.
z + az ? cellIdx.
z +
138 az : lowerPatchCorner[p].
z);
139 upperPatchCorner[p].
x =
140 (upperPatchCorner[p].
x <
141 cellIdx.
x + ax ? cellIdx.
x +
142 ax : upperPatchCorner[p].
x);
143 upperPatchCorner[p].
y =
144 (upperPatchCorner[p].
y <
145 cellIdx.
y + ay ? cellIdx.
y +
146 ay : upperPatchCorner[p].
y);
148 upperPatchCorner[p].
z =
149 (upperPatchCorner[p].
z <
150 cellIdx.
z + az ? cellIdx.
z +
151 az : upperPatchCorner[p].
z);
161 patchSize[p].
x = upperPatchCorner[p].
x - lowerPatchCorner[p].
x + 1;
162 patchSize[p].
y = upperPatchCorner[p].
y - lowerPatchCorner[p].
y + 1;
164 patchSize[p].
z = upperPatchCorner[p].
z - lowerPatchCorner[p].
z + 1;
168 (
double *) calloc(patchSize[p].
x * patchSize[p].
y *
169 patchSize[p].
z,
sizeof(
double));
191 for (i = 0; i < patchSize[p].
x; i++)
192 for (j = 0; j < patchSize[p].
y; j++)
193 for (k = 0; k < patchSize[p].
z; k++)
194 patch(p, i, j, k) = 0.0;
196 for (c = 0; c <
lnc; c++) {
202 for (p = 0; p <
MPIsize; p++) {
204 for (ax = 0; ax < 2; ax++)
205 for (ay = 0; ay < 2; ay++)
206 for (az = 0; az < 2; az++) {
214 idx.
x = (cellIdx.
x + ax) - lowerPatchCorner[p].
x;
215 idx.
y = (cellIdx.
y + ay) - lowerPatchCorner[p].
y;
216 idx.
z = (cellIdx.
z + az) - lowerPatchCorner[p].
z;
230 if (
cells[c].phase != 5) {
231 if (
cells[c].phase == 0) {
233 0.75 * (ax * d.
x + (1 - ax) * t.
x) * (ay * d.
y +
236 (az * d.
z + (1 - az) * t.
z);
239 1.0 * (ax * d.
x + (1 - ax) * t.
x) * (ay * d.
y +
242 (az * d.
z + (1 - az) * t.
z);
272 MPI_Alltoall(lowerPatchCorner,
sizeof(
struct int64Vector3d), MPI_BYTE,
275 MPI_Alltoall(upperPatchCorner,
sizeof(
struct int64Vector3d), MPI_BYTE,
279 cicRecvPatch = (
double **) calloc(MPIsize,
sizeof(
double *));
283 for (p = 0; p <
MPIsize; p++) {
286 patchSize[p].
x * patchSize[p].
y * patchSize[p].
z,
292 (upperPatchCornerR[p].
x - lowerPatchCornerR[p].
x +
293 1) * (upperPatchCornerR[p].
y - lowerPatchCornerR[p].
y +
294 1) * (upperPatchCornerR[p].
z - lowerPatchCornerR[p].
z +
296 if (!(
cicRecvPatch[p] = (
double *) calloc(recvSize,
sizeof(
double))))
298 MPI_Irecv(&(
cicRecvPatch[p][0]), recvSize, MPI_DOUBLE, p, p,
314 for (p = 0; p <
MPIsize; p++) {
317 if (MPI_Wait(&
cicReqSend[p], &status) != MPI_SUCCESS)
318 stopRun(103,
"sending", __FILE__, __LINE__);
321 for (p = 0; p <
MPIsize; p++) {
324 if (MPI_Wait(&
cicReqRecv[p], &status) != MPI_SUCCESS)
325 stopRun(103,
"receiving", __FILE__, __LINE__);
347 for (p = 0; p <
MPIsize; p++) {
351 for (i = lowerPatchCornerR[p].
x; i <= upperPatchCornerR[p].
x; i++)
352 for (j = lowerPatchCornerR[p].
y; j <= upperPatchCornerR[p].
y; j++)
353 for (k = lowerPatchCornerR[p].
z; k <= upperPatchCornerR[p].
z; k++) {
355 size.
x = upperPatchCornerR[p].
x - lowerPatchCornerR[p].
x + 1;
356 size.
y = upperPatchCornerR[p].
y - lowerPatchCornerR[p].
y + 1;
357 size.
z = upperPatchCornerR[p].
z - lowerPatchCornerR[p].
z + 1;
358 c.
x = i - lowerPatchCornerR[p].
x;
359 c.
y = j - lowerPatchCornerR[p].
y;
360 c.
z = k - lowerPatchCornerR[p].
z;
408 for (p = 0; p <
MPIsize; p++) {
412 size.
x = upperPatchCornerR[p].
x - lowerPatchCornerR[p].
x + 1;
413 size.
y = upperPatchCornerR[p].
y - lowerPatchCornerR[p].
y + 1;
414 size.
z = upperPatchCornerR[p].
z - lowerPatchCornerR[p].
z + 1;
415 fieldPatchSize = size.
x * size.
y * size.
z;
416 fieldsPatchesCommBuff[p] =
417 (
double *) calloc(
NFIELDS * fieldPatchSize,
sizeof(
double));
418 for (f = 0; f <
NFIELDS; f++) {
420 for (i = lowerPatchCornerR[p].
x; i <= upperPatchCornerR[p].
x; i++)
421 for (j = lowerPatchCornerR[p].
y; j <= upperPatchCornerR[p].
y; j++)
422 for (k = lowerPatchCornerR[p].
z; k <= upperPatchCornerR[p].
z;
424 idx.
x = i - lowerPatchCornerR[p].
x;
425 idx.
y = j - lowerPatchCornerR[p].
y;
426 idx.
z = k - lowerPatchCornerR[p].
z;
430 fieldsPatchesCommBuff[p][f * fieldPatchSize +
431 size.
z * size.
y * idx.
x +
432 size.
z * idx.
y + idx.
z] =
439 if (!(
fieldsPatches = (
double **) calloc(MPIsize,
sizeof(
double *))))
440 stopRun(106,
"fieldsPatches", __FILE__, __LINE__);
445 for (p = 0; p <
MPIsize; p++) {
449 (upperPatchCornerR[p].
x - lowerPatchCornerR[p].
x +
450 1) * (upperPatchCornerR[p].
y - lowerPatchCornerR[p].
y +
451 1) * (upperPatchCornerR[p].
z - lowerPatchCornerR[p].
z +
453 MPI_Isend(&(fieldsPatchesCommBuff[p][0]), sendSize, MPI_DOUBLE, p,
459 patchSize[p].
x * patchSize[p].
y * patchSize[p].
z *
NFIELDS;
461 (
fieldsPatches[p] = (
double *) calloc(recvSize,
sizeof(
double))))
462 stopRun(106,
"fieldsPatches", __FILE__, __LINE__);
463 MPI_Irecv(&(
fieldsPatches[p][0]), recvSize, MPI_DOUBLE, p, p,
480 for (p = 0; p <
MPIsize; p++) {
483 if (MPI_Wait(&
cicReqSend[p], &status) != MPI_SUCCESS)
484 stopRun(103,
"sending", __FILE__, __LINE__);
487 for (p = 0; p <
MPIsize; p++) {
490 if (MPI_Wait(&
cicReqRecv[p], &status) != MPI_SUCCESS)
491 stopRun(103,
"receiving", __FILE__, __LINE__);
512 int p, c, f, i, j, k;
523 for (c = 0; c <
lnc; c++)
526 for (c = 0; c <
lnc; c++) {
530 for (p = 0; p <
MPIsize; p++) {
534 for (ax = 0; ax < 2; ax++)
535 for (ay = 0; ay < 2; ay++)
536 for (az = 0; az < 2; az++) {
544 idx.
x = (cellIdx.
x + ax) - lowerPatchCorner[p].
x;
545 idx.
y = (cellIdx.
y + ay) - lowerPatchCorner[p].
y;
546 idx.
z = (cellIdx.
z + az) - lowerPatchCorner[p].
z;
562 for (f = 0; f <
NFIELDS; f++) {
563 cellFields[f][c] +=
fieldsPatches[p][f * patchSize[p].
x * patchSize[p].
y * patchSize[p].
z + patchSize[p].
y * patchSize[p].
z * idx.
x + patchSize[p].
z * idx.
y + idx.
z] * (ax * d.
x + (1 - ax) * t.
x) * (ay * d.
y + (1 - ay) * t.
y) * (az * d.
z + (1 - az) * t.
z);
640 free(lowerPatchCorner);
641 free(upperPatchCorner);
642 free(lowerPatchCornerR);
643 free(upperPatchCornerR);
void interpolateCellsToGrid()
void initCellsToGridExchange()
struct int64Vector3d * gridEndIdx
void waitFieldsPatchesExchange()
struct int64Vector3d * lowerPatchCorner
void waitCellsToGridExchange()
double ** fieldsPatchesCommBuff
contains the most important global variables, arrays and defines
struct int64Vector3d gridSize
#define patch(p, i, j, k)
struct int64Vector3d * patchSizeR
struct int64Vector3d * gridStartIdx
struct int64Vector3d * upperPatchCorner
struct int64Vector3d * lowerPatchCornerR
struct int64Vector3d * patchSize
struct int64Vector3d * upperPatchCornerR
double * fieldAddr[NFIELDS]
contains variables and arrays for global fields
void applyFieldsPatches()
void initFieldsPatchesExchange()
void interpolateFieldsToCells()
void stopRun(int ierr, char *name, char *file, int line)