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
64 int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
66 CHECK_BUFFER(buf, count);
\r
68 PASS_ZEROCOUNT(count);
\r
69 CHECK_DATATYPE(datatype, count);
\r
70 CHECK_STATUS(status);
\r
74 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
75 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));
\r
76 int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
\r
77 TRACE_smpi_comm_out(rank_traced);
\r
83 int PMPI_File_write(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
85 CHECK_BUFFER(buf, count);
\r
87 PASS_ZEROCOUNT(count);
\r
88 CHECK_DATATYPE(datatype, count);
\r
89 CHECK_STATUS(status);
\r
93 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
94 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", static_cast<double>(count*datatype->size())));
\r
95 int ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
\r
96 TRACE_smpi_comm_out(rank_traced);
\r
102 int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
104 CHECK_BUFFER(buf, count);
\r
105 CHECK_OFFSET(offset);
\r
106 CHECK_COUNT(count);
\r
107 PASS_ZEROCOUNT(count);
\r
108 CHECK_DATATYPE(datatype, count);
\r
109 CHECK_STATUS(status);
\r
113 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
114 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));
\r
115 int ret = fh->seek(offset,SEEK_SET);
\r
116 if(ret!=MPI_SUCCESS)
\r
118 ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
\r
119 TRACE_smpi_comm_out(rank_traced);
\r
120 smpi_bench_begin();
\r
126 int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
\r
128 CHECK_BUFFER(buf, count);
\r
129 CHECK_OFFSET(offset);
\r
130 CHECK_COUNT(count);
\r
131 PASS_ZEROCOUNT(count);
\r
132 CHECK_DATATYPE(datatype, count);
\r
133 CHECK_STATUS(status);
\r
137 int rank_traced = simgrid::s4u::this_actor::get_pid();
\r
138 TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", static_cast<double>(count*datatype->size())));
\r
139 int ret = fh->seek(offset,SEEK_SET);
\r
140 if(ret!=MPI_SUCCESS)
\r
142 ret = simgrid::smpi::File::write(fh, buf, count, datatype, status);
\r
143 TRACE_smpi_comm_out(rank_traced);
\r
144 smpi_bench_begin();
\r
149 int PMPI_File_delete(char *filename, MPI_Info info){
\r
150 if (filename == nullptr) {
\r
151 return MPI_ERR_FILE;
\r
154 int ret = simgrid::smpi::File::del(filename, info);
\r
155 smpi_bench_begin();
\r