This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavefieldmpi.c
156 lines (137 loc) · 4.98 KB
/
wavefieldmpi.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "wavefieldmpi.h"
void wavefieldmpi__perfect_match_layer_by_domain(
wavefield *wave,
velocity_model *model,
laplacian_params *lp,
domain_info *domain)
{
size_t pos;
// Left
if(domain->horizontal_position == LEFT) {
for(size_t iz = 0; iz < wave->nz; iz++) {
for(size_t ix = 0; ix < lp->border_size; ix++) {
pos = wave->nx * iz + ix;
wave->grid_o[pos] = wave->grid[pos] +
model->vel[pos] * lp->dt_dx * (wave->grid[pos+1] - wave->grid[pos]);
}
}
}
// Right
if(domain->horizontal_position == RIGHT) {
for(size_t iz = 0; iz < wave->nz; iz++) {
for(size_t ix = (wave->nx - lp->border_size); ix < wave->nx; ix++) {
pos = wave->nx * iz + ix;
wave->grid_o[pos] = wave->grid[pos] -
model->vel[pos] * lp->dt_dx * (wave->grid[pos] - wave->grid[pos-1]);
}
}
}
// Bottom
if(domain->vertical_position == BOTTOM) {
for(size_t iz = (wave->nz - lp->border_size); iz < wave->nz; iz++) {
for(size_t ix = 0; ix < wave->nx; ix++) {
pos = wave->nx * iz + ix;
wave->grid_o[pos] = wave->grid[pos] -
model->vel[pos] * lp->dt_dx * (wave->grid[pos] - wave->grid[pos-model->nx]);
}
}
}
}
void wavefieldmpi__share_border_by_domain(wavefield *wave, laplacian_params *lp, domain_info *d)
{
MPI_Status status;
size_t border_size;
double *buf;
size_t nelem;
size_t i;
size_t pos;
if(d->left_rank != -1) {
nelem = d->stencil_size_x * wave->nz;
buf = malloc(nelem * sizeof(double));
//send border to left
i = 0;
for(size_t iz = 0; iz < wave->nz; iz++) {
for(size_t ix=0; ix< d->stencil_size_x; ix++) {
pos = wave->nx * iz + ix;
buf[i++] = wave->grid[pos];
}
}
MPI_Send(buf, nelem, MPI_DOUBLE, d->left_rank, 0, MPI_COMM_WORLD);
//expect border from left
i = 0;
MPI_Recv(buf, nelem, MPI_DOUBLE, d->left_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(size_t iz = 0; iz < wave->nz; iz++) {
for(size_t ix=0; ix< d->stencil_size_x; ix++) {
pos = wave->nx * iz + ix;
wave->grid_o[pos] = buf[i++];
}
}
}
if(d->right_rank != -1) {
nelem = d->stencil_size_x * wave->nz;
buf = malloc(nelem * sizeof(double));
//expect border from right
i = 0;
MPI_Recv(buf, nelem, MPI_DOUBLE, d->right_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(size_t iz = 0 ; iz < wave->nz; iz++) {
for(size_t ix = wave->nx - d->stencil_size_x ; ix < wave->nx; ix++) {
pos = wave->nx * iz + ix;
wave->grid_o[pos] = buf[i++];
}
}
//send border to right
i = 0;
for(size_t iz = 0 ; iz < wave->nz; iz++) {
for(size_t ix = wave->nx - d->stencil_size_x ; ix< wave->nx; ix++) {
pos = wave->nx * iz + ix;
buf[i++] = wave->grid[pos];
}
}
MPI_Send(buf, nelem, MPI_DOUBLE, d->right_rank, 0, MPI_COMM_WORLD);
}
if(d->upper_rank != -1) {
nelem = d->stencil_size_z * wave->nx;
buf = malloc(nelem * sizeof(double));
//send border to up
i = 0;
for(size_t iz=0 ; iz < d->stencil_size_z; iz++) {
for(size_t ix = 0; ix < wave->nx; ix++) {
pos = wave->nx * iz + ix;
buf[i++] = wave->grid[pos];
}
}
MPI_Send(buf, nelem, MPI_DOUBLE, d->upper_rank, 0, MPI_COMM_WORLD);
//expect border from up
i = 0;
MPI_Recv(buf, nelem, MPI_DOUBLE, d->upper_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(size_t iz=0 ; iz < d->stencil_size_z; iz++) {
for(size_t ix = 0; ix < wave->nx; ix++) {
pos = wave->nx * iz + ix;
wave->grid_o[pos] = buf[i++];
}
}
}
if(d->lower_rank != -1) {
nelem = d->stencil_size_z * wave->nx;
buf = malloc(nelem * sizeof(double));
//send boerder to down
i = 0;
for(size_t iz= wave->nz - d->stencil_size_z; iz < wave->nz; iz++) {
for(size_t ix = 0; ix < wave->nx; ix++) {
pos = wave->nx * iz + ix;
buf[i++] = wave->grid[pos];
}
}
MPI_Send(buf, nelem, MPI_DOUBLE, d->lower_rank, 0, MPI_COMM_WORLD);
//expect border from down
i = 0;
MPI_Recv(buf, nelem, MPI_DOUBLE, d->lower_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(size_t iz= wave->nz - d->stencil_size_z; iz < wave->nz; iz++) {
for(size_t ix = 0; ix < wave->nx; ix++) {
pos = wave->nx * iz + ix;
wave->grid_o[pos] = buf[i++];
}
}
}
free(buf);
}