-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpi_exchange_boundaries.cpp
131 lines (96 loc) · 4.09 KB
/
mpi_exchange_boundaries.cpp
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
/*
* This file is part of the JIMWLK numerical solution package (https://github.com/piotrkorcyl/jimwlk).
* Copyright (c) 2020 P. Korcyl
*
* This program 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, version 3.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* File: mpi_exchange_boundaries.cpp
* Authors: P. Korcyl
* Contact: piotr.korcyl@uj.edu.pl
*
* Version: 1.0
*
* Description:
* Functionality for exchanging boundary data between neighbouring MPI ranks, not used at the moment
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include "config.h"
#include "mpi_pos.h"
#include "field.h"
template<class T> int field<T>::mpi_exchange_boundaries(void){
int size, rank;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
double *bufor_send_n;
double *bufor_receive_n;
double *bufor_send_p;
double *bufor_receive_p;
if( ExchangeX == 1 ){
int yy;
bufor_send_n = (double*) malloc(Nyl_buf*sizeof(double));
bufor_receive_n = (double*) malloc(Nyl_buf*sizeof(double));
for(yy = 0; yy < Nyl; yy++){
bufor_send_n[yy] = u[buf_pos(Nxl-1,yy)];
}
printf("X data exchange: rank %i sending to %i\n", rank, XNeighbourNext);
printf("X data exchange: rank %i receiving from %i\n", rank, XNeighbourNext);
MPI_Send(bufor_send_n, Nyl_buf, MPI_DOUBLE, XNeighbourNext, 11, MPI_COMM_WORLD);
MPI_Recv(bufor_receive_n, Nyl_buf, MPI_DOUBLE, XNeighbourPrevious, 11, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(yy = 0; yy < Nyl; yy++){
u[buf_pos_ex(0,yy)] = bufor_receive_n[yy];
}
bufor_send_p = (double*) malloc(Nyl_buf*sizeof(double));
bufor_receive_p = (double*) malloc(Nyl_buf*sizeof(double));
for(yy = 0; yy < Nyl; yy++){
bufor_send_p[yy] = u[buf_pos(0,yy)];
}
printf("X data exchange: rank %i sending to %i\n", rank, XNeighbourPrevious);
printf("X data exchange: rank %i receiving to %i\n", rank, XNeighbourPrevious);
MPI_Send(bufor_send_p, Nyl_buf, MPI_DOUBLE, XNeighbourPrevious, 12, MPI_COMM_WORLD);
MPI_Recv(bufor_receive_p, Nyl_buf, MPI_DOUBLE, XNeighbourNext, 12, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(yy = 0; yy < Nyl; yy++){
u[buf_pos_ex(Nxl+1,yy)] = bufor_receive_p[yy];
}
}
if( ExchangeY == 1 ){
int xx;
bufor_send_n = (double*) malloc(Nxl_buf*sizeof(double));
bufor_receive_n = (double*) malloc(Nxl_buf*sizeof(double));
for(xx = 0; xx < Nxl; xx++){
bufor_send_n[xx] = u[buf_pos(xx,Nyl-1)];
}
printf("Y data exchange: rank %i sending to %i\n", rank, YNeighbourNext);
printf("Y data exchange: rank %i receiving from %i\n", rank, YNeighbourNext);
MPI_Send(bufor_send_n, Nxl_buf, MPI_DOUBLE, YNeighbourNext, 13, MPI_COMM_WORLD);
MPI_Recv(bufor_receive_n, Nxl_buf, MPI_DOUBLE, YNeighbourPrevious, 13, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(xx = 0; xx < Nxl; xx++){
u[buf_pos_ex(xx,0)] = bufor_receive_n[xx];
}
bufor_send_p = (double*) malloc(Nxl_buf*sizeof(double));
bufor_receive_p = (double*) malloc(Nxl_buf*sizeof(double));
for(xx = 0; xx < Nxl; xx++){
bufor_send_p[xx] = u[buf_pos(xx,0)];
}
printf("Y data exchange: rank %i sending to %i\n", rank, YNeighbourPrevious);
printf("Y data exchange: rank %i receiving to %i\n", rank, YNeighbourPrevious);
MPI_Send(bufor_send_p, Nxl_buf, MPI_DOUBLE, YNeighbourPrevious, 14, MPI_COMM_WORLD);
MPI_Recv(bufor_receive_p, Nxl_buf, MPI_DOUBLE, YNeighbourNext, 14, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
for(xx = 0; xx < Nxl; xx++){
u[buf_pos_ex(xx,Nyl+1)] = bufor_receive_p[xx];
}
}
return 1;
}