AdjoinableMPI
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
modified.c
Go to the documentation of this file.
1 /*
2 ##########################################################
3 # This file is part of the AdjoinableMPI library #
4 # released under the MIT License. #
5 # The full COPYRIGHT notice can be found in the top #
6 # level directory of the AdjoinableMPI distribution. #
7 ##########################################################
8 */
9 #include <stdlib.h>
10 #include <assert.h>
11 #include <mpi.h>
12 #include "ampi/userIF/modified.h"
13 
15 MPI_Datatype AMPI_AREAL;
16 
17 
18 int AMPI_Init(int* argc,
19  char*** argv) {
20  return MPI_Init(argc,argv);
21 }
22 
23 int AMPI_Finalize(int* argc,
24  char*** argv) {
25  return MPI_Finalize();
26 }
27 
28 int AMPI_Buffer_attach(void *buffer,
29  int size) {
30  return MPI_Buffer_attach(buffer,
31  size);
32 
33 }
34 
35 int AMPI_Buffer_detach(void *buffer,
36  int *size){
37  return MPI_Buffer_detach(buffer,
38  size);
39 }
40 
41 
42 int AMPI_Send(void* buf,
43  int count,
44  MPI_Datatype datatype,
45  int dest,
46  int tag,
48  MPI_Comm comm) {
49  if (!(
50  pairedWith==AMPI_TO_RECV
51  ||
52  pairedWith==AMPI_TO_IRECV_WAIT
53  ||
54  pairedWith==AMPI_TO_IRECV_WAITALL
55  )) MPI_Abort(comm, MPI_ERR_ARG);
56  /* [llh] TODO: pass (pairedWith;AMPI_FROM_SEND) for verification on the receiver side */
57  return MPI_Send(buf,
58  count,
59  datatype,
60  dest,
61  tag,
62  comm);
63 }
64 
65 int AMPI_Recv(void* buf,
66  int count,
67  MPI_Datatype datatype,
68  int src,
69  int tag,
71  MPI_Comm comm,
72  MPI_Status* status) {
73  /* [llh] TODO: verify with the (pairedWith;AMPI_FROM_SEND) passed by the sender side */
74  if (!(
75  pairedWith==AMPI_FROM_SEND
76  ||
77  pairedWith==AMPI_FROM_BSEND
78  ||
79  pairedWith==AMPI_FROM_RSEND
80  ||
81  pairedWith==AMPI_FROM_ISEND_WAIT
82  ||
83  pairedWith==AMPI_FROM_ISEND_WAITALL
84  )) MPI_Abort(comm, MPI_ERR_ARG);
85  return MPI_Recv(buf,
86  count,
87  datatype,
88  src,
89  tag,
90  comm,
91  status);
92 }
93 
94 int AMPI_Isend (void* buf,
95  int count,
96  MPI_Datatype datatype,
97  int dest,
98  int tag,
100  MPI_Comm comm,
101  AMPI_Request* request) {
102  if (!(
103  pairedWith==AMPI_TO_RECV
104  ||
105  pairedWith==AMPI_TO_IRECV_WAIT
106  ||
107  pairedWith==AMPI_TO_IRECV_WAITALL
108  )) MPI_Abort(comm, MPI_ERR_ARG);
109  return MPI_Isend(buf,
110  count,
111  datatype,
112  dest,
113  tag,
114  comm,
115 #ifdef AMPI_FORTRANCOMPATIBLE
116  request
117 #else
118  &(request->plainRequest)
119 #endif
120  );
121 }
122 
123 int AMPI_Irecv (void* buf,
124  int count,
125  MPI_Datatype datatype,
126  int src,
127  int tag,
129  MPI_Comm comm,
130  AMPI_Request* request) {
131  if (!(
132  pairedWith==AMPI_FROM_SEND
133  ||
134  pairedWith==AMPI_FROM_BSEND
135  ||
136  pairedWith==AMPI_FROM_RSEND
137  ||
138  pairedWith==AMPI_FROM_ISEND_WAIT
139  ||
140  pairedWith==AMPI_FROM_ISEND_WAITALL
141  )) MPI_Abort(comm, MPI_ERR_ARG);
142  return MPI_Irecv(buf,
143  count,
144  datatype,
145  src,
146  tag,
147  comm,
148 #ifdef AMPI_FORTRANCOMPATIBLE
149  request
150 #else
151  &(request->plainRequest)
152 #endif
153  );
154 }
155 
156 int AMPI_Bsend(void *buf,
157  int count,
158  MPI_Datatype datatype,
159  int dest,
160  int tag,
162  MPI_Comm comm) {
163  if (!(
164  pairedWith==AMPI_TO_RECV
165  ||
166  pairedWith==AMPI_TO_IRECV_WAIT
167  )) MPI_Abort(comm, MPI_ERR_ARG);
168  return MPI_Bsend(buf,
169  count,
170  datatype,
171  dest,
172  tag,
173  comm);
174 }
175 
176 int AMPI_Rsend(void *buf,
177  int count,
178  MPI_Datatype datatype,
179  int dest,
180  int tag,
182  MPI_Comm comm) {
183  if (!(
184  pairedWith==AMPI_TO_RECV
185  ||
186  pairedWith==AMPI_TO_IRECV_WAIT
187  )) MPI_Abort(comm, MPI_ERR_ARG);
188  return MPI_Rsend(buf,
189  count,
190  datatype,
191  dest,
192  tag,
193  comm);
194 }
195 
196 int AMPI_Bcast (void* buf,
197  int count,
198  MPI_Datatype datatype,
199  int root,
200  MPI_Comm comm) {
201  return MPI_Bcast(buf,
202  count,
203  datatype,
204  root,
205  comm);
206 }
207 
208 
209 int AMPI_Reduce (void* sbuf,
210  void* rbuf,
211  int count,
212  MPI_Datatype datatype,
213  MPI_Op op,
214  int root,
215  MPI_Comm comm) {
216  /* [llh] It would be nice here to call our PEDESTRIAN_AMPI_Reduce(),
217  * just to test that our AMPI's reduction algorithm
218  * gives the same result as the one of this MPI */
219  return MPI_Reduce(sbuf,
220  rbuf,
221  count,
222  datatype,
223  op,
224  root,
225  comm);
226 }
227 
228 int AMPI_Allreduce (void* sbuf,
229  void* rbuf,
230  int count,
231  MPI_Datatype datatype,
232  MPI_Op op,
233  MPI_Comm comm) {
234  return MPI_Allreduce(sbuf,
235  rbuf,
236  count,
237  datatype,
238  op,
239  comm);
240 }
241 
242 int AMPI_Wait(AMPI_Request *request,
243  MPI_Status *status) {
244  return MPI_Wait(
245 #ifdef AMPI_FORTRANCOMPATIBLE
246  request
247 #else
248  &(request->plainRequest)
249 #endif
250  ,status);
251 }
252 
253 int AMPI_Waitall (int count,
254  AMPI_Request requests[],
255  MPI_Status statuses[]) {
256 #ifndef AMPI_FORTRANCOMPATIBLE
257  int i;
258  /* extract original requests */
259  MPI_Request * origRequests=(MPI_Request*)malloc(count*sizeof(MPI_Request));
260  assert(origRequests);
261  for (i=0;i<count;++i) origRequests[i]=requests[i].plainRequest;
262 #endif
263  return MPI_Waitall(count,
264 #ifdef AMPI_FORTRANCOMPATIBLE
265  requests,
266 #else
267  origRequests,
268 #endif
269  statuses);
270 }
271 
273  AMPI_Request requests[],
274  MPI_Status statuses[]) {
275  return MPI_SUCCESS;
276 }
277 
278 int AMPI_Barrier(MPI_Comm comm) {
279  return MPI_Barrier(comm);
280 }
281 
282 int AMPI_Gather(void *sendbuf,
283  int sendcnt,
284  MPI_Datatype sendtype,
285  void *recvbuf,
286  int recvcnt,
287  MPI_Datatype recvtype,
288  int root,
289  MPI_Comm comm) {
290  return MPI_Gather(sendbuf,
291  sendcnt,
292  sendtype,
293  recvbuf,
294  recvcnt,
295  recvtype,
296  root,
297  comm);
298 }
299 
300 int AMPI_Scatter(void *sendbuf,
301  int sendcnt,
302  MPI_Datatype sendtype,
303  void *recvbuf,
304  int recvcnt,
305  MPI_Datatype recvtype,
306  int root,
307  MPI_Comm comm) {
308  return MPI_Scatter(sendbuf,
309  sendcnt,
310  sendtype,
311  recvbuf,
312  recvcnt,
313  recvtype,
314  root,
315  comm);
316 }
317 
318 int AMPI_Allgather(void *sendbuf,
319  int sendcount,
320  MPI_Datatype sendtype,
321  void *recvbuf,
322  int recvcount,
323  MPI_Datatype recvtype,
324  MPI_Comm comm) {
325  return MPI_Allgather(sendbuf,
326  sendcount,
327  sendtype,
328  recvbuf,
329  recvcount,
330  recvtype,
331  comm);
332 }
333 
334 int AMPI_Gatherv(void *sendbuf,
335  int sendcnt,
336  MPI_Datatype sendtype,
337  void *recvbuf,
338  int *recvcnts,
339  int *displs,
340  MPI_Datatype recvtype,
341  int root,
342  MPI_Comm comm) {
343  return MPI_Gatherv(sendbuf,
344  sendcnt,
345  sendtype,
346  recvbuf,
347  recvcnts,
348  displs,
349  recvtype,
350  root,
351  comm);
352 }
353 
354 int AMPI_Scatterv(void *sendbuf,
355  int *sendcnts,
356  int *displs,
357  MPI_Datatype sendtype,
358  void *recvbuf,
359  int recvcnt,
360  MPI_Datatype recvtype,
361  int root, MPI_Comm comm) {
362  return MPI_Scatterv(sendbuf,
363  sendcnts,
364  displs,
365  sendtype,
366  recvbuf,
367  recvcnt,
368  recvtype,
369  root,
370  comm);
371 }
372 
373 int AMPI_Allgatherv(void *sendbuf,
374  int sendcnt,
375  MPI_Datatype sendtype,
376  void *recvbuf,
377  int *recvcnts,
378  int *displs,
379  MPI_Datatype recvtype,
380  MPI_Comm comm) {
381  return MPI_Allgatherv(sendbuf,
382  sendcnt,
383  sendtype,
384  recvbuf,
385  recvcnts,
386  displs,
387  recvtype,
388  comm);
389 }