Wrapper.cpp 5.21 KB
Newer Older
1
2
3
4
5
6
7
#include "Wrapper.h"
#include "RankOperations.h"
#include "TMPIConstants.h"
#include "Logging.h"
#include "Timing.h"

int MPI_Init(int *argc, char*** argv) {
8
9
10
  int err = 0;

  err |= PMPI_Init(argc, argv);
11
12
13

  init_rank();

14
  return err;
15
16
17
}

int MPI_Init_thread( int *argc, char ***argv, int required, int *provided ) {
18
19
20
  int err = 0;

  err |= PMPI_Init_thread(argc, argv, required, provided);
21
22
23

  init_rank();

24
  return err;
25
26
27
28
29
30
31
32
33
34
35
36
}

int MPI_Is_thread_main(int* flag) {
  // See header documentation
  *flag = get_R_number(getWorldRank()) + 1;
  return MPI_SUCCESS;
}

int MPI_Comm_rank(MPI_Comm comm, int *rank) {
  assert(comm == MPI_COMM_WORLD);

  *rank = getTeamRank();
37
//  logInfo("Returning rank " << *rank);
38
39
40
41
42
43
44
45

  return MPI_SUCCESS;
}

int MPI_Comm_size(MPI_Comm comm, int *size) {
  assert(comm == MPI_COMM_WORLD);

  *size = getTeamSize();
46
//  logInfo("Returning size " << *size);
47
48
49
50
51
52
53
54
55
56

  return MPI_SUCCESS;
}

int MPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest,
              int tag, MPI_Comm comm) {
  assert(comm == MPI_COMM_WORLD);

  int err = 0;

57
  err |= PMPI_Send(buf, count, datatype, dest, tag, getCommunicator());
58

59
60
61
62
  logInfo(
      "Send to rank " <<
      dest <<
      "/" <<
63
      map_team_to_world(dest) <<
64
65
      " with tag " <<
      tag);
66
67
68
69
70
71
72
73
74
75

  return err;
}

int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag,
              MPI_Comm comm, MPI_Status *status) {
  assert(comm == MPI_COMM_WORLD);

  int err = 0;

76
  err |= PMPI_Recv(buf, count, datatype, source, tag, getCommunicator(), status);
77
78

  remap_status(status);
79
80
81
82
83

  logInfo(
      "Receive from rank " <<
      source <<
      "/" <<
84
      map_team_to_world(source) <<
85
86
      " with tag " <<
      tag);
87
88
89
90
91
92
93
94
95
96

  return err;
}

int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest,
               int tag, MPI_Comm comm, MPI_Request *request) {
  assert(comm == MPI_COMM_WORLD);

  int err = 0;

97
  err |= PMPI_Isend(buf, count, datatype, dest, tag, getCommunicator(), request);
98
//  Timing::startNonBlocking(Timing::NonBlockingType::iSend, tag, request);
99

100
101
102
103
  logInfo(
      "Isend to rank " <<
      dest <<
      "/" <<
104
      map_team_to_world(dest) <<
105
106
      " with tag " <<
      tag);
107
108
109
110
111
112
113
114
115
116

  return err;
}

int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag,
               MPI_Comm comm, MPI_Request *request) {
  assert(comm == MPI_COMM_WORLD);

  int err = 0;

117
  err |= PMPI_Irecv(buf, count, datatype, source, tag, getCommunicator(), request);
118

119
//  Timing::startNonBlocking(Timing::NonBlockingType::iRecv, tag, request);
120

121
122
123
124
  logInfo(
      "Receive from rank " <<
      source <<
      "/" <<
125
      map_team_to_world(source) <<
126
127
      " with tag " <<
      tag);
128
129
130
131
132
133
134
135
136
137

  return err;
}

int MPI_Wait(MPI_Request *request, MPI_Status *status) {
  int err = 0;
  logInfo("Wait initialised");

  err |= PMPI_Wait(request, status);

138
//  Timing::endNonBlocking(request, status);
139
140
141

  remap_status(status);
  logInfo("Wait completed "
142
143
//      <<"(STATUS_SOURCE=" << status->MPI_SOURCE
//      << ",STATUS_TAG=" << status->MPI_TAG
144
145
146
147
148
      << ")");

  return err;
}

149
150
151
152
153
154
155
int MPI_Waitall(int count, MPI_Request array_of_requests[], MPI_Status array_of_statuses[]) {
  int err = 0;

  logInfo("Waitall initialised with " << count << " requests");

  err |= PMPI_Waitall(count, array_of_requests, array_of_statuses);

156
157
158
159
  if (array_of_statuses != MPI_STATUSES_IGNORE) {
    for (int i = 0; i < count; i++) {
      remap_status(&array_of_statuses[i]);
    }
160
161
162
163
164
165
166
  }

  logInfo("Waitall completed with " << count << " requests");

  return err;
}

167
168
169
170
171
172
int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status) {
  int err = 0;

  err |= PMPI_Test(request, flag, status);

  if (*flag) {
173
//    Timing::endNonBlocking(request, status);
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
    remap_status(status);
  }

  logInfo("Test completed ("
      << "FLAG=" << *flag
      << ",STATUS_SOURCE=" << status->MPI_SOURCE
      << ",STATUS_TAG=" << status->MPI_TAG
      << ")");
  return err;
}

int MPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status *status) {
  assert(comm == MPI_COMM_WORLD);
  int err = 0;

  logInfo(
      "Probe initialised (SOURCE="
      << source
      << ",TAG="
      << tag
      << ")");
195

196
  err |= PMPI_Probe(source, tag, getCommunicator(), status);
197
198
199
  remap_status(status);
  logInfo(
      "Probe finished ("
200
      << "SOURCE=" << map_team_to_world(source)
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
      << ",TAG=" << tag
      << ",STATUS_SOURCE=" << status->MPI_SOURCE
      << ",STATUS_TAG=" << status->MPI_TAG
      << ")");

  return err;

}

int MPI_Iprobe(int source, int tag, MPI_Comm comm, int *flag,
                MPI_Status *status) {
  assert(comm == MPI_COMM_WORLD);

  int err = 0;

216
  err |= PMPI_Iprobe(source, tag, getCommunicator(), flag, status);
217
218
219
220
  remap_status(status);
  logInfo(
      "Iprobe finished ("
      << "FLAG=" << *flag
221
      << ",SOURCE=" << map_team_to_world(source)
222
223
224
225
226
227
228
229
230
231
232
233
234
      << ",TAG=" << tag
      << ",STATUS_SOURCE=" << status->MPI_SOURCE
      << ",STATUS_TAG=" << status->MPI_TAG
      << ")");

  return err;
}

int MPI_Barrier(MPI_Comm comm) {
  assert(comm == MPI_COMM_WORLD);

  int err = 0;

235
  err |= PMPI_Barrier(getCommunicator());
236
237
238
239
240

  return err;
}

int MPI_Finalize() {
241
  logInfo("Finalize");
242
243

  freeCommunicator();
244
  //output_timing();
245
246

  return PMPI_Finalize();
247
248
249
//  logInfo("End finalize");
//
//  return 0;
250
}