Loading src/libnptm/file_io.cpp +61 −47 Original line number Original line Diff line number Diff line Loading @@ -277,9 +277,10 @@ VirtualAsciiFile::VirtualAsciiFile(const mixMPI *mpidata, int rr) { VirtualAsciiFile::~VirtualAsciiFile() { VirtualAsciiFile::~VirtualAsciiFile() { // is it necessary to pop them out one by one? isn't there the dedicated method of std::vector to clean the vector? // is it necessary to pop them out one by one? isn't there the dedicated method of std::vector to clean the vector? // besides, shouldn't this be done anyway by the destructor of std:vector? // besides, shouldn't this be done anyway by the destructor of std:vector? while (!_file_lines->size() > 0) { _file_lines->clear(); _file_lines->pop_back(); // while (_file_lines->size() > 0) { } // _file_lines->pop_back(); // } if (_file_lines != NULL) delete _file_lines; if (_file_lines != NULL) delete _file_lines; } } Loading @@ -300,6 +301,7 @@ void VirtualAsciiFile::append_line(const string& line) { int VirtualAsciiFile::append_to_disk(const std::string& file_name) { int VirtualAsciiFile::append_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::app); output_file.open(file_name, ios::app); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -310,6 +312,7 @@ int VirtualAsciiFile::append_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -334,6 +337,7 @@ int VirtualAsciiFile::insert(int32_t position, VirtualAsciiFile& rhs, int32_t st int VirtualAsciiFile::write_to_disk(const std::string& file_name) { int VirtualAsciiFile::write_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, replacing the given file_name // dump to disk the contents of the virtualasciifile, replacing the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::out); output_file.open(file_name, ios::out); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -344,6 +348,7 @@ int VirtualAsciiFile::write_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -354,6 +359,7 @@ void VirtualAsciiFile::mpisend(const mixMPI *mpidata) { int32_t num_lines = _file_lines->size(); int32_t num_lines = _file_lines->size(); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); // now loop over data to send // now loop over data to send if (num_lines>0) { int32_t mysize; int32_t mysize; for (vector<string>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { for (vector<string>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { // send the length of each string // send the length of each string Loading @@ -363,6 +369,7 @@ void VirtualAsciiFile::mpisend(const mixMPI *mpidata) { MPI_Send(it->c_str(), mysize+1, MPI_CHAR, 0, 10, MPI_COMM_WORLD); MPI_Send(it->c_str(), mysize+1, MPI_CHAR, 0, 10, MPI_COMM_WORLD); } } } } } #endif #endif /* >>> End of VirtualAsciiFile class implementation <<< */ /* >>> End of VirtualAsciiFile class implementation <<< */ Loading Loading @@ -483,9 +490,10 @@ VirtualBinaryFile::~VirtualBinaryFile() { // for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { // for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { // delete it; // delete it; // } // } while (!_file_lines->size() > 0) { _file_lines->clear(); _file_lines->pop_back(); // while (_file_lines->size() > 0) { } // _file_lines->pop_back(); // } if (_file_lines != NULL) delete _file_lines; if (_file_lines != NULL) delete _file_lines; } } Loading @@ -506,6 +514,7 @@ void VirtualBinaryFile::append_line(const VirtualBinaryLine& line) { int VirtualBinaryFile::append_to_disk(const std::string& file_name) { int VirtualBinaryFile::append_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::app | ios::binary); output_file.open(file_name, ios::app | ios::binary); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -516,6 +525,7 @@ int VirtualBinaryFile::append_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -541,6 +551,7 @@ int VirtualBinaryFile::append_to_disk(const std::string& file_name) { int VirtualBinaryFile::write_to_disk(const std::string& file_name) { int VirtualBinaryFile::write_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, replacing the given file_name // dump to disk the contents of the virtualasciifile, replacing the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::out | ios::binary); output_file.open(file_name, ios::out | ios::binary); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -551,6 +562,7 @@ int VirtualBinaryFile::write_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -561,10 +573,12 @@ void VirtualBinaryFile::mpisend(const mixMPI *mpidata) { int32_t num_lines = _file_lines->size(); int32_t num_lines = _file_lines->size(); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); // now loop over data to send // now loop over data to send if (num_lines>0) { for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { it->mpisend(mpidata); it->mpisend(mpidata); } } } } } #endif #endif /* >>> End of VirtualBinaryFile class implementation <<< */ /* >>> End of VirtualBinaryFile class implementation <<< */ Loading
src/libnptm/file_io.cpp +61 −47 Original line number Original line Diff line number Diff line Loading @@ -277,9 +277,10 @@ VirtualAsciiFile::VirtualAsciiFile(const mixMPI *mpidata, int rr) { VirtualAsciiFile::~VirtualAsciiFile() { VirtualAsciiFile::~VirtualAsciiFile() { // is it necessary to pop them out one by one? isn't there the dedicated method of std::vector to clean the vector? // is it necessary to pop them out one by one? isn't there the dedicated method of std::vector to clean the vector? // besides, shouldn't this be done anyway by the destructor of std:vector? // besides, shouldn't this be done anyway by the destructor of std:vector? while (!_file_lines->size() > 0) { _file_lines->clear(); _file_lines->pop_back(); // while (_file_lines->size() > 0) { } // _file_lines->pop_back(); // } if (_file_lines != NULL) delete _file_lines; if (_file_lines != NULL) delete _file_lines; } } Loading @@ -300,6 +301,7 @@ void VirtualAsciiFile::append_line(const string& line) { int VirtualAsciiFile::append_to_disk(const std::string& file_name) { int VirtualAsciiFile::append_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::app); output_file.open(file_name, ios::app); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -310,6 +312,7 @@ int VirtualAsciiFile::append_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -334,6 +337,7 @@ int VirtualAsciiFile::insert(int32_t position, VirtualAsciiFile& rhs, int32_t st int VirtualAsciiFile::write_to_disk(const std::string& file_name) { int VirtualAsciiFile::write_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, replacing the given file_name // dump to disk the contents of the virtualasciifile, replacing the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::out); output_file.open(file_name, ios::out); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -344,6 +348,7 @@ int VirtualAsciiFile::write_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -354,6 +359,7 @@ void VirtualAsciiFile::mpisend(const mixMPI *mpidata) { int32_t num_lines = _file_lines->size(); int32_t num_lines = _file_lines->size(); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); // now loop over data to send // now loop over data to send if (num_lines>0) { int32_t mysize; int32_t mysize; for (vector<string>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { for (vector<string>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { // send the length of each string // send the length of each string Loading @@ -363,6 +369,7 @@ void VirtualAsciiFile::mpisend(const mixMPI *mpidata) { MPI_Send(it->c_str(), mysize+1, MPI_CHAR, 0, 10, MPI_COMM_WORLD); MPI_Send(it->c_str(), mysize+1, MPI_CHAR, 0, 10, MPI_COMM_WORLD); } } } } } #endif #endif /* >>> End of VirtualAsciiFile class implementation <<< */ /* >>> End of VirtualAsciiFile class implementation <<< */ Loading Loading @@ -483,9 +490,10 @@ VirtualBinaryFile::~VirtualBinaryFile() { // for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { // for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { // delete it; // delete it; // } // } while (!_file_lines->size() > 0) { _file_lines->clear(); _file_lines->pop_back(); // while (_file_lines->size() > 0) { } // _file_lines->pop_back(); // } if (_file_lines != NULL) delete _file_lines; if (_file_lines != NULL) delete _file_lines; } } Loading @@ -506,6 +514,7 @@ void VirtualBinaryFile::append_line(const VirtualBinaryLine& line) { int VirtualBinaryFile::append_to_disk(const std::string& file_name) { int VirtualBinaryFile::append_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name // dump to disk the contents of the virtualasciifile, appending at the end of the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::app | ios::binary); output_file.open(file_name, ios::app | ios::binary); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -516,6 +525,7 @@ int VirtualBinaryFile::append_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -541,6 +551,7 @@ int VirtualBinaryFile::append_to_disk(const std::string& file_name) { int VirtualBinaryFile::write_to_disk(const std::string& file_name) { int VirtualBinaryFile::write_to_disk(const std::string& file_name) { // dump to disk the contents of the virtualasciifile, replacing the given file_name // dump to disk the contents of the virtualasciifile, replacing the given file_name int result = 0; int result = 0; if (_file_lines->size() > 0) { fstream output_file; fstream output_file; output_file.open(file_name, ios::out | ios::binary); output_file.open(file_name, ios::out | ios::binary); if (output_file.is_open()) { if (output_file.is_open()) { Loading @@ -551,6 +562,7 @@ int VirtualBinaryFile::write_to_disk(const std::string& file_name) { } else { } else { result = 1; result = 1; } } } return result; return result; } } Loading @@ -561,10 +573,12 @@ void VirtualBinaryFile::mpisend(const mixMPI *mpidata) { int32_t num_lines = _file_lines->size(); int32_t num_lines = _file_lines->size(); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); MPI_Send(&num_lines, 1, MPI_INT32_T, 0, 10, MPI_COMM_WORLD); // now loop over data to send // now loop over data to send if (num_lines>0) { for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { for (vector<VirtualBinaryLine>::iterator it = _file_lines->begin(); it != _file_lines->end(); ++it) { it->mpisend(mpidata); it->mpisend(mpidata); } } } } } #endif #endif /* >>> End of VirtualBinaryFile class implementation <<< */ /* >>> End of VirtualBinaryFile class implementation <<< */