1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
\r
3 /* This program is free software; you can redistribute it and/or modify it
\r
4 * under the terms of the license (GNU LGPL) which comes with this package. */
\r
6 #include "private.hpp"
\r
7 #include "smpi_file.hpp"
\r
8 #include "smpi_datatype.hpp"
\r
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
\r
12 int PMPI_File_open(MPI_Comm comm, char *filename, int amode, MPI_Info info, MPI_File *fh){
\r
13 if (comm == MPI_COMM_NULL) {
\r
14 return MPI_ERR_COMM;
\r
15 } else if (filename == nullptr) {
\r
16 return MPI_ERR_FILE;
\r
17 } else if (amode < 0) {
\r
18 return MPI_ERR_AMODE;
\r
21 *fh = new simgrid::smpi::File(comm, filename, amode, info);
\r
23 if (((*fh)->size() == 0 && (not amode & MPI_MODE_CREATE)) ||
\r
24 ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL))){
\r
26 return MPI_ERR_AMODE;
\r
28 if(amode & MPI_MODE_APPEND)
\r
29 (*fh)->seek(0,MPI_SEEK_END);
\r
34 int PMPI_File_close(MPI_File *fh){
\r
39 int ret = simgrid::smpi::File::close(fh);
\r
40 *fh = MPI_FILE_NULL;
\r
45 #define CHECK_FILE(fh) if(fh==MPI_FILE_NULL) return MPI_ERR_FILE
\r
46 #define CHECK_BUFFER(buf, count) else if (buf==nullptr && count > 0) return MPI_ERR_BUFFER
\r
47 #define CHECK_COUNT(count) else if (count < 0) return MPI_ERR_COUNT
\r
48 #define CHECK_OFFSET(offset) else if (offset < 0) return MPI_ERR_DISP
\r
49 #define PASS_ZEROCOUNT(count) else if (count == 0) return MPI_SUCCESS
\r
50 #define CHECK_DATATYPE(datatype, count) else if (datatype == MPI_DATATYPE_NULL && count > 0) return MPI_ERR_TYPE
\r
51 #define CHECK_STATUS(status) else if (status == nullptr) return MPI_ERR_ARG
\r
52 #define CHECK_FLAGS(fh) else if (fh->flags() & MPI_MODE_SEQUENTIAL) return MPI_ERR_AMODE
\r
54 int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){
\r
58 int ret = fh->seek(offset,whence);
\r
65 int PMPI_File_get_position(MPI_File fh, MPI_Offset* offset){
\r
67 else if (offset==nullptr)
\r
68 return MPI_ERR_DISP;
\r
71 int ret = fh->get_position(offset);
\r
77 int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
79 CHECK_BUFFER(buf, count);
\r
81 PASS_ZEROCOUNT(count);
\r
82 CHECK_DATATYPE(datatype, count);
\r
83 CHECK_STATUS(status);
\r
87 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
88 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));
\r
89 int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
\r
90 TRACE_smpi_comm_out(rank_traced);
\r
96 int PMPI_File_write(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
98 CHECK_BUFFER(buf, count);
\r
100 PASS_ZEROCOUNT(count);
\r
101 CHECK_DATATYPE(datatype, count);
\r
102 CHECK_STATUS(status);
\r
106 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
107 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", static_cast<double>(count*datatype->size())));
\r
108 int ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
\r
109 TRACE_smpi_comm_out(rank_traced);
\r
110 smpi_bench_begin();
\r
115 int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
117 CHECK_BUFFER(buf, count);
\r
118 CHECK_COUNT(count);
\r
119 CHECK_DATATYPE(datatype, count);
\r
120 CHECK_STATUS(status);
\r
124 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
125 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_all", static_cast<double>(count*datatype->size())));
\r
126 int ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
\r
127 TRACE_smpi_comm_out(rank_traced);
\r
128 smpi_bench_begin();
\r
133 int PMPI_File_write_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
135 CHECK_BUFFER(buf, count);
\r
136 CHECK_COUNT(count);
\r
137 CHECK_DATATYPE(datatype, count);
\r
138 CHECK_STATUS(status);
\r
142 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
143 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_all", static_cast<double>(count*datatype->size())));
\r
144 int ret = fh->op_all<simgrid::smpi::File::write>(buf, count, datatype, status);
\r
145 TRACE_smpi_comm_out(rank_traced);
\r
146 smpi_bench_begin();
\r
151 int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
153 CHECK_BUFFER(buf, count);
\r
154 CHECK_OFFSET(offset);
\r
155 CHECK_COUNT(count);
\r
156 PASS_ZEROCOUNT(count);
\r
157 CHECK_DATATYPE(datatype, count);
\r
158 CHECK_STATUS(status);
\r
162 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
163 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));
\r
164 int ret = fh->seek(offset,SEEK_SET);
\r
165 if(ret!=MPI_SUCCESS)
\r
167 ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
\r
168 TRACE_smpi_comm_out(rank_traced);
\r
169 smpi_bench_begin();
\r
174 int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
176 CHECK_BUFFER(buf, count);
\r
177 CHECK_OFFSET(offset);
\r
178 CHECK_COUNT(count);
\r
179 CHECK_DATATYPE(datatype, count);
\r
180 CHECK_STATUS(status);
\r
184 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
185 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_at_all", static_cast<double>(count*datatype->size())));
\r
186 int ret = fh->seek(offset,SEEK_SET);
\r
187 if(ret!=MPI_SUCCESS)
\r
189 ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
\r
190 TRACE_smpi_comm_out(rank_traced);
\r
191 smpi_bench_begin();
\r
196 int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
198 CHECK_BUFFER(buf, count);
\r
199 CHECK_OFFSET(offset);
\r
200 CHECK_COUNT(count);
\r
201 PASS_ZEROCOUNT(count);
\r
202 CHECK_DATATYPE(datatype, count);
\r
203 CHECK_STATUS(status);
\r
207 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
208 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", static_cast<double>(count*datatype->size())));
\r
209 int ret = fh->seek(offset,SEEK_SET);
\r
210 if(ret!=MPI_SUCCESS)
\r
212 ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
\r
213 TRACE_smpi_comm_out(rank_traced);
\r
214 smpi_bench_begin();
\r
219 int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
221 CHECK_BUFFER(buf, count);
\r
222 CHECK_OFFSET(offset);
\r
223 CHECK_COUNT(count);
\r
224 CHECK_DATATYPE(datatype, count);
\r
225 CHECK_STATUS(status);
\r
229 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
230 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_at_all", static_cast<double>(count*datatype->size())));
\r
231 int ret = fh->seek(offset,SEEK_SET);
\r
232 if(ret!=MPI_SUCCESS)
\r
234 ret = fh->op_all<simgrid::smpi::File::write>(buf, count, datatype, status);
\r
235 TRACE_smpi_comm_out(rank_traced);
\r
236 smpi_bench_begin();
\r
241 int PMPI_File_delete(char *filename, MPI_Info info){
\r
242 if (filename == nullptr) {
\r
243 return MPI_ERR_FILE;
\r
246 int ret = simgrid::smpi::File::del(filename, info);
\r
247 smpi_bench_begin();
\r
252 int PMPI_File_get_info(MPI_File fh, MPI_Info* info)
\r
256 *info = fh->info();
\r
257 return MPI_SUCCESS;
\r
261 int PMPI_File_set_info(MPI_File fh, MPI_Info info)
\r
265 fh->set_info(info);
\r
266 return MPI_SUCCESS;
\r