Tt test #87
No files matched your search
@@ -28,8 +28,8 @@ else
|
||||
endif
|
||||
endif
|
||||
|
||||
CXXFLAGS := -std=c++20 -O0 -flto -Wall -g
|
||||
LDFLAGS := -O0 -flto
|
||||
CXXFLAGS := -std=c++20 -O3 -flto -Wall
|
||||
LDFLAGS := -O3 -flto
|
||||
|
||||
ifeq ($(PLATFORM),mac)
|
||||
ifeq ($(ARCH),arm64)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
constexpr int BENCH_DEPTH = 5;
|
||||
constexpr int BENCH_DEPTH = 13;
|
||||
|
||||
void RunBenchmark();
|
||||
+28
-8
@@ -2,6 +2,8 @@
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <thread>
|
||||
#include <pthread.h>
|
||||
#include <tuple>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include "datagen.h"
|
||||
@@ -210,11 +212,31 @@ void Run(int targetPositions, int threads) {
|
||||
std::atomic<int> positions = 0;
|
||||
std::atomic<bool> stopFlag = false;
|
||||
|
||||
std::vector<std::thread> workerThreads;
|
||||
std::vector<pthread_t> workerThreads;
|
||||
|
||||
// Start N-1 threads
|
||||
for (int i = 0; i < threads-1; i++) {
|
||||
workerThreads.emplace_back(std::thread(PlayGames, i, std::ref(positions), std::ref(stopFlag)));
|
||||
for (int i = 0; i < threads - 1; ++i) {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2 * 1024 * 1024); // 2 MB stack
|
||||
|
||||
auto* args = new std::tuple<int, std::atomic<int>*, std::atomic<bool>*>(i, &positions, &stopFlag);
|
||||
|
||||
pthread_t thread;
|
||||
if (pthread_create(&thread, &attr,
|
||||
[](void* a) -> void* {
|
||||
auto* tup = static_cast<std::tuple<int, std::atomic<int>*, std::atomic<bool>*>*>(a);
|
||||
PlayGames(std::get<0>(*tup), *std::get<1>(*tup), *std::get<2>(*tup));
|
||||
delete tup;
|
||||
return nullptr;
|
||||
}, args) == 0)
|
||||
{
|
||||
workerThreads.push_back(thread);
|
||||
} else {
|
||||
std::cerr << "Failed to create thread " << i << "\n";
|
||||
delete args;
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
}
|
||||
|
||||
Stopwatch sw;
|
||||
@@ -228,10 +250,8 @@ void Run(int targetPositions, int threads) {
|
||||
|
||||
stopFlag = true;
|
||||
|
||||
for (auto& thread : workerThreads) {
|
||||
if (thread.joinable()) {
|
||||
thread.join();
|
||||
}
|
||||
for (pthread_t& thread : workerThreads) {
|
||||
pthread_join(thread, nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+30
-7
@@ -4,6 +4,8 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <pthread.h>
|
||||
#include <tuple>
|
||||
#include "types.h"
|
||||
#include "movegen.h"
|
||||
#include "search.h"
|
||||
@@ -69,6 +71,33 @@ static int ReadParam(std::string param, std::string &command) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <SEARCH::searchMode mode>
|
||||
static void* ThreadFunc(void* arg) {
|
||||
auto* tup = static_cast<std::tuple<Board*, SearchParams, SEARCH::SearchContext*>*>(arg);
|
||||
SEARCH::SearchPosition<mode>(*std::get<0>(*tup), std::get<1>(*tup), std::get<2>(*tup));
|
||||
delete tup;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void StartSearchThread(Board& board, SearchParams params, SEARCH::SearchContext* ctx) {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, 2 * 1024 * 1024); // 2 MB stack
|
||||
|
||||
pthread_t thread;
|
||||
|
||||
if (params.nodes) {
|
||||
auto* arg = new std::tuple<Board*, SearchParams, SEARCH::SearchContext*>(&board, params, ctx);
|
||||
pthread_create(&thread, &attr, ThreadFunc<SEARCH::nodesMode>, arg);
|
||||
} else {
|
||||
auto* arg = new std::tuple<Board*, SearchParams, SEARCH::SearchContext*>(&board, params, ctx);
|
||||
pthread_create(&thread, &attr, ThreadFunc<SEARCH::normal>, arg);
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
pthread_detach(thread);
|
||||
}
|
||||
|
||||
static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext* ctx) {
|
||||
SearchParams params;
|
||||
|
||||
@@ -87,13 +116,7 @@ static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext* c
|
||||
params.btime = 99999999;
|
||||
}
|
||||
|
||||
if (params.nodes) {
|
||||
auto worker = std::thread(SEARCH::SearchPosition<SEARCH::nodesMode>, std::ref(board), params, ctx);
|
||||
worker.detach();
|
||||
} else {
|
||||
auto worker = std::thread(SEARCH::SearchPosition<SEARCH::normal>, std::ref(board), params, ctx);
|
||||
worker.detach();
|
||||
}
|
||||
StartSearchThread(board, params, ctx);
|
||||
}
|
||||
|
||||
static void SetOption(std::string &command, SEARCH::SearchContext* ctx) {
|
||||
|
||||
Reference in new issue
Block a user