diff options
author | Benji Dial <benji6283@gmail.com> | 2023-05-31 18:52:02 -0400 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2023-05-31 18:52:02 -0400 |
commit | 4534c0c569e18e00ca3e41e292524a381cbaeafe (patch) | |
tree | 9b5c9093fc31692f6eb2db67f8e050cfbb0028c0 /tabulator-mpi | |
parent | 6be4a1d094f7049230dc04329e8c36aca3b20e96 (diff) | |
download | lib94-4534c0c569e18e00ca3e41e292524a381cbaeafe.tar.gz |
change tabulator output, remove score
Diffstat (limited to 'tabulator-mpi')
-rw-r--r-- | tabulator-mpi/constants.hpp | 2 | ||||
-rw-r--r-- | tabulator-mpi/head.cpp | 38 | ||||
-rw-r--r-- | tabulator-mpi/worker.cpp | 25 |
3 files changed, 33 insertions, 32 deletions
diff --git a/tabulator-mpi/constants.hpp b/tabulator-mpi/constants.hpp index 3f80bff..de4dd27 100644 --- a/tabulator-mpi/constants.hpp +++ b/tabulator-mpi/constants.hpp @@ -1,3 +1,3 @@ #define STEPS_TO_TIE 1000000 -#define ROUNDS_PER_CHUNK 500 +#define ROUNDS_PER_CHUNK 200 #define CHUNKS_PER_PAIR 5 diff --git a/tabulator-mpi/head.cpp b/tabulator-mpi/head.cpp index c425865..7026746 100644 --- a/tabulator-mpi/head.cpp +++ b/tabulator-mpi/head.cpp @@ -5,25 +5,27 @@ #include "constants.hpp" -static int **score_results; +static int **wins; static int get_result() { - int result[3]; + int result[4]; MPI_Status status; - MPI_Recv(result, 3, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status); + MPI_Recv(result, 4, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, &status); - if (result[0] != -1) - score_results[result[0]][result[1]] += result[2]; + if (result[0] != -1) { + wins[result[0]][result[1]] += result[2]; + wins[result[1]][result[0]] += result[3]; + } return status.MPI_SOURCE; } void head_main(int comm_size, int warrior_count, const lib94::warrior *const *warriors) { - score_results = new int *[warrior_count]; + wins = new int *[warrior_count]; for (int i = 0; i < warrior_count; ++i) { - score_results[i] = new int[warrior_count]; + wins[i] = new int[warrior_count]; for (int j = 0; j < warrior_count; ++j) - score_results[i][j] = 0; + wins[i][j] = 0; } int chunks = warrior_count * (warrior_count - 1) / 2 * CHUNKS_PER_PAIR; @@ -53,8 +55,8 @@ void head_main(int comm_size, int warrior_count, const lib94::warrior *const *wa for (int x = 0; x < CHUNKS_PER_PAIR; ++x) { ++on_chunk; int rank = get_result(); - int message[3] = {i, j, x * ROUNDS_PER_CHUNK}; - MPI_Send(message, 2, MPI_INT, rank, 0, MPI_COMM_WORLD); + int message[4] = {i, j, x * ROUNDS_PER_CHUNK}; + MPI_Send(message, 4, MPI_INT, rank, 0, MPI_COMM_WORLD); fprintf(stderr, "\x1b[%d;0H%*d | %*s vs %*s | %*d - %*d | %*d / %*d\x1b[0K", rank + 1, rank_width, rank, left_name_width, warriors[i]->name.c_str(), right_name_width, warriors[j]->name.c_str(), left_round_width, x * ROUNDS_PER_CHUNK + 1, right_round_width, x * ROUNDS_PER_CHUNK + ROUNDS_PER_CHUNK, @@ -63,8 +65,8 @@ void head_main(int comm_size, int warrior_count, const lib94::warrior *const *wa for (int i = 0; i < comm_size - 1; ++i) { int rank = get_result(); - int message[3] = {-1}; - MPI_Send(message, 3, MPI_INT, rank, 0, MPI_COMM_WORLD); + int message[4] = {-1}; + MPI_Send(message, 4, MPI_INT, rank, 0, MPI_COMM_WORLD); fprintf(stderr, "\x1b[%d;0H%*d | %*s | %*s | %*s\x1b[0K", rank + 1, rank_width, rank, left_name_width + 4 + right_name_width, "", @@ -74,13 +76,6 @@ void head_main(int comm_size, int warrior_count, const lib94::warrior *const *wa fprintf(stderr, "\x1b[?25h\x1b[?47l\x1b""8"); - for (int i = 0; i < warrior_count; ++i) - for (int j = i + 1; j < warrior_count; ++j) - if (score_results[i][j] < 0) { - score_results[j][i] = -score_results[i][j]; - score_results[i][j] = 0; - } - int *tab_widths = new int[warrior_count + 1]; tab_widths[0] = 0; @@ -109,7 +104,10 @@ void head_main(int comm_size, int warrior_count, const lib94::warrior *const *wa for (int i = 0; i < warrior_count; ++i) { printf(" %*s", tab_widths[0], warriors[i]->name.c_str()); for (int j = 0; j < warrior_count; ++j) - printf(" | %*d", tab_widths[j + 1], score_results[i][j]); + if (i == j) + printf(" | %*s", tab_widths[j + 1], "x"); + else + printf(" | %*d", tab_widths[j + 1], wins[i][j]); putchar('\n'); } } 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]); } } |