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);
12 #define CHECK_FLAGS(fh) \
13 if ((fh)->flags() & MPI_MODE_SEQUENTIAL) \
15 #define CHECK_RDONLY(fh) \
16 if ((fh)->flags() & MPI_MODE_RDONLY) \
18 #define CHECK_WRONLY(fh) \
19 if ((fh)->flags() & MPI_MODE_WRONLY) \
21 #define PASS_ZEROCOUNT(count) \
27 #define CHECK_FILE_INPUTS \
29 CHECK_BUFFER(2, buf, count) \
30 CHECK_COUNT(3, count) \
31 CHECK_TYPE(4, datatype) \
32 CHECK_NULL(5, MPI_ERR_ARG, status)
34 #define CHECK_FILE_INPUT_OFFSET \
36 CHECK_BUFFER(2, buf, count) \
37 CHECK_OFFSET(3, offset) \
38 CHECK_COUNT(4, count) \
39 CHECK_TYPE(5, datatype) \
40 CHECK_NULL(6, MPI_ERR_ARG, status)
42 extern MPI_Errhandler SMPI_default_File_Errhandler;
44 int PMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh){
46 CHECK_NULL(2, MPI_ERR_FILE, filename)
50 *fh = new simgrid::smpi::File(comm, filename, amode, info);
52 if ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL)){
56 if(amode & MPI_MODE_APPEND)
57 (*fh)->seek(0,MPI_SEEK_END);
61 int PMPI_File_close(MPI_File *fh){
62 CHECK_NULL(2, MPI_ERR_ARG, fh)
64 int ret = simgrid::smpi::File::close(fh);
70 int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){
73 int ret = fh->seek(offset,whence);
78 int PMPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence){
81 int ret = fh->seek_shared(offset,whence);
86 int PMPI_File_get_position(MPI_File fh, MPI_Offset* offset){
88 CHECK_NULL(2, MPI_ERR_DISP, offset)
90 int ret = fh->get_position(offset);
95 int PMPI_File_get_position_shared(MPI_File fh, MPI_Offset* offset){
97 CHECK_NULL(2, MPI_ERR_DISP, offset)
99 int ret = fh->get_position_shared(offset);
104 int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
107 PASS_ZEROCOUNT(count)
109 int rank_traced = simgrid::s4u::this_actor::get_pid();
110 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
111 int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
112 TRACE_smpi_comm_out(rank_traced);
117 int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
121 PASS_ZEROCOUNT(count)
123 int rank_traced = simgrid::s4u::this_actor::get_pid();
124 TRACE_smpi_comm_in(rank_traced, __func__,
125 new simgrid::instr::CpuTIData("IO - read_shared", count * datatype->size()));
126 int ret = simgrid::smpi::File::read_shared(fh, buf, count, datatype, status);
127 TRACE_smpi_comm_out(rank_traced);
132 int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
136 PASS_ZEROCOUNT(count)
138 int rank_traced = simgrid::s4u::this_actor::get_pid();
139 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
140 int ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
141 TRACE_smpi_comm_out(rank_traced);
146 int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
150 PASS_ZEROCOUNT(count)
152 int rank_traced = simgrid::s4u::this_actor::get_pid();
153 TRACE_smpi_comm_in(rank_traced, __func__,
154 new simgrid::instr::CpuTIData("IO - write_shared", count * datatype->size()));
155 int ret = simgrid::smpi::File::write_shared(fh, buf, count, datatype, status);
156 TRACE_smpi_comm_out(rank_traced);
161 int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
166 int rank_traced = simgrid::s4u::this_actor::get_pid();
167 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_all", count * datatype->size()));
168 int ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
169 TRACE_smpi_comm_out(rank_traced);
174 int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
179 int rank_traced = simgrid::s4u::this_actor::get_pid();
180 TRACE_smpi_comm_in(rank_traced, __func__,
181 new simgrid::instr::CpuTIData("IO - read_ordered", count * datatype->size()));
182 int ret = simgrid::smpi::File::read_ordered(fh, buf, count, datatype, status);
183 TRACE_smpi_comm_out(rank_traced);
188 int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
193 int rank_traced = simgrid::s4u::this_actor::get_pid();
194 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_all", count * datatype->size()));
195 int ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
196 TRACE_smpi_comm_out(rank_traced);
201 int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
206 int rank_traced = simgrid::s4u::this_actor::get_pid();
207 TRACE_smpi_comm_in(rank_traced, __func__,
208 new simgrid::instr::CpuTIData("IO - write_ordered", count * datatype->size()));
209 int ret = simgrid::smpi::File::write_ordered(fh, buf, count, datatype, status);
210 TRACE_smpi_comm_out(rank_traced);
215 int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
219 PASS_ZEROCOUNT(count);
221 int rank_traced = simgrid::s4u::this_actor::get_pid();
222 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
223 int ret = fh->seek(offset,MPI_SEEK_SET);
226 ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
227 TRACE_smpi_comm_out(rank_traced);
232 int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
233 CHECK_FILE_INPUT_OFFSET
237 int rank_traced = simgrid::s4u::this_actor::get_pid();
238 TRACE_smpi_comm_in(rank_traced, __func__,
239 new simgrid::instr::CpuTIData("IO - read_at_all", count * datatype->size()));
240 int ret = fh->seek(offset,MPI_SEEK_SET);
243 ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
244 TRACE_smpi_comm_out(rank_traced);
249 int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
250 CHECK_FILE_INPUT_OFFSET
253 PASS_ZEROCOUNT(count);
255 int rank_traced = simgrid::s4u::this_actor::get_pid();
256 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
257 int ret = fh->seek(offset,MPI_SEEK_SET);
260 ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
261 TRACE_smpi_comm_out(rank_traced);
266 int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
267 CHECK_FILE_INPUT_OFFSET
271 int rank_traced = simgrid::s4u::this_actor::get_pid();
272 TRACE_smpi_comm_in(rank_traced, __func__,
273 new simgrid::instr::CpuTIData("IO - write_at_all", count * datatype->size()));
274 int ret = fh->seek(offset,MPI_SEEK_SET);
277 ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
278 TRACE_smpi_comm_out(rank_traced);
283 int PMPI_File_delete(const char *filename, MPI_Info info){
284 if (filename == nullptr)
287 int ret = simgrid::smpi::File::del(filename, info);
292 int PMPI_File_get_info(MPI_File fh, MPI_Info* info)
299 int PMPI_File_set_info(MPI_File fh, MPI_Info info)
306 int PMPI_File_get_size(MPI_File fh, MPI_Offset* size)
313 int PMPI_File_get_amode(MPI_File fh, int* amode)
316 *amode = fh->flags();
320 int PMPI_File_get_group(MPI_File fh, MPI_Group* group)
323 *group = fh->comm()->group();
327 int PMPI_File_sync(MPI_File fh)
334 int PMPI_File_create_errhandler(MPI_File_errhandler_function* function, MPI_Errhandler* errhandler){
335 *errhandler=new simgrid::smpi::Errhandler(function);
339 int PMPI_File_get_errhandler(MPI_File file, MPI_Errhandler* errhandler){
340 if (errhandler==nullptr){
342 } else if (file == MPI_FILE_NULL) {
343 *errhandler = SMPI_default_File_Errhandler;
346 *errhandler=file->errhandler();
350 int PMPI_File_set_errhandler(MPI_File file, MPI_Errhandler errhandler){
351 if (errhandler==nullptr){
353 } else if (file == MPI_FILE_NULL) {
354 SMPI_default_File_Errhandler = errhandler;
357 file->set_errhandler(errhandler);
361 int PMPI_File_call_errhandler(MPI_File file,int errorcode){
362 if (file == nullptr) {
365 file->errhandler()->call(file, errorcode);