Newer
Older
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
* ADIOS is freely available under the terms of the BSD license described
* in the COPYING file in the top level directory of this source distribution.
*
* Copyright (c) 2008 - 2009. UT-BATTELLE, LLC. All rights reserved.
*/
/*
A dummy MPI implementation for the BP READ API, to have an MPI-free version
of the API
*/
/// \cond EXCLUDE_FROM_DOXYGEN
#define __STDC_FORMAT_MACROS
#include <cstdint>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
//#define _LARGEFILE64_SOURCE
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
/// \endcond
#include "mpidummy.h"
#if defined(__APPLE__) || defined(__WIN32__) || defined(__CYGWIN__)
#define lseek64 lseek
#define open64 open
#endif
namespace adios
{
static char mpierrmsg[MPI_MAX_ERROR_STRING];
int MPI_Init(int *argc, char ***argv)
{
mpierrmsg[0] = '\0';
return MPI_SUCCESS;
}
int MPI_Finalize()
{
mpierrmsg[0] = '\0';
return MPI_SUCCESS;
}
int MPI_Initialized(int *flag)
{
*flag = 1;
return MPI_SUCCESS;
}
int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *comm_out)
{
return MPI_SUCCESS;
}
int MPI_Barrier(MPI_Comm comm) { return MPI_SUCCESS; }
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root,
MPI_Comm comm)
{
return MPI_SUCCESS;
}
int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
{
*newcomm = comm;
return MPI_SUCCESS;
}
int MPI_Comm_rank(MPI_Comm comm, int *rank)
{
*rank = 0;
return MPI_SUCCESS;
}
int MPI_Comm_size(MPI_Comm comm, int *size)
{
*size = 1;
return MPI_SUCCESS;
}
int MPI_Comm_free(MPI_Comm *comm)
{
*comm = 0;
return MPI_SUCCESS;
}
MPI_Comm MPI_Comm_f2c(MPI_Fint comm) { return comm; }
int MPI_Gather(void *sendbuf, int sendcnt, MPI_Datatype sendtype, void *recvbuf,
int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm)
{
int ier = MPI_SUCCESS;
size_t n = 0, nsent = 0, nrecv = 0;
if (!sendbuf || !recvbuf)
ier = MPI_ERR_BUFFER;
if (comm == MPI_COMM_NULL || root)
ier = MPI_ERR_COMM;
switch (sendtype)
{
case MPI_INT:
n = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
}
nsent = n * sendcnt;
switch (recvtype)
{
case MPI_INT:
nrecv = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
}
nrecv = n * recvcnt;
if (nrecv != nsent)
ier = MPI_ERR_COUNT;
if (ier == MPI_SUCCESS)
memcpy(recvbuf, sendbuf, nsent);
else
snprintf(mpierrmsg, ier, "could not gather data\n");
return ier;
}
int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
void *recvbuf, int *recvcnts, int *displs,
MPI_Datatype recvtype, int root, MPI_Comm comm)
{
int ier = MPI_SUCCESS;
if (!recvcnts || !displs)
ier = MPI_ERR_BUFFER;
if (ier == MPI_SUCCESS)
ier = MPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, recvcnts[0], recvtype,
root, comm);
return ier;
}
int MPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm)
{
return MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype,
0, comm);
}
int MPI_Scatter(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root,
MPI_Comm comm)
{
int ier = MPI_SUCCESS;
size_t n = 0, nsent = 0, nrecv = 0;
if (!sendbuf || !recvbuf)
ier = MPI_ERR_BUFFER;
if (comm == MPI_COMM_NULL || root)
ier = MPI_ERR_COMM;
switch (sendtype)
{
case MPI_INT:
n = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
}
nsent = n * sendcnt;
switch (recvtype)
{
case MPI_INT:
nrecv = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
}
nrecv = n * recvcnt;
if (nrecv != nsent)
ier = MPI_ERR_COUNT;
if (ier == MPI_SUCCESS)
memcpy(sendbuf, recvbuf, nsent);
else
snprintf(mpierrmsg, ier, "could not scatter data\n");
return ier;
}
int MPI_Scatterv(void *sendbuf, int *sendcnts, int *displs,
MPI_Datatype sendtype, void *recvbuf, int recvcnt,
MPI_Datatype recvtype, int root, MPI_Comm comm)
{
int ier = MPI_SUCCESS;
if (!sendcnts || !displs)
ier = MPI_ERR_BUFFER;
if (ier == MPI_SUCCESS)
ier = MPI_Scatter(sendbuf, sendcnts[0], sendtype, recvbuf, recvcnt,
recvtype, root, comm);
return ier;
}
int MPI_Recv(void *recvbuffer, int count, MPI_Datatype type, int source,
int tag, MPI_Comm comm, MPI_Status *status)
{
return 0;
}
int MPI_Irecv(void *recvbuffer, int count, MPI_Datatype type, int source,
int tag, MPI_Comm comm, MPI_Request *request)
{
return 0;
}
int MPI_Send(void *sendbuffer, int count, MPI_Datatype type, int destination,
int tag, MPI_Comm comm)
{
return 0;
}
int MPI_Isend(void *recvbuffer, int count, MPI_Datatype type, int source,
int tag, MPI_Comm comm, MPI_Request *request)
{
return 0;
}
int MPI_Wait(MPI_Request *request, MPI_Status *status) { return 0; }
int MPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info,
MPI_File *fh)
{
*fh = open64(filename, amode);
if (*fh == -1)
{
snprintf(mpierrmsg, MPI_MAX_ERROR_STRING, "File not found: %s", filename);
return -1;
}
return MPI_SUCCESS;
}
int MPI_File_close(MPI_File *fh) { return close(*fh); }
int MPI_File_get_size(MPI_File fh, MPI_Offset *size)
{
uint64_t curpos = lseek64(fh, 0, SEEK_CUR); // get the current seek pos
uint64_t endpos =
lseek64(fh, 0, SEEK_END); // go to end, returned is the size in bytes
lseek64(fh, curpos, SEEK_SET); // go back where we were
*size = (MPI_Offset)endpos;
// printf("MPI_File_get_size: fh=%d, size=%lld\n", fh, *size);
return MPI_SUCCESS;
}
int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype,
MPI_Status *status)
{
// FIXME: int count can read only 2GB (*datatype size) array at max
std::uint64_t bytes_to_read =
count * datatype; // datatype should hold the size of the type, not an id
std::uint64_t bytes_read;
bytes_read = read(fh, buf, bytes_to_read);
if (bytes_read != bytes_to_read)
{
snprintf(mpierrmsg, MPI_MAX_ERROR_STRING,
"could not read %" PRId64 " bytes. read only: %" PRId64 "\n",
bytes_to_read, bytes_read);
return -2;
}
*status = bytes_read;
// printf("MPI_File_read: fh=%d, count=%d, typesize=%d, bytes read=%lld\n",
// fh, count, datatype, *status);
return MPI_SUCCESS;
}
int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
{
uint64_t off = (uint64_t)offset;
lseek64(fh, off, whence);
// printf("MPI_File_seek: fh=%d, offset=%lld, whence=%d\n", fh, off, whence);
return MPI_SUCCESS;
}
int MPI_Get_count(MPI_Status *status, MPI_Datatype datatype, int *count)
{
*count = (int)*status;
return MPI_SUCCESS;
}
int MPI_Error_string(int errorcode, char *string, int *resultlen)
{
// sprintf(string, "Dummy lib does not know error strings.
// Code=%d\n",errorcode);
strcpy(string, mpierrmsg);
*resultlen = strlen(string);
return MPI_SUCCESS;
}
double MPI_Wtime()
{
// Implementation not tested
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)(tv.tv_sec) + (double)(tv.tv_usec) / 1000000;
}
int MPI_Get_processor_name(char *name, int *resultlen)
{
sprintf(name, "0");
*resultlen = 1;
return 0;
}
} // end namespace