-
Notifications
You must be signed in to change notification settings - Fork 2
/
pack_kernel_c.c
200 lines (169 loc) · 5.42 KB
/
pack_kernel_c.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*Crown Copyright 2012 AWE.
*
* This file is part of CloverLeaf.
*
* CloverLeaf is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* CloverLeaf is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* CloverLeaf. If not, see http://www.gnu.org/licenses/. */
/**
* @brief C mpi buffer packing kernel
* @author Wayne Gaudin
* @details Packs/unpacks mpi send and receive buffers
*/
#include <stdio.h>
#include <stdlib.h>
#include "ftocmacros.h"
#include <math.h>
void pack_left_right_buffers_c_(int *xmin,int *xmax,int *ymin,int *ymax,
int *chnk_lft,int *chnk_rght,int *xtrnl_fc,
int *xinc,int *yinc,int *dpth,int *sz,
double *field, double *left_snd_buffer, double *right_snd_buffer)
{
int x_min=*xmin;
int x_max=*xmax;
int y_min=*ymin;
int y_max=*ymax;
int chunk_left=*chnk_lft;
int chunk_right=*chnk_rght;
int external_face=*xtrnl_fc;
int x_inc=*xinc;
int y_inc=*yinc;
int depth=*dpth;
int j,k,index;
{
if(chunk_left!=external_face) {
for (k=y_min-depth;k<=y_max+y_inc+depth;k++) {
#pragma ivdep
for (j=1;j<=depth;j++) {
index=j+(k+depth-1)*depth;
left_snd_buffer[FTNREF1D(index,1)]=field[FTNREF2D(x_min+x_inc-1+j,k,x_max+4+x_inc,x_min-2,y_min-2)];
}
}
}
if(chunk_right!=external_face) {
for (k=y_min-depth;k<=y_max+y_inc+depth;k++) {
#pragma ivdep
for (j=1;j<=depth;j++) {
index=j+(k+depth-1)*depth;
right_snd_buffer[FTNREF1D(index,1)]=field[FTNREF2D(x_max+1-j,k,x_max+4+x_inc,x_min-2,y_min-2)];
}
}
}
}
}
void unpack_left_right_buffers_c_(int *xmin,int *xmax,int *ymin,int *ymax,
int *chnk_lft,int *chnk_rght,int *xtrnl_fc,
int *xinc,int *yinc,int *dpth,int *sz,
double *field, double *left_rcv_buffer, double *right_rcv_buffer)
{
int x_min=*xmin;
int x_max=*xmax;
int y_min=*ymin;
int y_max=*ymax;
int chunk_left=*chnk_lft;
int chunk_right=*chnk_rght;
int external_face=*xtrnl_fc;
int x_inc=*xinc;
int y_inc=*yinc;
int depth=*dpth;
int j,k,index;
{
if(chunk_left!=external_face) {
for (k=y_min-depth;k<=y_max+y_inc+depth;k++) {
#pragma ivdep
for (j=1;j<=depth;j++) {
index=j+(k+depth-1)*depth;
field[FTNREF2D(x_min-j,k,x_max+4+x_inc,x_min-2,y_min-2)]=left_rcv_buffer[FTNREF1D(index,1)];
}
}
}
if(chunk_right!=external_face) {
for (k=y_min-depth;k<=y_max+y_inc+depth;k++) {
#pragma ivdep
for (j=1;j<=depth;j++) {
index=j+(k+depth-1)*depth;
field[FTNREF2D(x_max+x_inc+j,k,x_max+4+x_inc,x_min-2,y_min-2)]=right_rcv_buffer[FTNREF1D(index,1)];
}
}
}
}
}
void pack_top_bottom_buffers_c_(int *xmin,int *xmax,int *ymin,int *ymax,
int *chnk_bttm,int *chnk_tp,int *xtrnl_fc,
int *xinc,int *yinc,int *dpth,int *sz,
double *field, double *bottom_snd_buffer, double *top_snd_buffer)
{
int x_min=*xmin;
int x_max=*xmax;
int y_min=*ymin;
int y_max=*ymax;
int chunk_top=*chnk_tp;
int chunk_bottom=*chnk_bttm;
int external_face=*xtrnl_fc;
int x_inc=*xinc;
int y_inc=*yinc;
int depth=*dpth;
int j,k,index;
{
if(chunk_bottom!=external_face) {
for (k=1;k<=depth;k++) {
for (j=x_min-depth;j<=x_max+x_inc+depth;j++) {
index=j+depth+(k-1)*(x_max+x_inc+(2*depth));
bottom_snd_buffer[FTNREF1D(index,1)]=field[FTNREF2D(j,y_min+y_inc-1+k,x_max+4+x_inc,x_min-2,y_min-2)];
}
}
}
if(chunk_top!=external_face) {
for (k=1;k<=depth;k++) {
for (j=x_min-depth;j<=x_max+x_inc+depth;j++) {
index=j+depth+(k-1)*(x_max+x_inc+(2*depth));
top_snd_buffer[FTNREF1D(index,1)]=field[FTNREF2D(j,y_max+1-k,x_max+4+x_inc,x_min-2,y_min-2)];
}
}
}
}
}
void unpack_top_bottom_buffers_c_(int *xmin,int *xmax,int *ymin,int *ymax,
int *chnk_bttm,int *chnk_tp,int *xtrnl_fc,
int *xinc,int *yinc,int *dpth,int *sz,
double *field, double *bottom_rcv_buffer, double *top_rcv_buffer)
{
int x_min=*xmin;
int x_max=*xmax;
int y_min=*ymin;
int y_max=*ymax;
int chunk_top=*chnk_tp;
int chunk_bottom=*chnk_bttm;
int external_face=*xtrnl_fc;
int x_inc=*xinc;
int y_inc=*yinc;
int depth=*dpth;
int j,k,index;
{
if(chunk_bottom!=external_face) {
for (k=1;k<=depth;k++) {
for (j=x_min-depth;j<=x_max+x_inc+depth;j++) {
index=j+depth+(k-1)*(x_max+x_inc+(2*depth));
field[FTNREF2D(j,y_min-k,x_max+4+x_inc,x_min-2,y_min-2)]=bottom_rcv_buffer[FTNREF1D(index,1)];
}
}
}
if(chunk_top!=external_face) {
for (k=1;k<=depth;k++) {
for (j=x_min-depth;j<=x_max+x_inc+depth;j++) {
index=j+depth+(k-1)*(x_max+x_inc+(2*depth));
field[FTNREF2D(j,y_max+y_inc+k,x_max+4+x_inc,x_min-2,y_min-2)]=top_rcv_buffer[FTNREF1D(index,1)];
}
}
}
}
}