diff options
Diffstat (limited to 'tabulator-mpi/head.cpp')
-rw-r--r-- | tabulator-mpi/head.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
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'); } } |