diff options
author | Benji Dial <benji@benjidial.net> | 2023-05-30 03:01:25 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2023-05-30 03:01:25 -0400 |
commit | 6678dccccdfffb9c40f64a828fd769c53bb2d29f (patch) | |
tree | 4a7f1c0b849b8bc4cebe5c9c0bc690a0e6e07146 /tabulator-mpi/worker.cpp | |
parent | e39e53f96e0fb75847bd2f5eb40cac7c52e85886 (diff) | |
download | lib94-6678dccccdfffb9c40f64a828fd769c53bb2d29f.tar.gz |
mpi-based tabulator
Diffstat (limited to 'tabulator-mpi/worker.cpp')
-rw-r--r-- | tabulator-mpi/worker.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tabulator-mpi/worker.cpp b/tabulator-mpi/worker.cpp new file mode 100644 index 0000000..e9768b2 --- /dev/null +++ b/tabulator-mpi/worker.cpp @@ -0,0 +1,43 @@ +#include <lib94/lib94.hpp> +#include <mpi.h> + +static int do_round(const lib94::warrior *w1, const lib94::warrior *w2) { + const lib94::warrior *ws[2] = {w1, w2}; + + lib94::instruction background = { + .op = lib94::DAT, .mod = lib94::F, + .amode = lib94::DIRECT, .bmode = lib94::DIRECT, + .anumber = 0, .bnumber = 0 + }; + + lib94::clear_core(background); + + lib94::init_round(ws, 2); + + for (int i = 0; i < 1000000; ++i) { + const lib94::warrior *result = lib94::single_step(); + if (result == w1) + return -1; + if (result == w2) + return 1; + } + + return 0; +} + +void worker_main(const lib94::warrior *const *warriors) { + int buffer[3] = {-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); + + if (buffer[0] == -1) + return; + + buffer[2] = 0; + + for (int i = 0; i < 100; ++i) + buffer[2] += do_round(warriors[buffer[0]], warriors[buffer[1]]); + } +} |