[cluster] Some formatting cleanup

standarize whitespace a bit.
Also adds two TODOs for follow up work.

No functional change.
This commit is contained in:
Joost VandeVondele
2018-12-13 23:02:59 +01:00
committed by Stéphane Nicolet
parent 1cd2c7861a
commit 54a0a228f6
5 changed files with 49 additions and 24 deletions
+37 -14
View File
@@ -50,6 +50,7 @@ static std::vector<KeyedTTEntry> TTBuff;
static MPI_Datatype MIDatatype = MPI_DATATYPE_NULL;
void init() {
int thread_support;
MPI_Init_thread(nullptr, nullptr, MPI_THREAD_MULTIPLE, &thread_support);
if (thread_support < MPI_THREAD_MULTIPLE)
@@ -78,10 +79,12 @@ void init() {
}
void finalize() {
MPI_Finalize();
}
bool getline(std::istream& input, std::string& str) {
int size;
std::vector<char> vec;
bool state;
@@ -98,27 +101,31 @@ bool getline(std::istream& input, std::string& str) {
MPI_Ibcast(&size, 1, MPI_INT, 0, InputComm, &reqInput);
if (is_root())
MPI_Wait(&reqInput, MPI_STATUS_IGNORE);
else {
while (true) {
else
{
while (true)
{
int flag;
MPI_Test(&reqInput, &flag, MPI_STATUS_IGNORE);
if (flag)
break;
else {
else
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
}
if (!is_root())
vec.resize(size);
MPI_Bcast(vec.data(), size, MPI_CHAR, 0, InputComm);
if (!is_root())
str.assign(vec.begin(), vec.end());
MPI_Bcast(&state, 1, MPI_CXX_BOOL, 0, InputComm);
return state;
}
void sync_start() {
stop_signal = false;
// Start listening to stop signal
@@ -127,15 +134,19 @@ void sync_start() {
}
void sync_stop() {
if (is_root()) {
if (!stop_signal && Threads.stop) {
if (is_root())
{
if (!stop_signal && Threads.stop)
{
// Signal the cluster about stopping
stop_signal = true;
MPI_Ibarrier(StopComm, &reqStop);
MPI_Wait(&reqStop, MPI_STATUS_IGNORE);
}
}
else {
else
{
int flagStop;
// Check if we've received any stop signal
MPI_Test(&reqStop, &flagStop, MPI_STATUS_IGNORE);
@@ -145,10 +156,12 @@ void sync_stop() {
}
int size() {
return world_size;
}
int rank() {
return world_rank;
}
@@ -185,6 +198,7 @@ void save(Thread* thread, TTEntry* tte,
{
if (irank == size_t(rank()))
continue;
for (size_t i = irank * TTSendBufferSize ; i < (irank + 1) * TTSendBufferSize; ++i)
{
auto&& e = TTBuff[i];
@@ -198,7 +212,8 @@ void save(Thread* thread, TTEntry* tte,
send_buff = {};
// Build up new send buffer: best 16 found across all threads
for (auto&& th : Threads) {
for (auto&& th : Threads)
{
std::lock_guard<Mutex> lk(th->ttBuffer.mutex);
for (auto&& e : th->ttBuffer.buffer)
send_buff.replace(e);
@@ -216,24 +231,32 @@ void save(Thread* thread, TTEntry* tte,
}
void pick_moves(MoveInfo& mi) {
MoveInfo* pMoveInfo = NULL;
if (is_root()) {
if (is_root())
{
pMoveInfo = (MoveInfo*)malloc(sizeof(MoveInfo) * size());
}
MPI_Gather(&mi, 1, MIDatatype, pMoveInfo, 1, MIDatatype, 0, MoveComm);
if (is_root()) {
if (is_root())
{
std::map<int, int> votes;
int minScore = pMoveInfo[0].score;
for (int i = 0; i < size(); i++) {
for (int i = 0; i < size(); ++i)
{
minScore = std::min(minScore, pMoveInfo[i].score);
votes[pMoveInfo[i].move] = 0;
}
for (int i = 0; i < size(); i++) {
for (int i = 0; i < size(); ++i)
{
votes[pMoveInfo[i].move] += pMoveInfo[i].score - minScore + pMoveInfo[i].depth;
}
int bestVote = votes[pMoveInfo[0].move];
for (int i = 0; i < size(); i++) {
if (votes[pMoveInfo[i].move] > bestVote) {
for (int i = 0; i < size(); ++i)
{
if (votes[pMoveInfo[i].move] > bestVote)
{
bestVote = votes[pMoveInfo[i].move];
mi = pMoveInfo[i];
}