Skip to content

Commit

Permalink
Merge pull request #1 from KyQiao/working
Browse files Browse the repository at this point in the history
update version
  • Loading branch information
KyQiao authored Jul 22, 2021
2 parents 1c1ab6c + 65707db commit d4373f4
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 43 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ include_directories(/src)

add_subdirectory(pybind11)
pybind11_add_module(_logReader ${PythonSOURCES})
target_compile_definitions(_logReader PRIVATE VERSION_INFO=${VERSION_INFO})

add_library(logReader ${SOURCES})

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def build_extension(self, ext):
cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
"-DPYTHON_EXECUTABLE={}".format(sys.executable),
"-DEXAMPLE_VERSION_INFO={}".format(
"-DVERSION_INFO={}".format(
self.distribution.get_version()),
# not used on MSVC, but no harm
"-DCMAKE_BUILD_TYPE={}".format(cfg),
Expand Down Expand Up @@ -121,7 +121,7 @@ def build_extension(self, ext):
# logic and declaration, and simpler if you include description/version in a file.
setup(
name="logReader",
version="0.0.1",
version="0.1.1",
author="Kaiyao QIAO",
author_email="ustkyqiao@gmail.com",
description="reading lammps log file",
Expand Down
291 changes: 279 additions & 12 deletions src/logReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@

#define debug 0

int logReader::checker(std::string s) {
if (s.size() >= 22 && s.substr(0, 22) == "Created orthogonal box") {
auto match = [](std::string target, std::string pattern) {
size_t size = pattern.size();
return (target.size() >= size && target.substr(0, size) == pattern);
};
readFlag logReader::checker(std::string s) {
if (match(s, "Created orthogonal box")) {
// read box info
return 1;
} else if (s.size() >= 30 && s.substr(0, 30) == "Per MPI rank memory allocation") {
return readFlag::BOX;
} else if (match(s, "Per MPI rank memory allocation")) {
// read thermo info
return 2;
return readFlag::THERMO;
} else if (match(s, "Lattice spacing")) {
//read lattice spacing
return readFlag::SPACING;
} else if (match(s, "Performance")) {
//read performance info
return readFlag::PERFORMANCE;
} else if (s.size() >= 15 && s.substr(0, 7) == "Created" && s.substr(s.size() - 5, 5) == "atoms") {
return readFlag::ATOMNUMBER;
}
return -1;
return readFlag::NONE;
};

void logReader::read(std::string fileName) {
#if debug
std::cout << "reading file " << fileName << std::endl;
#endif

int internal_flag = -1;
auto internal_flag = readFlag::NONE;
size_t numberOfRun = 0;

std::ifstream file(fileName, std::ios_base::in);

if (file.fail()) {
Expand All @@ -32,7 +46,7 @@ void logReader::read(std::string fileName) {
// a temp string for storing lines
std::string line;
std::stringstream ss;
std::string tmp;
std::string tmp, dummy;

// useful lambda function
// skip lines in file
Expand All @@ -44,24 +58,62 @@ void logReader::read(std::string fileName) {
// get string into ss
auto ssGet = [&file, &line, &ss]() {
getline(file, line);
// reset buf as empty
ss.str("");
// clear stringstream state
ss.clear();
// input new string line
ss << line;
// using sstream is quite tricky. above is the way to rewrite buffer
};

// main loop for data input
while (std::getline(file, tmp)) {
internal_flag = checker(tmp);
if (internal_flag == 1) {
if (internal_flag == readFlag::BOX) {
#if debug
std::cout << "reading box info from " << fileName << std::endl;
#endif
// check if current run is added
if (this->getSize() < numberOfRun + 1) {
this->runs.push_back(new thermo);
}
// read box info
ss.str("");
ss.clear();
for (size_t i = 0; i < tmp.size(); i++) {
if (tmp[i] == '(') {
tmp[i] = ' ';
} else if (tmp[i] == ')') {
tmp[i] = ' ';
}
}
ss << tmp;
size_t index = 0;

} else if (internal_flag == 2) {
while (index < 6) {
ss >> this->runs.back()->box[index];
if (ss.fail()) {
ss.clear();
ss >> dummy;
} else {
index += 1;
}
}

this->runs.back()->Box_flag = true;
} else if (internal_flag == readFlag::THERMO) {
#if debug
std::cout << "reading thermo info from " << fileName << std::endl;
#endif
// read thermo info
// std::string
size_t index = 0;
ssGet();
this->runs.push_back(new thermo);
// check if current run is added
if (this->getSize() < numberOfRun + 1) {
this->runs.push_back(new thermo);
}
runs.back()->attr_order = line;
while (std::getline(ss, tmp, ' ')) {
this->runs.back()->attr_index[tmp] = index++;
Expand Down Expand Up @@ -89,8 +141,223 @@ void logReader::read(std::string fileName) {
this->runs.back()->attr_table[i].push_back(d_tmp);
}
}
this->runs.back()->Thermo_flag = true;
} else if (internal_flag == readFlag::ATOMNUMBER) {
#if debug
std::cout << "reading particle info from " << fileName << std::endl;
#endif
// check if current run is added
if (this->getSize() < numberOfRun + 1) {
this->runs.push_back(new thermo);
}

} //end of read thermo data
ss.str("");
ss.clear();
ss << tmp;
ss >> this->runs.back()->particleN;
while (ss.fail()) {
ss.clear();
ss >> dummy;
}
this->runs.back()->particleN = true;
} else if (internal_flag == readFlag::SPACING) {
#if debug
std::cout << "reading lattice info from " << fileName << std::endl;
#endif
// check if current run is added
if (this->getSize() < numberOfRun + 1) {
this->runs.push_back(new thermo);
}
ss.str("");
ss.clear();
ss << tmp;
size_t index = 0;
#if debug
std::cout << "parsing line is: " << tmp << std::endl;
#endif
while (index < 3) {
ss >> this->runs.back()->lattice[index];
if (ss.fail()) {
ss.clear();
ss >> dummy;
} else {
#if debug
std::cout << "insert: " << this->runs.back()->lattice[index] << std::endl;
#endif
index += 1;
}
}
this->runs.back()->lattice_flag = true;
} else if (internal_flag == readFlag::PERFORMANCE) {
#if debug
std::cout << "reading performance info from " << fileName << std::endl;
#endif
// check if current run is added
if (this->getSize() < numberOfRun + 1) {
this->runs.push_back(new thermo);
}

ss.str("");
ss.clear();
ss << tmp;

// read general performance info

{
#if debug
std::cout << "1" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
size_t index = 0;
while (index < 2) {
ss >> this->runs.back()->performance[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
// read run general cpu info
{
std::getline(file, tmp);
size_t index = 0;
for (size_t i = 0; i < tmp.size(); i++)
if (tmp[i] == '%')
tmp[i]
= ' ';
ss.str("");
ss.clear();
ss << tmp;
#if debug
std::cout << "2" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
while (index < 3) {
ss >> this->runs.back()->cpu[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
// read tablur info
skipLines(4);

// read Pair info
{
size_t index = 0;
ssGet();
#if debug
std::cout << "3" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
while (index < 5) {
ss >> this->runs.back()->Pair[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
// read Neigh info
{
size_t index = 0;
ssGet();
#if debug
std::cout << "4" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
while (index < 5) {
ss >> this->runs.back()->Neigh[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
// read Comm info
{
size_t index = 0;
ssGet();
#if debug
std::cout << "5" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
while (index < 5) {
ss >> this->runs.back()->Comm[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
// read Output info
{
size_t index = 0;
ssGet();
#if debug
std::cout << "6" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
while (index < 5) {
ss >> this->runs.back()->Output[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
// read Modify info
{
size_t index = 0;
ssGet();
#if debug
std::cout << "7" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
while (index < 5) {
ss >> this->runs.back()->Modify[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
// read Other info
{
size_t index = 0;
ssGet();
#if debug
std::cout << "8" << std::endl;
std::cout << "parsing:" << ss.str() << std::endl;
#endif
while (index < 2) {
ss >> this->runs.back()->Other[index];
if (!ss.fail()) {
index += 1;
} else {
ss.clear();
ss >> dummy;
}
}
}
this->runs.back()->performance_flag = true;
//after reading performance add number of run by 1
numberOfRun += 1;
}
} // end of reading file
};
Loading

0 comments on commit d4373f4

Please sign in to comment.