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 \
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

View file

@ -1,6 +1,6 @@
.PHONY: run clean
CFLAGS += -O3
CFLAGS += -g
# CFLAGS += -DFMT_HEADER_ONLY -g
# 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 <set>
#include <vector>
@ -12,7 +7,6 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <utility>
#ifdef FMT_HEADER_ONLY
#include <fmt/format.h>
@ -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<int, int> 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<int> sendbuf;
std::vector<int> send_counts;
std::vector<int> send_displs;
std::vector<int> recv_counts;
std::vector<int> recv_displs;
std::vector<int> recvbuf;
int sendbuf[num_my_nodes];
int send_counts[p];
int send_displs[p];
int recv_counts[p];
int recv_displs[p];
std::map<int, int> 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<int>(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,29 +448,32 @@ int lookup_assignment(int *base_node_assignment, pair my_node_range,
int index = -1, ctr = 0;
std::vector<int> 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;
{
// 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];

View file

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