Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5c14cdf5cb877adf5710e0e3e5227c7238b9570a
[simgrid.git] / src / smpi / bindings / smpi_pmpi_file.cpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */\r
2 \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
5 \r
6 #include "private.hpp"\r
7 #include "smpi_file.hpp"\r
8 #include "smpi_datatype.hpp"\r
9 \r
10 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);\r
11 \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
19   } else {\r
20     smpi_bench_end();\r
21     *fh =  new simgrid::smpi::File(comm, filename, amode, info);\r
22     smpi_bench_begin();\r
23     if (((*fh)->size() == 0 && (not amode & MPI_MODE_CREATE)) ||\r
24        ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL))){\r
25       delete fh;\r
26       return MPI_ERR_AMODE;\r
27     }\r
28     if(amode & MPI_MODE_APPEND)\r
29       (*fh)->seek(0,MPI_SEEK_END);\r
30     return MPI_SUCCESS;\r
31   }\r
32 }\r
33 \r
34 int PMPI_File_close(MPI_File *fh){\r
35   if (fh==nullptr){\r
36     return MPI_ERR_ARG;\r
37   } else {\r
38     smpi_bench_end();\r
39     int ret = simgrid::smpi::File::close(fh);\r
40     *fh = MPI_FILE_NULL;\r
41     smpi_bench_begin();\r
42     return ret;\r
43   }\r
44 }\r
45 \r
46 int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){\r
47   if (fh==MPI_FILE_NULL){\r
48     return MPI_ERR_FILE;\r
49   } else {\r
50     smpi_bench_end();\r
51     int ret = fh->seek(offset,whence);\r
52     smpi_bench_begin();\r
53     return ret;\r
54   }\r
55 }\r
56 \r
57 int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){\r
58   if (fh==MPI_FILE_NULL){\r
59     return MPI_ERR_FILE;\r
60   } else if (buf==nullptr && count > 0){\r
61     return MPI_ERR_BUFFER;\r
62   } else if ( count < 0){\r
63     return MPI_ERR_COUNT;\r
64   } else if ( datatype == MPI_DATATYPE_NULL && count > 0){\r
65     return MPI_ERR_TYPE;\r
66   } else if (status == nullptr){\r
67     return MPI_ERR_ARG;\r
68   } else if (fh->flags() & MPI_MODE_SEQUENTIAL){\r
69     return MPI_ERR_AMODE;\r
70   } else {\r
71     smpi_bench_end();\r
72     int rank_traced = simgrid::s4u::this_actor::get_pid();\r
73     TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", static_cast<double>(count*datatype->size())));\r
74     int ret = fh->read(buf, count, datatype, status);\r
75     TRACE_smpi_comm_out(rank_traced);\r
76     smpi_bench_begin();\r
77     return ret;\r
78   }\r
79 }\r
80 \r
81 \r
82 int PMPI_File_delete(char *filename, MPI_Info info){\r
83   if (filename == nullptr) {\r
84     return MPI_ERR_FILE;\r
85   } else {\r
86     smpi_bench_end();\r
87     int ret = simgrid::smpi::File::del(filename, info);\r
88     smpi_bench_begin();\r
89     return ret;\r
90   }\r
91 }\r
92 \r