summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2023-05-30 21:49:05 -0400
committerBenji Dial <benji@benjidial.net>2023-05-30 21:49:05 -0400
commit1a0a068b87e3f04e9c7301b6c7b238dc4baf1af2 (patch)
tree2299c47a245b35960ecbafc5cf7aaa331ca6bdb2
parent6b2cbe6c00c1b008e3145c1adf6096640f4e7bbd (diff)
downloadlib94-1a0a068b87e3f04e9c7301b6c7b238dc4baf1af2.tar.gz
move tabulator-mpi's parameters into separate file for easier changing
-rw-r--r--tabulator-mpi/constants.hpp3
-rw-r--r--tabulator-mpi/head.cpp9
-rw-r--r--tabulator-mpi/worker.cpp6
3 files changed, 13 insertions, 5 deletions
diff --git a/tabulator-mpi/constants.hpp b/tabulator-mpi/constants.hpp
new file mode 100644
index 0000000..c8f18e2
--- /dev/null
+++ b/tabulator-mpi/constants.hpp
@@ -0,0 +1,3 @@
+#define STEPS_TO_TIE 1000000
+#define ROUNDS_PER_CHUNK 100
+#define CHUNKS_PER_PAIR 10
diff --git a/tabulator-mpi/head.cpp b/tabulator-mpi/head.cpp
index e2372bc..bd270af 100644
--- a/tabulator-mpi/head.cpp
+++ b/tabulator-mpi/head.cpp
@@ -2,6 +2,8 @@
#include <cstdio>
#include <mpi.h>
+#include "constants.hpp"
+
static int **score_results;
static int get_result() {
@@ -26,11 +28,12 @@ void head_main(int comm_size, int warrior_count, const lib94::warrior *const *wa
for (int i = 0; i < warrior_count; ++i)
for (int j = i + 1; j < warrior_count; ++j) {
fprintf(stderr, "%s vs %s\n", warriors[i]->name.c_str(), warriors[j]->name.c_str());
- for (int x = 0; x < 10; ++x) {
+ for (int x = 0; x < CHUNKS_PER_PAIR; ++x) {
int rank = get_result();
- int message[3] = {i, j, x * 100};
+ int message[3] = {i, j, x * ROUNDS_PER_CHUNK};
MPI_Send(message, 2, MPI_INT, rank, 0, MPI_COMM_WORLD);
- fprintf(stderr, "sent rounds %d through %d to worker %d\n", x * 100 + 1, x * 100 + 100, rank);
+ fprintf(stderr, "sent rounds %d through %d to worker %d\n",
+ x * ROUNDS_PER_CHUNK + 1, x * ROUNDS_PER_CHUNK + ROUNDS_PER_CHUNK, rank);
}
fputc('\n', stderr);
}
diff --git a/tabulator-mpi/worker.cpp b/tabulator-mpi/worker.cpp
index 47b8eeb..5a20db2 100644
--- a/tabulator-mpi/worker.cpp
+++ b/tabulator-mpi/worker.cpp
@@ -1,6 +1,8 @@
#include <lib94/lib94.hpp>
#include <mpi.h>
+#include "constants.hpp"
+
static int do_round(const lib94::warrior *w1, const lib94::warrior *w2) {
const lib94::warrior *ws[2] = {w1, w2};
@@ -14,7 +16,7 @@ static int do_round(const lib94::warrior *w1, const lib94::warrior *w2) {
lib94::init_round(ws, 2);
- for (int i = 0; i < 1000000; ++i) {
+ for (int i = 0; i < STEPS_TO_TIE; ++i) {
const lib94::warrior *result = lib94::single_step<false>();
if (result == w1)
return -1;
@@ -37,7 +39,7 @@ void worker_main(const lib94::warrior *const *warriors) {
buffer[2] = 0;
- for (int i = 0; i < 100; ++i)
+ for (int i = 0; i < ROUNDS_PER_CHUNK; ++i)
buffer[2] += do_round(warriors[buffer[0]], warriors[buffer[1]]);
}
}