-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmpi.impala
159 lines (146 loc) · 5.16 KB
/
mpi.impala
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
type size_t = u64;
type MPI_Comm = &();
type MPI_Datatype = &();
type MPI_Op = &();
type MPI_Request = &();
type MPI_Status = &mut [i8];
type MPI_Buf = &[i8];
type MPI_MutBuf = &mut [i8];
extern "C" {
// fn MPI_Init(&i32, &[&[u8]]) -> i32;
fn MPI_init() -> i32;
fn MPI_Comm_size(MPI_Comm, &mut i32) -> i32;
fn MPI_Comm_rank(MPI_Comm, &mut i32) -> i32;
fn MPI_Allreduce(MPI_Buf, MPI_MutBuf, i32, MPI_Datatype, MPI_Op, MPI_Comm) -> i32;
fn MPI_Send(MPI_Buf, i32, MPI_Datatype, i32, i32, MPI_Comm) -> i32;
fn MPI_Recv(MPI_MutBuf, i32, MPI_Datatype, i32, i32, MPI_Comm, MPI_Status) -> i32;
fn MPI_Isend_ex(MPI_Buf, i32, MPI_Datatype, i32, i32, MPI_Comm, i32) -> i32;
fn MPI_Irecv_ex(MPI_MutBuf, i32, MPI_Datatype, i32, i32, MPI_Comm, i32) -> i32;
fn MPI_Wait(&MPI_Request, MPI_Status) -> i32;
fn MPI_Waitall_ex(i32) -> i32;
fn MPI_Probe(i32, i32, MPI_Comm, MPI_Status) -> i32;
fn MPI_Get_count(MPI_Status, MPI_Datatype, &mut i32) -> i32;
fn MPI_Gather(MPI_Buf, i32, MPI_Datatype, MPI_MutBuf, i32, MPI_Datatype, i32, MPI_Comm) -> i32;
fn MPI_Barrier(MPI_Comm, &MPI_Request) -> i32;
fn MPI_Wtime() -> f64;
fn MPI_Finalize() -> i32;
// wrappers in mpi.cpp for getting MPI constants
fn get_mpi_comm_world() -> MPI_Comm;
fn get_mpi_int() -> MPI_Datatype;
fn get_mpi_int64() -> MPI_Datatype;
fn get_mpi_double() -> MPI_Datatype;
fn get_mpi_float() -> MPI_Datatype;
fn get_mpi_max() -> MPI_Op;
fn get_mpi_sum() -> MPI_Op;
fn get_mpi_status_ignore() -> MPI_Status;
fn get_mpi_cart_neighborhood(i32, i32, i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32) -> ();
fn sync_ghost_layer_loop(i32, MPI_Buf, MPI_MutBuf, &[i32], &[i32], &[i32], &[i32], &[i32], &[i32]) -> ();
}
struct MPIComms {
world : MPI_Comm,
}
struct MPIOps {
max : MPI_Op,
sum : MPI_Op,
}
// TODO should be autogenerated, differs for other MPI implementations (e.g. MPICH)
struct MPIStatus {
source : i32,
tag : i32,
error : i32,
// internal to openmpi, do not access
_cancelled : i32,
_ucount : u64
}
struct MPIStatuses {
ignore : &mut MPIStatus,
}
struct MPI {
comms : MPIComms,
ops : MPIOps,
status : MPIStatuses,
int_t : MPI_Datatype,
double_t : MPI_Datatype,
float_t : MPI_Datatype,
int64_t: MPI_Datatype,
init : fn() -> i32,
comm_size : fn(MPI_Comm, &mut i32) -> i32,
comm_rank : fn(MPI_Comm, &mut i32) -> i32,
cart: fn(i32, i32, i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32, &mut i32) -> (),
allreduce : fn(MPI_Buf, MPI_MutBuf, i32, MPI_Datatype, MPI_Op, MPI_Comm) -> i32,
send : fn(MPI_Buf, i32, MPI_Datatype, i32, i32, MPI_Comm) -> i32,
recv : fn(MPI_MutBuf, i32, MPI_Datatype, i32, i32, MPI_Comm, &mut MPIStatus) -> i32,
isend : fn(MPI_Buf, i32, MPI_Datatype, i32, i32, MPI_Comm, i32) -> i32,
irecv : fn(MPI_MutBuf, i32, MPI_Datatype, i32, i32, MPI_Comm, i32) -> i32,
wait : fn(&MPI_Request, &mut MPIStatus) -> i32,
wait_all : fn(i32) -> i32,
probe: fn(i32, i32, MPI_Comm, &mut MPIStatus) -> i32,
get_count: fn(&mut MPIStatus, MPI_Datatype, &mut i32) -> i32,
gather: fn(MPI_Buf, i32, MPI_Datatype, MPI_MutBuf, i32, MPI_Datatype, i32, MPI_Comm) -> i32,
barrier : fn(MPI_Comm, &MPI_Request) -> i32,
wtime : fn() -> f64,
finalize : fn() -> i32,
}
fn get_world_size() -> i32 {
let mpih = mpi();
let mut world_size: i32;
mpih.comm_size(mpih.comms.world, &mut world_size);
world_size
}
fn get_process_rank() -> i32 {
let mpih = mpi();
let mut rank: i32;
mpih.comm_rank(mpih.comms.world, &mut rank);
rank
}
fn barrier() -> () {
let mpih = mpi();
let mut request: MPI_Request;
mpih.barrier(mpih.comms.world, &mut request);
}
fn @mpi() -> MPI {
MPI {
comms : MPIComms {
world : get_mpi_comm_world(),
},
ops : MPIOps {
max : get_mpi_max(),
sum : get_mpi_sum(),
},
status : MPIStatuses {
ignore : get_mpi_status_ignore() as &mut MPIStatus,
},
double_t : get_mpi_double(),
int_t : get_mpi_int(),
int64_t : get_mpi_int64(),
float_t : get_mpi_float(),
init : MPI_init,
comm_size : MPI_Comm_size,
comm_rank : MPI_Comm_rank,
cart: get_mpi_cart_neighborhood,
allreduce : MPI_Allreduce,
send : MPI_Send,
recv : @|buf, count, datatype, source, tag, comm, status| {
MPI_Recv(buf, count, datatype, source, tag, comm, status as MPI_Status)
},
isend : MPI_Isend_ex,
irecv : MPI_Irecv_ex,
wait : @|request, status| {
MPI_Wait(request, status as MPI_Status)
},
wait_all : @|count| {
MPI_Waitall_ex(count)
},
probe: @|source, tag, comm, status| {
MPI_Probe(source, tag, comm, status as MPI_Status)
},
get_count: @|status, datatype, count| {
MPI_Get_count(status as MPI_Status, datatype, count)
},
gather: MPI_Gather,
barrier : MPI_Barrier,
wtime : MPI_Wtime,
finalize : MPI_Finalize,
}
}
;