SIONlib  1.7.4
Scalable I/O library for parallel access to task-local files
sion_cxx_mpi.cpp
1 
2 #include "mpi.h"
3 
4 #include "sion_cxx_mpi.hpp"
5 
6 namespace sionlib {
7 
8  namespace mpi {
9 
10  SIONFile::SIONFile() {
11  std::cerr << "At least name has to be given\n";
12  exit (EXIT_FAILURE);
13  }
14 
15  SIONFile::SIONFile(std::string sion_file_name, std::string mode, int num_files,
16  int global_rank, MPI_Comm gComm, MPI_Comm lComm) {
17 
18  size_t ncharacter = sion_file_name.length()+1;
19  const char * tmp_sion_file_name = sion_file_name.c_str();
20  _sion_file_name = new char[ncharacter];
21 
22  strncpy(_sion_file_name, tmp_sion_file_name, ncharacter);
23 
24  _mode = mode;
25  _num_files = num_files;
26 
27  _g_comm = gComm;
28 
29  _l_comm = lComm;
30 
31  _chunk_size = 2097152;
32  _fs_blk_size = -1;
33 
34  _file_ptr = NULL;
35  _new_sion_file_name = new char[255];
36 
37  }
38 
39  SIONFile::~SIONFile() {
40  delete [] _sion_file_name;
41  _sion_file_name = NULL;
42  delete [] _new_sion_file_name;
43  _new_sion_file_name = NULL;
44  // sion_parclose_mpi(_sid);
45  }
46 
47  //void SIONFile::setSionFileName(std::string sion_file_name) {
48  // _sion_file_name = sion_file_name;
49  //}
50 
51  void SIONFile::setLocalCommunicator(MPI_Comm lComm) {
52  _l_comm = lComm;
53  }
54 
55  MPI_Comm SIONFile::getLocalCommunicator() const {
56  return _l_comm;
57  }
58 
59  void SIONFile::setGlobalCommunicator(MPI_Comm gComm) {
60  _g_comm = gComm;
61  }
62 
63  MPI_Comm SIONFile::getGlobalCommunicator() const {
64  return _g_comm;
65  }
66 
67  void SIONFile::setGlobalRank(int global_rank) {
68  _global_rank = global_rank;
69  }
70 
71  int SIONFile::getGlobalRank() const {
72  return _global_rank;
73  }
74 
75  char * SIONFile::getNewSionFileName() const {
76  return _new_sion_file_name;
77  }
78  //std::ostream* SIONFile::getSionStream() const {
79  // return _sion_stream;
80  //}
81 
82  // sion_paropen_mpi
83  //int SIONFile::open() {
84  //
85  // _sid = sion_paropen_mpi(_sion_file_name,
86  // _mode.c_str(),
87  // &_num_files,
88  // MPI_COMM_WORLD,
89  // &_l_comm,
90  // &_chunk_size,
91  // &_fs_blk_size,
92  // &_global_rank,
93  // &_file_ptr,
94  // &_new_sion_file_name);
96  // return _sid;
97  //
98  //}
99 
100  void SIONFile::open() {
101  _sid = sion_paropen_mpi(_sion_file_name, _mode.c_str(), &_num_files,
102  _g_comm, &_l_comm, &_chunk_size, &_fs_blk_size,
103  &_global_rank, NULL, &_new_sion_file_name);
104  _return_code = _sid;
105  }
106 
107  void SIONFile::close() {
108  // fwrite(void *).
109  _return_code = sion_parclose_mpi (_sid);
110  }
111 
112  //void SIONFile::read() {
114  // double * buffer = new double();
115  // sion_fread(buffer, 1, 8, _sid);
116  // std::cout << *buffer << std::endl;
117  //}
118 
119  void SIONFile::ensureFreeSpace(long numbytes) {
120  _return_code = sion_ensure_free_space(_sid, numbytes);
121  }
122 
123  void SIONFile::endOfFile() {
124  _return_code = sion_feof(_sid);
125  }
126 
127  } /* namespace mpi */
128 } /* namespace sionlib */
int sion_feof(int sid)
Function that indicates whether the end of file is reached for this task.
Definition: sion_common.c:809
int sion_ensure_free_space(int sid, sion_int64 bytes)
Funtion to ensure that enough space is available for writing.
Definition: sion_common.c:1053
int sion_paropen_mpi(const char *fname, const char *file_mode, int *numFiles, MPI_Comm gComm, const MPI_Comm *lComm, sion_int64 *chunksize, sion_int32 *fsblksize, int *globalrank, FILE **fileptr, char **newfname)
Open a sion file using MPI.
Definition: sion_mpi_gen.c:85
int sion_parclose_mpi(int sid)
Close a sion file using MPI.
Definition: sion_mpi_gen.c:230