datagen merges files | bench 4699541
This commit is contained in:
1 parent
2e46f0d1cd
commit
d35eb66dbc
2 files changed
+54
-19
No files matched your search
@@ -5,6 +5,13 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
#include "datagen.h"
|
#include "datagen.h"
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
@@ -114,6 +121,51 @@ static void WriteToFile(std::vector<Game> &gamesBuffer, std::ofstream &file) {
|
|||||||
file.flush();
|
file.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void MergeThreadFiles() {
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
std::time_t now_time = std::chrono::system_clock::to_time_t(now);
|
||||||
|
std::tm tm = *std::localtime(&now_time);
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "datagen_"
|
||||||
|
<< std::put_time(&tm, "%Y-%m-%d_%H-%M")
|
||||||
|
<< ".binpack";
|
||||||
|
std::string finalFileName = oss.str();
|
||||||
|
|
||||||
|
std::ofstream finalFile(finalFileName, std::ios::binary);
|
||||||
|
if (!finalFile.is_open()) {
|
||||||
|
std::cerr << "Failed to create final merged file: " << finalFileName << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& entry : fs::directory_iterator(fs::current_path())) {
|
||||||
|
if (!entry.is_regular_file()) continue;
|
||||||
|
std::string filename = entry.path().filename().string();
|
||||||
|
|
||||||
|
if (filename.find("thread") == 0 && filename.find(".binpack") != std::string::npos) {
|
||||||
|
std::ifstream threadFile(entry.path(), std::ios::binary);
|
||||||
|
if (!threadFile.is_open()) {
|
||||||
|
std::cerr << "Failed to open " << filename << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
finalFile << threadFile.rdbuf();
|
||||||
|
threadFile.close();
|
||||||
|
|
||||||
|
std::error_code ec;
|
||||||
|
fs::remove(entry.path(), ec);
|
||||||
|
if (ec) {
|
||||||
|
std::cerr << "Failed to delete " << filename << ": " << ec.message() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
finalFile.close();
|
||||||
|
std::cout << "Merged all thread files into: " << finalFileName << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
static void PlayGames(int id, std::atomic<int>& positions, std::atomic<bool>& stopFlag) {
|
static void PlayGames(int id, std::atomic<int>& positions, std::atomic<bool>& stopFlag) {
|
||||||
std::vector<Game> gamesBuffer;
|
std::vector<Game> gamesBuffer;
|
||||||
gamesBuffer.reserve(GAME_BUFFER);
|
gamesBuffer.reserve(GAME_BUFFER);
|
||||||
@@ -283,6 +335,8 @@ void Run(int targetPositions, int threads) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
MergeThreadFiles();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ShowCursor();
|
ShowCursor();
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -34,25 +34,6 @@ struct MarlinFormat {
|
|||||||
this->wdl = wdl;
|
this->wdl = wdl;
|
||||||
extra = 0;
|
extra = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeToFile(const std::string& filename) const {
|
|
||||||
std::ofstream outFile(filename, std::ios::binary);
|
|
||||||
if (!outFile) {
|
|
||||||
std::cerr << "Error opening file for writing!" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&occupancy), sizeof(occupancy));
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&pieces), sizeof(pieces));
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&stmEPSquare), sizeof(stmEPSquare));
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&halfmoveClock), sizeof(halfmoveClock));
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&fullmoveNumber), sizeof(fullmoveNumber));
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&eval), sizeof(eval));
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&wdl), sizeof(wdl));
|
|
||||||
outFile.write(reinterpret_cast<const char*>(&extra), sizeof(extra));
|
|
||||||
|
|
||||||
outFile.close();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ScoredMove {
|
struct ScoredMove {
|
||||||
|
|||||||
Reference in new issue
Block a user