--- branches/development/src/io/ifstrstream.cpp 2011/09/13 22:05:04 1627 +++ branches/development/src/io/ifstrstream.cpp 2013/05/15 15:09:35 1874 @@ -35,12 +35,13 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ /** - * @file basic_ifstrstream.cpp + * @file ifstrstream.cpp * @author Teng Lin * @date 10/14/2004 * @version 1.0 @@ -71,9 +72,9 @@ namespace OpenMD { /** * Explicit constructor - * @filename String containing the name of the file to be opened - * @mode Flags describing the requested i/o mode for the file, default value is ios_base::in - * @checkFilename Flags indicating checking the file name in parallel + * @param filename String containing the name of the file to be opened + * @param mode Flags describing the requested i/o mode for the file, default value is ios_base::in + * @param checkFilename Flags indicating checking the file name in parallel */ #ifdef IS_MPI ifstrstream::ifstrstream(const char* filename, std::ios_base::openmode mode, bool checkFilename) @@ -102,9 +103,9 @@ namespace OpenMD { * Opens a file and associats a buffer with the specified file to perform the i/o operations * (single mode). Master reads a file and brocasts its content to the other slave nodes. After * brocasting, every nodes fall back to stringstream (parallel mode). - * @filename String containing the name of the file to be opened - * @mode Flags describing the requested i/o mode for the file - * @checkFilename Flags indicating checking the file name in parallel + * @param filename String containing the name of the file to be opened + * @param mode Flags describing the requested i/o mode for the file + * @param checkFilename Flags indicating checking the file name in parallel */ void ifstrstream::open(const char* filename, std::ios_base::openmode mode, bool checkFilename){ @@ -159,15 +160,16 @@ namespace OpenMD { * Internal function used to open the file * @return true if succesfully opens a file (single mode) or gets the file content (parallel mode) * otherwise return false - * @filename String containing the name of the file to be opened - * @mode Flags describing the requested i/o mode for the file + * @param filename String containing the name of the file to be opened + * @param mode Flags describing the requested i/o mode for the file + * @param checkFilename Flags indicating checking the file name in parallel * @todo use try - catch syntax to make the program more readable */ bool ifstrstream::internalOpen(const char* filename, std::ios_base::openmode mode, bool checkFilename){ #ifdef IS_MPI - int commStatus; + //int commStatus; long fileSize; char* fbuf; int filenameLen; @@ -176,7 +178,7 @@ namespace OpenMD { int myRank; int masterNode; - commStatus = MPI_Comm_rank(MPI_COMM_WORLD, &myRank); + myRank = MPI::COMM_WORLD.Get_rank(); masterNode = 0; if (myRank == masterNode) { @@ -185,12 +187,13 @@ namespace OpenMD { //check the filename is the same filenameLen = strlen(filename); - commStatus = MPI_Bcast(&filenameLen, 1, MPI_INT, masterNode, MPI_COMM_WORLD); - commStatus = MPI_Bcast((void*)filename, filenameLen, MPI_CHAR, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&filenameLen, 1, MPI::INT, masterNode); + MPI::COMM_WORLD.Bcast((void*)filename, filenameLen, MPI::CHAR, + masterNode); diffFilename = 0; - commStatus = MPI_Allreduce(&diffFilename, &error, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); - + MPI::COMM_WORLD.Allreduce(&diffFilename, &error, 1, MPI::INT, MPI::SUM); + //if file names are different just return false if (error > 0) return false; @@ -214,27 +217,27 @@ namespace OpenMD { if (fin.fail()) fileSize = FileIOError; - //brocasting the file size - commStatus = MPI_Bcast(&fileSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); + //broadcast the file size + MPI::COMM_WORLD.Bcast(&fileSize, 1, MPI::LONG, masterNode); if (fileSize < 0) { fin.close(); - delete fbuf; + delete[] fbuf; return false; } - // make a c-style std::string and brocasting it + // make a c-style std::string and broadcast it fbuf[fileSize] = '\0'; - commStatus = MPI_Bcast(fbuf, fileSize + 1, MPI_CHAR, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(fbuf, fileSize + 1, MPI::CHAR, masterNode); //close the file and delete the buffer fin.close(); internalStringBuf_.str(fbuf); - delete [] fbuf; + delete[] fbuf; }else{ fileSize = FileNotExists; - commStatus = MPI_Bcast(&fileSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&fileSize, 1, MPI::LONG, masterNode); return false; } @@ -242,32 +245,33 @@ namespace OpenMD { //check file name if (checkFilename) { - commStatus = MPI_Bcast(&filenameLen, 1, MPI_INT, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&filenameLen, 1, MPI::INT, masterNode); char * masterFilename = new char[filenameLen]; - commStatus = MPI_Bcast(masterFilename, filenameLen, MPI_CHAR, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(masterFilename, filenameLen, MPI::CHAR, + masterNode); if( strcmp(masterFilename, filename) == 0) diffFilename = 0; else diffFilename = 1; - delete masterFilename; + delete[] masterFilename; - commStatus = MPI_Allreduce(&diffFilename, &error, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + MPI::COMM_WORLD.Allreduce(&diffFilename, &error, 1, MPI::INT, MPI::SUM); if (error > 0) return false; } //get file size - commStatus = MPI_Bcast(&fileSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(&fileSize, 1, MPI::LONG, masterNode); if (fileSize >= 0 ) { fbuf = new char[fileSize+1]; assert(fbuf); //receive file content - commStatus = MPI_Bcast(fbuf, fileSize + 1, MPI_CHAR, masterNode, MPI_COMM_WORLD); + MPI::COMM_WORLD.Bcast(fbuf, fileSize + 1, MPI::CHAR, masterNode); internalStringBuf_.str(fbuf); delete [] fbuf;