-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpi_exchange_grid.cpp
79 lines (61 loc) · 1.99 KB
/
mpi_exchange_grid.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
/*
* 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_grid.cpp
* Authors: P. Korcyl
* Contact: piotr.korcyl@uj.edu.pl
*
* Version: 1.0
*
* Description:
* Functionality for identification of rank neighbours
*
*/
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "mpi_class.h"
int mpi_class::mpi_exchange_grid(void) {
printf("rank %i has grid position (%i, %i)\n", rank, pos_x, pos_y);
//next
n_pos_x = pos_x, n_pos_y = pos_y;
//previous
p_pos_x = pos_x, p_pos_y = pos_y;
if( ExchangeX == 1 ){
n_pos_x = pos_x + 1;
if(n_pos_x == proc_grid[0])
n_pos_x = 0;
p_pos_x = pos_x - 1;
if(p_pos_x == -1)
p_pos_x = proc_grid[0]-1;
}
if( ExchangeY == 1 ){
n_pos_y = pos_y + 1;
if(n_pos_y == proc_grid[1])
n_pos_y = 0;
p_pos_y = pos_y - 1;
if(p_pos_y == -1)
p_pos_y = proc_grid[1]-1;
}
XNeighbourNext = pos_y + proc_grid[1] * n_pos_x;
XNeighbourPrevious = pos_y + proc_grid[1] * p_pos_x;
YNeighbourNext = n_pos_y + proc_grid[1] * pos_x;
YNeighbourPrevious = p_pos_y + proc_grid[1] * pos_x;
printf("rank %i has neighbours in X direction %i %i\n", rank, XNeighbourNext, XNeighbourPrevious);
printf("rank %i has neighbours in Y direction %i %i\n", rank, YNeighbourNext, YNeighbourPrevious);
return 1;
}