From d75da8de6d50ab258a2dca9f9507c577013f04e8 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 27 Nov 2023 19:05:40 -0600 Subject: [PATCH] give up on C --- Dockerfile | 3 +- assignments/03/Makefile | 2 +- assignments/03/lpa.cpp | 87 +++++++++++++++++++---------------------- assignments/03/test.gdb | 2 +- 4 files changed, 45 insertions(+), 49 deletions(-) diff --git a/Dockerfile b/Dockerfile index c988ba5..48772eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ RUN apt update -y && apt install -y --no-install-recommends \ clang \ curl \ direnv \ + gdb \ git \ libomp-dev \ libopenmpi-dev \ @@ -31,6 +32,6 @@ COPY --from=typst /bin/typst /usr/bin/typst RUN curl https://sh.rustup.rs -sSf | bash -s -- -y RUN /root/.cargo/bin/cargo install cargo-watch -RUN /root/.cargo/bin/cargo install watchexec +# RUN /root/.cargo/bin/cargo install watchexec-cli RUN echo 'eval "$(direnv hook bash)"' >> /root/.bashrc \ No newline at end of file diff --git a/assignments/03/Makefile b/assignments/03/Makefile index 836ebdb..794db67 100644 --- a/assignments/03/Makefile +++ b/assignments/03/Makefile @@ -1,6 +1,6 @@ .PHONY: run clean -CFLAGS += -O3 +CFLAGS += -g # CFLAGS += -DFMT_HEADER_ONLY -g # LDFLAGS += $(shell pkg-config --libs fmt) diff --git a/assignments/03/lpa.cpp b/assignments/03/lpa.cpp index f84a85a..22b334f 100644 --- a/assignments/03/lpa.cpp +++ b/assignments/03/lpa.cpp @@ -1,8 +1,3 @@ -#include -#include -#include -#include -#include #include #include #include @@ -12,7 +7,6 @@ #include #include #include -#include #ifdef FMT_HEADER_ONLY #include @@ -182,7 +176,6 @@ int main(int argc, char **argv) { // of the graph. #pragma region int node_label_assignment_vec[num_my_nodes]; - // std::map node_label_assignment; pair my_node_range = node_ranges[rank]; // Initial node assignment @@ -246,12 +239,11 @@ int main(int argc, char **argv) { #pragma region while (true) { // First, exchange the data that needs to be exchanged - std::vector sendbuf; - std::vector send_counts; - std::vector send_displs; - std::vector recv_counts; - std::vector recv_displs; - std::vector recvbuf; + int sendbuf[num_my_nodes]; + int send_counts[p]; + int send_displs[p]; + int recv_counts[p]; + int recv_displs[p]; std::map remote_labels; if (p > 1) { @@ -262,28 +254,27 @@ int main(int argc, char **argv) { for (int i = 0; i < p; ++i) { int count = send_map[i].size(); for (auto local_node : send_map[i]) { - sendbuf.push_back( - node_label_assignment_vec[local_node - my_node_range.fst]); + sendbuf[offset + local_node - my_node_range.fst] = + node_label_assignment_vec[local_node - my_node_range.fst]; } - send_counts.push_back(count); - send_displs.push_back(offset); + send_counts[i] = count; + send_displs[i] = offset; offset += count; } offset = 0; for (int i = 0; i < p; ++i) { int count = recv_map[i].size(); - recv_counts.push_back(count); - recv_displs.push_back(offset); + recv_counts[i] = count; + recv_displs[i] = offset; offset += count; } recv_total = offset; } - recvbuf = std::vector(recv_total, 0); - MPI_Alltoallv(sendbuf.data(), send_counts.data(), send_displs.data(), - MPI_INT, recvbuf.data(), recv_counts.data(), - recv_displs.data(), MPI_INT, MPI_COMM_WORLD); + int recvbuf[recv_total]; + MPI_Alltoallv(sendbuf, send_counts, send_displs, MPI_INT, recvbuf, + recv_counts, recv_displs, MPI_INT, MPI_COMM_WORLD); // Cache efficiently for (int i = 0; i < p; ++i) { @@ -369,8 +360,6 @@ int main(int argc, char **argv) { int count = this_node_range.snd - this_node_range.fst; if (process_idx == 0) { for (int j = 0; j < count; ++j) { - // all_assignments[this_node_range.fst + j] = - // node_label_assignment_vec[j]; fprintf(fp, "%d\n", node_label_assignment_vec[j]); label_count[node_label_assignment_vec[j]]++; } @@ -384,6 +373,9 @@ int main(int argc, char **argv) { } } } + + printf("%d\n", label_count.size()); + } else { MPI_Send(node_label_assignment_vec, num_my_nodes, MPI_INT, 0, TAG_SEND_FINAL_RESULT, MPI_COMM_WORLD); @@ -456,30 +448,33 @@ int lookup_assignment(int *base_node_assignment, pair my_node_range, int index = -1, ctr = 0; std::vector inner(recv_map[process_from].begin(), recv_map[process_from].end()); - // { - // int lo = 0, hi = count; - // while (lo < hi) { - // int mid = (lo + hi) / 2; - // int midk = inner[mid]; - // if (node_number < midk) - // hi = mid; - // else if (node_number > midk) - // lo = mid; - // else { - // index = mid; - // break; - // } - // } - // } - for (int i = 0; i < count; ++i) { - int remote_node = inner[i]; - if (node_number == remote_node) { - index = ctr; - break; + + { + // Use binary search... + int lo = 0, hi = count; + while (lo < hi) { + int mid = (lo + hi) / 2; + int midk = inner[mid]; + if (node_number < midk) + hi = mid; + else if (node_number > midk) + lo = mid; + else { + index = mid; + break; + } } - ctr++; } + // for (int i = 0; i < count; ++i) { + // int remote_node = inner[i]; + // if (node_number == remote_node) { + // index = ctr; + // break; + // } + // ctr++; + // } + // Pull the corresponding value from the map return recvbuf[recv_displs[process_from] + index]; } diff --git a/assignments/03/test.gdb b/assignments/03/test.gdb index 171a8f9..0ea4c26 100644 --- a/assignments/03/test.gdb +++ b/assignments/03/test.gdb @@ -1,5 +1,5 @@ set pagination off -run dataset/both_1000.txt +run dataset/both_1000.txt out.txt bt frame 3 print k \ No newline at end of file