1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
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. */
8 #include "smpi_file.hpp"
9 #include "smpi_datatype.hpp"
11 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
13 extern MPI_Errhandler SMPI_default_File_Errhandler;
15 int PMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh){
16 if (comm == MPI_COMM_NULL)
18 if (filename == nullptr)
23 *fh = new simgrid::smpi::File(comm, filename, amode, info);
25 if ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL)){
29 if(amode & MPI_MODE_APPEND)
30 (*fh)->seek(0,MPI_SEEK_END);
34 int PMPI_File_close(MPI_File *fh){
38 int ret = simgrid::smpi::File::close(fh);
45 #define CHECK_OFFSET(offset) \
48 #define CHECK_STATUS(status) \
49 if ((status) == nullptr) \
51 #define CHECK_FLAGS(fh) \
52 if ((fh)->flags() & MPI_MODE_SEQUENTIAL) \
54 #define CHECK_RDONLY(fh) \
55 if ((fh)->flags() & MPI_MODE_RDONLY) \
58 #define PASS_ZEROCOUNT(count) \
64 int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){
67 int ret = fh->seek(offset,whence);
72 int PMPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence){
75 int ret = fh->seek_shared(offset,whence);
80 int PMPI_File_get_position(MPI_File fh, MPI_Offset* offset){
84 int ret = fh->get_position(offset);
89 int PMPI_File_get_position_shared(MPI_File fh, MPI_Offset* offset){
94 int ret = fh->get_position_shared(offset);
99 int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
101 CHECK_BUFFER(2, buf, count)
102 CHECK_COUNT(3, count)
103 CHECK_TYPE(4, datatype)
106 PASS_ZEROCOUNT(count)
108 int rank_traced = simgrid::s4u::this_actor::get_pid();
109 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
110 int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
111 TRACE_smpi_comm_out(rank_traced);
116 int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
118 CHECK_BUFFER(2, buf, count)
119 CHECK_COUNT(3, count)
120 CHECK_TYPE(4, datatype)
123 PASS_ZEROCOUNT(count)
125 int rank_traced = simgrid::s4u::this_actor::get_pid();
126 TRACE_smpi_comm_in(rank_traced, __func__,
127 new simgrid::instr::CpuTIData("IO - read_shared", count * datatype->size()));
128 int ret = simgrid::smpi::File::read_shared(fh, buf, count, datatype, status);
129 TRACE_smpi_comm_out(rank_traced);
134 int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
136 CHECK_BUFFER(2, buf, count)
137 CHECK_COUNT(3, count)
138 CHECK_TYPE(4, datatype)
142 PASS_ZEROCOUNT(count)
144 int rank_traced = simgrid::s4u::this_actor::get_pid();
145 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
146 int ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
147 TRACE_smpi_comm_out(rank_traced);
152 int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
154 CHECK_BUFFER(2, buf, count)
155 CHECK_COUNT(3, count)
156 CHECK_TYPE(4, datatype)
160 PASS_ZEROCOUNT(count)
162 int rank_traced = simgrid::s4u::this_actor::get_pid();
163 TRACE_smpi_comm_in(rank_traced, __func__,
164 new simgrid::instr::CpuTIData("IO - write_shared", count * datatype->size()));
165 int ret = simgrid::smpi::File::write_shared(fh, buf, count, datatype, status);
166 TRACE_smpi_comm_out(rank_traced);
171 int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
173 CHECK_BUFFER(2, buf, count)
174 CHECK_COUNT(3, count)
175 CHECK_TYPE(4, datatype)
179 int rank_traced = simgrid::s4u::this_actor::get_pid();
180 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_all", count * datatype->size()));
181 int ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
182 TRACE_smpi_comm_out(rank_traced);
187 int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
189 CHECK_BUFFER(2, buf, count)
190 CHECK_COUNT(3, count)
191 CHECK_TYPE(4, datatype)
195 int rank_traced = simgrid::s4u::this_actor::get_pid();
196 TRACE_smpi_comm_in(rank_traced, __func__,
197 new simgrid::instr::CpuTIData("IO - read_ordered", count * datatype->size()));
198 int ret = simgrid::smpi::File::read_ordered(fh, buf, count, datatype, status);
199 TRACE_smpi_comm_out(rank_traced);
204 int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
206 CHECK_BUFFER(2, buf, count)
207 CHECK_COUNT(3, count)
208 CHECK_TYPE(4, datatype)
213 int rank_traced = simgrid::s4u::this_actor::get_pid();
214 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_all", count * datatype->size()));
215 int ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
216 TRACE_smpi_comm_out(rank_traced);
221 int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
223 CHECK_BUFFER(2, buf, count)
224 CHECK_COUNT(3, count)
225 CHECK_TYPE(4, datatype)
230 int rank_traced = simgrid::s4u::this_actor::get_pid();
231 TRACE_smpi_comm_in(rank_traced, __func__,
232 new simgrid::instr::CpuTIData("IO - write_ordered", count * datatype->size()));
233 int ret = simgrid::smpi::File::write_ordered(fh, buf, count, datatype, status);
234 TRACE_smpi_comm_out(rank_traced);
239 int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
241 CHECK_BUFFER(2, buf, count)
243 CHECK_COUNT(3, count)
244 CHECK_TYPE(4, datatype)
247 PASS_ZEROCOUNT(count);
249 int rank_traced = simgrid::s4u::this_actor::get_pid();
250 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
251 int ret = fh->seek(offset,MPI_SEEK_SET);
254 ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
255 TRACE_smpi_comm_out(rank_traced);
260 int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
262 CHECK_BUFFER(2, buf, count)
264 CHECK_COUNT(3, count)
265 CHECK_TYPE(4, datatype)
269 int rank_traced = simgrid::s4u::this_actor::get_pid();
270 TRACE_smpi_comm_in(rank_traced, __func__,
271 new simgrid::instr::CpuTIData("IO - read_at_all", count * datatype->size()));
272 int ret = fh->seek(offset,MPI_SEEK_SET);
275 ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
276 TRACE_smpi_comm_out(rank_traced);
281 int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
283 CHECK_BUFFER(2, buf, count)
285 CHECK_COUNT(4, count)
286 CHECK_TYPE(5, datatype)
290 PASS_ZEROCOUNT(count);
292 int rank_traced = simgrid::s4u::this_actor::get_pid();
293 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
294 int ret = fh->seek(offset,MPI_SEEK_SET);
297 ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
298 TRACE_smpi_comm_out(rank_traced);
303 int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
305 CHECK_BUFFER(2, buf, count)
307 CHECK_COUNT(4, count)
308 CHECK_TYPE(5, datatype)
313 int rank_traced = simgrid::s4u::this_actor::get_pid();
314 TRACE_smpi_comm_in(rank_traced, __func__,
315 new simgrid::instr::CpuTIData("IO - write_at_all", count * datatype->size()));
316 int ret = fh->seek(offset,MPI_SEEK_SET);
319 ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
320 TRACE_smpi_comm_out(rank_traced);
325 int PMPI_File_delete(const char *filename, MPI_Info info){
326 if (filename == nullptr)
329 int ret = simgrid::smpi::File::del(filename, info);
334 int PMPI_File_get_info(MPI_File fh, MPI_Info* info)
341 int PMPI_File_set_info(MPI_File fh, MPI_Info info)
348 int PMPI_File_get_size(MPI_File fh, MPI_Offset* size)
355 int PMPI_File_get_amode(MPI_File fh, int* amode)
358 *amode = fh->flags();
362 int PMPI_File_get_group(MPI_File fh, MPI_Group* group)
365 *group = fh->comm()->group();
369 int PMPI_File_sync(MPI_File fh)
376 int PMPI_File_create_errhandler(MPI_File_errhandler_function* function, MPI_Errhandler* errhandler){
377 *errhandler=new simgrid::smpi::Errhandler(function);
381 int PMPI_File_get_errhandler(MPI_File file, MPI_Errhandler* errhandler){
382 if (errhandler==nullptr){
384 } else if (file == MPI_FILE_NULL) {
385 *errhandler = SMPI_default_File_Errhandler;
388 *errhandler=file->errhandler();
392 int PMPI_File_set_errhandler(MPI_File file, MPI_Errhandler errhandler){
393 if (errhandler==nullptr){
395 } else if (file == MPI_FILE_NULL) {
396 SMPI_default_File_Errhandler = errhandler;
399 file->set_errhandler(errhandler);
403 int PMPI_File_call_errhandler(MPI_File file,int errorcode){
404 if (file == nullptr) {
407 file->errhandler()->call(file, errorcode);