give up on C

This commit is contained in:
Michael Zhang 2023-11-27 19:05:40 -06:00
parent 584a919ff1
commit d75da8de6d
4 changed files with 45 additions and 49 deletions

View file

@ -12,6 +12,7 @@ RUN apt update -y && apt install -y --no-install-recommends \
clang \ clang \
curl \ curl \
direnv \ direnv \
gdb \
git \ git \
libomp-dev \ libomp-dev \
libopenmpi-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 curl https://sh.rustup.rs -sSf | bash -s -- -y
RUN /root/.cargo/bin/cargo install cargo-watch 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 RUN echo 'eval "$(direnv hook bash)"' >> /root/.bashrc

View file

@ -1,6 +1,6 @@
.PHONY: run clean .PHONY: run clean
CFLAGS += -O3 CFLAGS += -g
# CFLAGS += -DFMT_HEADER_ONLY -g # CFLAGS += -DFMT_HEADER_ONLY -g
# LDFLAGS += $(shell pkg-config --libs fmt) # LDFLAGS += $(shell pkg-config --libs fmt)

View file

@ -1,8 +1,3 @@
#include <algorithm>
#include <array>
#include <cstring>
#include <functional>
#include <limits>
#include <map> #include <map>
#include <set> #include <set>
#include <vector> #include <vector>
@ -12,7 +7,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <utility>
#ifdef FMT_HEADER_ONLY #ifdef FMT_HEADER_ONLY
#include <fmt/format.h> #include <fmt/format.h>
@ -182,7 +176,6 @@ int main(int argc, char **argv) {
// of the graph. // of the graph.
#pragma region #pragma region
int node_label_assignment_vec[num_my_nodes]; int node_label_assignment_vec[num_my_nodes];
// std::map<int, int> node_label_assignment;
pair my_node_range = node_ranges[rank]; pair my_node_range = node_ranges[rank];
// Initial node assignment // Initial node assignment
@ -246,12 +239,11 @@ int main(int argc, char **argv) {
#pragma region #pragma region
while (true) { while (true) {
// First, exchange the data that needs to be exchanged // First, exchange the data that needs to be exchanged
std::vector<int> sendbuf; int sendbuf[num_my_nodes];
std::vector<int> send_counts; int send_counts[p];
std::vector<int> send_displs; int send_displs[p];
std::vector<int> recv_counts; int recv_counts[p];
std::vector<int> recv_displs; int recv_displs[p];
std::vector<int> recvbuf;
std::map<int, int> remote_labels; std::map<int, int> remote_labels;
if (p > 1) { if (p > 1) {
@ -262,28 +254,27 @@ int main(int argc, char **argv) {
for (int i = 0; i < p; ++i) { for (int i = 0; i < p; ++i) {
int count = send_map[i].size(); int count = send_map[i].size();
for (auto local_node : send_map[i]) { for (auto local_node : send_map[i]) {
sendbuf.push_back( sendbuf[offset + local_node - my_node_range.fst] =
node_label_assignment_vec[local_node - my_node_range.fst]); node_label_assignment_vec[local_node - my_node_range.fst];
} }
send_counts.push_back(count); send_counts[i] = count;
send_displs.push_back(offset); send_displs[i] = offset;
offset += count; offset += count;
} }
offset = 0; offset = 0;
for (int i = 0; i < p; ++i) { for (int i = 0; i < p; ++i) {
int count = recv_map[i].size(); int count = recv_map[i].size();
recv_counts.push_back(count); recv_counts[i] = count;
recv_displs.push_back(offset); recv_displs[i] = offset;
offset += count; offset += count;
} }
recv_total = offset; recv_total = offset;
} }
recvbuf = std::vector<int>(recv_total, 0); int recvbuf[recv_total];
MPI_Alltoallv(sendbuf.data(), send_counts.data(), send_displs.data(), MPI_Alltoallv(sendbuf, send_counts, send_displs, MPI_INT, recvbuf,
MPI_INT, recvbuf.data(), recv_counts.data(), recv_counts, recv_displs, MPI_INT, MPI_COMM_WORLD);
recv_displs.data(), MPI_INT, MPI_COMM_WORLD);
// Cache efficiently // Cache efficiently
for (int i = 0; i < p; ++i) { 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; int count = this_node_range.snd - this_node_range.fst;
if (process_idx == 0) { if (process_idx == 0) {
for (int j = 0; j < count; ++j) { 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]); fprintf(fp, "%d\n", node_label_assignment_vec[j]);
label_count[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 { } else {
MPI_Send(node_label_assignment_vec, num_my_nodes, MPI_INT, 0, MPI_Send(node_label_assignment_vec, num_my_nodes, MPI_INT, 0,
TAG_SEND_FINAL_RESULT, MPI_COMM_WORLD); TAG_SEND_FINAL_RESULT, MPI_COMM_WORLD);
@ -456,29 +448,32 @@ int lookup_assignment(int *base_node_assignment, pair my_node_range,
int index = -1, ctr = 0; int index = -1, ctr = 0;
std::vector<int> inner(recv_map[process_from].begin(), std::vector<int> inner(recv_map[process_from].begin(),
recv_map[process_from].end()); recv_map[process_from].end());
// {
// int lo = 0, hi = count; {
// while (lo < hi) { // Use binary search...
// int mid = (lo + hi) / 2; int lo = 0, hi = count;
// int midk = inner[mid]; while (lo < hi) {
// if (node_number < midk) int mid = (lo + hi) / 2;
// hi = mid; int midk = inner[mid];
// else if (node_number > midk) if (node_number < midk)
// lo = mid; hi = mid;
// else { else if (node_number > midk)
// index = mid; lo = mid;
// break; else {
// } index = mid;
// }
// }
for (int i = 0; i < count; ++i) {
int remote_node = inner[i];
if (node_number == remote_node) {
index = ctr;
break; 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 // Pull the corresponding value from the map
return recvbuf[recv_displs[process_from] + index]; return recvbuf[recv_displs[process_from] + index];

View file

@ -1,5 +1,5 @@
set pagination off set pagination off
run dataset/both_1000.txt run dataset/both_1000.txt out.txt
bt bt
frame 3 frame 3
print k print k