diff options
Diffstat (limited to 'tabulator-mpi/worker.cpp')
-rw-r--r-- | tabulator-mpi/worker.cpp | 25 |
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]); } } |