Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
32 bits insists of having some timestamps off by 1us ... Hide them.
[simgrid.git] / src / smpi / bindings / smpi_pmpi_file.cpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "private.hpp"
7 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
8
9 #include "smpi_file.hpp"
10 #include "smpi_datatype.hpp"
11
12
13 int PMPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh){
14   if (comm == MPI_COMM_NULL)
15     return MPI_ERR_COMM;
16   if (filename == nullptr)
17     return MPI_ERR_FILE;
18   if (amode < 0)
19     return MPI_ERR_AMODE;
20   smpi_bench_end();
21   *fh =  new simgrid::smpi::File(comm, filename, amode, info);
22   smpi_bench_begin();
23   if (((*fh)->size() == 0 && not (amode & MPI_MODE_CREATE)) ||
24      ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL))){
25     delete fh;
26     return MPI_ERR_AMODE;
27   }
28   if(amode & MPI_MODE_APPEND)
29     (*fh)->seek(0,MPI_SEEK_END);
30   return MPI_SUCCESS;
31 }
32
33 int PMPI_File_close(MPI_File *fh){
34   if (fh==nullptr)
35     return MPI_ERR_ARG;
36   smpi_bench_end();
37   int ret = simgrid::smpi::File::close(fh);
38   *fh = MPI_FILE_NULL;
39   smpi_bench_begin();
40   return ret;
41 }
42 #define CHECK_FILE(fh) if(fh==MPI_FILE_NULL) return MPI_ERR_FILE;
43 #define CHECK_BUFFER(buf, count)  if (buf==nullptr && count > 0) return MPI_ERR_BUFFER;
44 #define CHECK_COUNT(count)  if (count < 0) return MPI_ERR_COUNT;
45 #define CHECK_OFFSET(offset)  if (offset < 0) return MPI_ERR_DISP;
46 #define CHECK_DATATYPE(datatype, count) if (datatype == MPI_DATATYPE_NULL && count > 0) return MPI_ERR_TYPE;
47 #define CHECK_STATUS(status) if (status == nullptr) return MPI_ERR_ARG;
48 #define CHECK_FLAGS(fh) if (fh->flags() & MPI_MODE_SEQUENTIAL) return MPI_ERR_AMODE;
49
50 #define PASS_ZEROCOUNT(count) if (count == 0) {\
51 status->count=0;\
52 return MPI_SUCCESS;\
53 }
54
55 int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){
56   CHECK_FILE(fh);
57   smpi_bench_end();
58   int ret = fh->seek(offset,whence);
59   smpi_bench_begin();
60   return ret;
61
62 }
63
64 int PMPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence){
65   CHECK_FILE(fh)
66   smpi_bench_end();
67   int ret = fh->seek_shared(offset,whence);
68   smpi_bench_begin();
69   return ret;
70
71 }
72
73 int PMPI_File_get_position(MPI_File fh, MPI_Offset* offset){
74   if (offset==nullptr)
75     return MPI_ERR_DISP;
76   smpi_bench_end();
77   int ret = fh->get_position(offset);
78   smpi_bench_begin();
79   return ret;
80 }
81
82 int PMPI_File_get_position_shared(MPI_File fh, MPI_Offset* offset){
83   CHECK_FILE(fh)
84   if (offset==nullptr)
85     return MPI_ERR_DISP;
86   smpi_bench_end();
87   int ret = fh->get_position_shared(offset);
88   smpi_bench_begin();
89   return ret;
90 }
91
92 int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
93   CHECK_FILE(fh)
94   CHECK_BUFFER(buf, count)
95   CHECK_COUNT(count)
96   CHECK_DATATYPE(datatype, count)
97   CHECK_STATUS(status)
98   CHECK_FLAGS(fh)
99   PASS_ZEROCOUNT(count)
100   smpi_bench_end();
101   int rank_traced = simgrid::s4u::this_actor::get_pid();
102   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));
103   int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
104   TRACE_smpi_comm_out(rank_traced);
105   smpi_bench_begin();
106   return ret;
107 }
108
109 int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
110   CHECK_FILE(fh)
111   CHECK_BUFFER(buf, count)
112   CHECK_COUNT(count)
113   CHECK_DATATYPE(datatype, count)
114   CHECK_STATUS(status)
115   CHECK_FLAGS(fh)
116   PASS_ZEROCOUNT(count)
117   smpi_bench_end();
118   int rank_traced = simgrid::s4u::this_actor::get_pid();
119   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_shared", static_cast<double>(count*datatype->size())));
120   int ret = simgrid::smpi::File::read_shared(fh, buf, count, datatype, status);
121   TRACE_smpi_comm_out(rank_traced);
122   smpi_bench_begin();
123   return ret;
124 }
125
126 int PMPI_File_write(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
127   CHECK_FILE(fh)
128   CHECK_BUFFER(buf, count)
129   CHECK_COUNT(count)
130   CHECK_DATATYPE(datatype, count)
131   CHECK_STATUS(status)
132   CHECK_FLAGS(fh)
133   PASS_ZEROCOUNT(count)
134   smpi_bench_end();
135   int rank_traced = simgrid::s4u::this_actor::get_pid();
136   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", static_cast<double>(count*datatype->size())));
137   int ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
138   TRACE_smpi_comm_out(rank_traced);
139   smpi_bench_begin();
140   return ret;
141 }
142
143 int PMPI_File_write_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
144   CHECK_FILE(fh)
145   CHECK_BUFFER(buf, count)
146   CHECK_COUNT(count)
147   CHECK_DATATYPE(datatype, count)
148   CHECK_STATUS(status)
149   CHECK_FLAGS(fh)
150   PASS_ZEROCOUNT(count)
151   smpi_bench_end();
152   int rank_traced = simgrid::s4u::this_actor::get_pid();
153   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_shared", static_cast<double>(count*datatype->size())));
154   int ret = simgrid::smpi::File::write_shared(fh, buf, count, datatype, status);
155   TRACE_smpi_comm_out(rank_traced);
156   smpi_bench_begin();
157   return ret;
158 }
159
160 int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
161   CHECK_FILE(fh)
162   CHECK_BUFFER(buf, count)
163   CHECK_COUNT(count)
164   CHECK_DATATYPE(datatype, count)
165   CHECK_STATUS(status)
166   CHECK_FLAGS(fh)
167   smpi_bench_end();
168   int rank_traced = simgrid::s4u::this_actor::get_pid();
169   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_all", static_cast<double>(count*datatype->size())));
170   int ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
171   TRACE_smpi_comm_out(rank_traced);
172   smpi_bench_begin();
173   return ret;
174 }
175
176 int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
177   CHECK_FILE(fh)
178   CHECK_BUFFER(buf, count)
179   CHECK_COUNT(count)
180   CHECK_DATATYPE(datatype, count)
181   CHECK_STATUS(status)
182   CHECK_FLAGS(fh)
183   smpi_bench_end();
184   int rank_traced = simgrid::s4u::this_actor::get_pid();
185   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_ordered", static_cast<double>(count*datatype->size())));
186   int ret = simgrid::smpi::File::read_ordered(fh, buf, count, datatype, status);
187   TRACE_smpi_comm_out(rank_traced);
188   smpi_bench_begin();
189   return ret;
190 }
191
192 int PMPI_File_write_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
193   CHECK_FILE(fh)
194   CHECK_BUFFER(buf, count)
195   CHECK_COUNT(count)
196   CHECK_DATATYPE(datatype, count)
197   CHECK_STATUS(status)
198   CHECK_FLAGS(fh)
199   smpi_bench_end();
200   int rank_traced = simgrid::s4u::this_actor::get_pid();
201   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_all", static_cast<double>(count*datatype->size())));
202   int ret = fh->op_all<simgrid::smpi::File::write>(buf, count, datatype, status);
203   TRACE_smpi_comm_out(rank_traced);
204   smpi_bench_begin();
205   return ret;
206 }
207
208 int PMPI_File_write_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
209   CHECK_FILE(fh)
210   CHECK_BUFFER(buf, count)
211   CHECK_COUNT(count)
212   CHECK_DATATYPE(datatype, count)
213   CHECK_STATUS(status)
214   CHECK_FLAGS(fh)
215   smpi_bench_end();
216   int rank_traced = simgrid::s4u::this_actor::get_pid();
217   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_ordered", static_cast<double>(count*datatype->size())));
218   int ret = simgrid::smpi::File::write_ordered(fh, buf, count, datatype, status);
219   TRACE_smpi_comm_out(rank_traced);
220   smpi_bench_begin();
221   return ret;
222 }
223
224 int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
225   CHECK_FILE(fh)
226   CHECK_BUFFER(buf, count)
227   CHECK_OFFSET(offset)
228   CHECK_COUNT(count)
229   CHECK_DATATYPE(datatype, count)
230   CHECK_STATUS(status)
231   CHECK_FLAGS(fh)
232   PASS_ZEROCOUNT(count);
233   smpi_bench_end();
234   int rank_traced = simgrid::s4u::this_actor::get_pid();
235   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));
236   int ret = fh->seek(offset,MPI_SEEK_SET);
237   if(ret!=MPI_SUCCESS)
238     return ret;
239   ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
240   TRACE_smpi_comm_out(rank_traced);
241   smpi_bench_begin();
242   return ret;
243 }
244
245 int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
246   CHECK_FILE(fh)
247   CHECK_BUFFER(buf, count)
248   CHECK_OFFSET(offset)
249   CHECK_COUNT(count)
250   CHECK_DATATYPE(datatype, count)
251   CHECK_STATUS(status)
252   CHECK_FLAGS(fh)
253   smpi_bench_end();
254   int rank_traced = simgrid::s4u::this_actor::get_pid();
255   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_at_all", static_cast<double>(count*datatype->size())));
256   int ret = fh->seek(offset,MPI_SEEK_SET);
257   if(ret!=MPI_SUCCESS)
258     return ret;
259   ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
260   TRACE_smpi_comm_out(rank_traced);
261   smpi_bench_begin();
262   return ret;
263 }
264
265 int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
266   CHECK_FILE(fh)
267   CHECK_BUFFER(buf, count)
268   CHECK_OFFSET(offset)
269   CHECK_COUNT(count)
270   CHECK_DATATYPE(datatype, count)
271   CHECK_STATUS(status)
272   CHECK_FLAGS(fh)
273   PASS_ZEROCOUNT(count);
274   smpi_bench_end();
275   int rank_traced = simgrid::s4u::this_actor::get_pid();
276   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", static_cast<double>(count*datatype->size())));
277   int ret = fh->seek(offset,MPI_SEEK_SET);
278   if(ret!=MPI_SUCCESS)
279     return ret;
280   ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
281   TRACE_smpi_comm_out(rank_traced);
282   smpi_bench_begin();
283   return ret;
284 }
285
286 int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
287   CHECK_FILE(fh)
288   CHECK_BUFFER(buf, count)
289   CHECK_OFFSET(offset)
290   CHECK_COUNT(count)
291   CHECK_DATATYPE(datatype, count)
292   CHECK_STATUS(status)
293   CHECK_FLAGS(fh)
294   smpi_bench_end();
295   int rank_traced = simgrid::s4u::this_actor::get_pid();
296   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_at_all", static_cast<double>(count*datatype->size())));
297   int ret = fh->seek(offset,MPI_SEEK_SET);
298   if(ret!=MPI_SUCCESS)
299     return ret;
300   ret = fh->op_all<simgrid::smpi::File::write>(buf, count, datatype, status);
301   TRACE_smpi_comm_out(rank_traced);
302   smpi_bench_begin();
303   return ret;
304 }
305
306 int PMPI_File_delete(char *filename, MPI_Info info){
307   if (filename == nullptr)
308     return MPI_ERR_FILE;
309   smpi_bench_end();
310   int ret = simgrid::smpi::File::del(filename, info);
311   smpi_bench_begin();
312   return ret;
313 }
314
315 int PMPI_File_get_info(MPI_File  fh, MPI_Info* info)
316 {
317   CHECK_FILE(fh)
318   *info = fh->info();
319   return MPI_SUCCESS;
320 }
321
322 int PMPI_File_set_info(MPI_File  fh, MPI_Info info)
323 {
324   CHECK_FILE(fh)
325   fh->set_info(info);
326   return MPI_SUCCESS;
327 }