-
Notifications
You must be signed in to change notification settings - Fork 11
/
cart.c
133 lines (102 loc) · 2.51 KB
/
cart.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
#include "mpiP.h"
/*
* MPI_Cart_create
*
* create a new communicator,
*/
int FC_FUNC( mpi_cart_create , MPI_CART_CREATE )
( int *comm_old, int *ndims, int *dims, int *periods,
int *reorder, int *comm_cart, int *ierr)
{
*ierr = MPI_Cart_create( *comm_old, *ndims, dims, periods, *reorder,
comm_cart);
return(MPI_SUCCESS);
}
int MPI_Cart_create( MPI_Comm comm_old, int ndims, int *dims, int *periods,
int reorder, MPI_Comm *comm_cart)
{
int i;
for (i = 0; i < ndims; i++)
if (dims[i] > 1)
{
printf("MPI_Cart_create: Greater dimension than no. of procs\n");
abort();
}
MPI_Comm_dup(comm_old, comm_cart);
return MPI_SUCCESS;
}
/*
* MPI_Cart_get
*
* Returns information about the cartesian organization
* of the communicator.
*
* Assuming the user gives right maxdims, the only possible
* dimensions are (1,1,..,1) for however many dimensions
*/
int FC_FUNC( mpi_cart_get , MPI_CART_GET )
(int * comm, int * maxdims, int * dims,
int * periods, int * coords, int * ierr)
{
*ierr = MPI_Cart_get(*comm, *maxdims, dims, periods, coords);
return(MPI_SUCCESS);
}
int MPI_Cart_get(MPI_Comm comm, int maxdims, int *dims,
int *periods, int *coords)
{
int i;
for (i=0;i<maxdims;i++)
{
dims[i]=1;
coords[i]=0;
}
return(MPI_SUCCESS);
}
/*
* MPI_Cart_coords
*
* Returns the coordinates of a particular rank
* If rank != 0, erroneous. Coordinates must be (0,0)
*/
int FC_FUNC( mpi_cart_coords , MPI_CART_COORDS)
(int *comm, int *rank, int *maxdims, int *coords, int *ierr)
{
*ierr = MPI_Cart_coords(*comm, *rank, *maxdims, coords);
return(MPI_SUCCESS);
}
int MPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int *coords)
{
int i;
if (rank != 0)
{
printf("MPI_Cart_coords: Rank != 0\n");
abort();
}
for (i=0;i<maxdims;i++)
coords[i]=0;
return MPI_SUCCESS;
}
/*
* MPI_Dims_create
*
* A convenience function to distribute nodes among a grid. Since we have one
* node only, every dimension must be "1" or it is erroneous
*/
int FC_FUNC( mpi_dims_create , MPI_DIMS_CREATE )
(int *nnodes, int *ndims, int * dims, int *ierr)
{
*ierr = MPI_Dims_create(*nnodes, *ndims, dims);
return(MPI_SUCCESS);
}
int MPI_Dims_create(int nnodes, int ndims, int *dims)
{
int i;
if (nnodes > 1)
{
printf("MPI_Dims_create: More nodes than procs specified.\n");
abort();
}
for (i=0; i<ndims; i++)
dims[i] = 1;
return MPI_SUCCESS;
}