summaryrefslogtreecommitdiff
path: root/tabulator-mpi/worker.cpp
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2023-05-31 18:52:02 -0400
committerBenji Dial <benji6283@gmail.com>2023-05-31 18:52:02 -0400
commit4534c0c569e18e00ca3e41e292524a381cbaeafe (patch)
tree9b5c9093fc31692f6eb2db67f8e050cfbb0028c0 /tabulator-mpi/worker.cpp
parent6be4a1d094f7049230dc04329e8c36aca3b20e96 (diff)
downloadlib94-4534c0c569e18e00ca3e41e292524a381cbaeafe.tar.gz
change tabulator output, remove score
Diffstat (limited to 'tabulator-mpi/worker.cpp')
-rw-r--r--tabulator-mpi/worker.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/tabulator-mpi/worker.cpp b/tabulator-mpi/worker.cpp
index 5a20db2..ea1b17a 100644
--- a/tabulator-mpi/worker.cpp
+++ b/tabulator-mpi/worker.cpp
@@ -3,7 +3,7 @@
#include "constants.hpp"
-static int do_round(const lib94::warrior *w1, const lib94::warrior *w2) {
+static void do_round(const lib94::warrior *w1, const lib94::warrior *w2, int &w1_wins, int& w2_wins) {
const lib94::warrior *ws[2] = {w1, w2};
lib94::instruction background = {
@@ -18,28 +18,31 @@ static int do_round(const lib94::warrior *w1, const lib94::warrior *w2) {
for (int i = 0; i < STEPS_TO_TIE; ++i) {
const lib94::warrior *result = lib94::single_step<false>();
- if (result == w1)
- return -1;
- if (result == w2)
- return 1;
+ if (result == w1) {
+ ++w2_wins;
+ return;
+ }
+ if (result == w2) {
+ ++w1_wins;
+ return;
+ }
}
-
- return 0;
}
void worker_main(const lib94::warrior *const *warriors) {
- int buffer[3] = {-1};
+ int buffer[4] = {-1};
while (1) {
- MPI_Send(buffer, 3, MPI_INT, 0, 1, MPI_COMM_WORLD);
- MPI_Recv(buffer, 3, MPI_INT, 0, 0, MPI_COMM_WORLD, 0);
+ MPI_Send(buffer, 4, MPI_INT, 0, 1, MPI_COMM_WORLD);
+ MPI_Recv(buffer, 4, MPI_INT, 0, 0, MPI_COMM_WORLD, 0);
if (buffer[0] == -1)
return;
buffer[2] = 0;
+ buffer[3] = 0;
for (int i = 0; i < ROUNDS_PER_CHUNK; ++i)
- buffer[2] += do_round(warriors[buffer[0]], warriors[buffer[1]]);
+ do_round(warriors[buffer[0]], warriors[buffer[1]], buffer[2], buffer[3]);
}
}