-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelperFunctions.c
51 lines (48 loc) · 2.3 KB
/
HelperFunctions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "mpi.h"
//Make grid point computations
void ComputeInnerPoints(int x_interval[],int y_interval[],int z_interval[], int iter, double delta_sq,int FrobCheckFreq, double *FrobNorm, double ***f,double *** u, int redFlag){
double u_tmp;
double h = 1.0/6;
for(int i=x_interval[0]; i<x_interval[1];i++){ //x
for(int j=z_interval[0]; j<z_interval[1];j++){ //z
for(int k=y_interval[0]; k<y_interval[1];k++){ //y
//Gauss-seidel iteration
if( (i+j+k) % 2 == redFlag){
if (iter % FrobCheckFreq == 0){
u_tmp = u[i][j][k];
u[i][j][k] = h*(u[i-1][j][k] + u[i+1][j][k] + u[i][j-1][k] + u[i][j+1][k] + u[i][j][k-1] + u[i][j][k+1] + delta_sq*f[i][j][k]);
*FrobNorm += (u[i][j][k] - u_tmp) * (u[i][j][k] - u_tmp);
} else{
u[i][j][k] = h*(u[i-1][j][k] + u[i+1][j][k] + u[i][j-1][k] + u[i][j+1][k] + u[i][j][k-1] + u[i][j][k+1] + delta_sq*f[i][j][k]);
}
}
}
}
}
}
//Send & Recieve Messages
void SendRecieve(int neigh[],int n,int N,int iter,MPI_Request requests[],double ***u, MPI_Datatype send){
if (neigh[0] != -1){
// send and recieve above
MPI_Irecv(&(u[1][0][1]), 1, send, neigh[0], iter, MPI_COMM_WORLD,&requests[0]);
MPI_Isend(&(u[1][1][1]), 1, send, neigh[0], iter, MPI_COMM_WORLD,&requests[1]);
}
if (neigh[1] != -1){
// send and recieve left
MPI_Irecv(&(u[0][1][0]), (n-2)*N, MPI_DOUBLE, neigh[1], iter, MPI_COMM_WORLD,&requests[2]);
MPI_Isend(&(u[1][1][0]), (n-2)*N, MPI_DOUBLE, neigh[1], iter, MPI_COMM_WORLD,&requests[3]);
}
if (neigh[2] != -1){
// send and recieve right
MPI_Irecv(&(u[n-1][1][0]), (n-2)*N, MPI_DOUBLE, neigh[2], iter, MPI_COMM_WORLD,&requests[4]);
MPI_Isend(&(u[n-2][1][0]), (n-2)*N, MPI_DOUBLE, neigh[2], iter, MPI_COMM_WORLD,&requests[5]);
}
if (neigh[3] != -1){
// send and recieve below
MPI_Irecv(&(u[1][n-1][1]), 1, send, neigh[3], iter, MPI_COMM_WORLD,&requests[6]);
MPI_Isend(&(u[1][n-2][1]), 1, send, neigh[3], iter, MPI_COMM_WORLD,&requests[7]);
}
}