more shit

This commit is contained in:
Michael Zhang 2023-11-25 03:23:37 +00:00
parent d7d251bac5
commit ce54410a21

View file

@ -21,6 +21,13 @@
#define TAG_SEND_EDGES 1002
#define TAG_SEND_FINAL_RESULT 1003
#define min(a, b) \
({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a < _b ? _a : _b; \
})
typedef struct {
int fst;
int snd;
@ -76,13 +83,6 @@ int main(int argc, char **argv) {
rank == p - 1 ? total_num_nodes - rank * each_num_nodes : each_num_nodes;
int my_nodes[num_my_nodes];
// std::function<std::pair<int, int>(int)> node_range =
// [p, total_num_nodes, each_num_nodes](int process) {
// int start = process * each_num_nodes;
// int end = process == p - 1 ? total_num_nodes : start +
// each_num_nodes; return std::make_pair(start, end);
// };
// Read the edges
int num_my_edges;
pair *my_edges;
@ -148,7 +148,7 @@ int main(int argc, char **argv) {
char *buf = (char *)calloc(sizeof(char), 1000);
int offset = 0; // Keep track of the current position in the buffer
for (int i = 0; i < std::min(num_my_edges, 5); i++) {
for (int i = 0; i < min(num_my_edges, 5); i++) {
offset +=
sprintf(buf + offset, "(%d, %d)", my_edges[i].fst, my_edges[i].snd);
if (i < len - 1) {
@ -302,11 +302,8 @@ int main(int argc, char **argv) {
// Have there been any changes in the labels?
int num_changes = new_labels.size();
int total_changes;
MPI::COMM_WORLD.Allreduce(&num_changes, &total_changes, 1, MPI_INT,
MPI::SUM);
// std::cout << fmt::format("[{}] # updates: {} ({})", rank, num_changes,
// total_changes)
// << std::endl;
MPI_Allreduce(&num_changes, &total_changes, 1, MPI_INT, MPI_SUM,
MPI_COMM_WORLD);
if (total_changes == 0) {
break;
@ -346,8 +343,8 @@ int main(int argc, char **argv) {
label_count[all_assignments[this_node_range.fst + j]]++;
}
} else {
MPI::COMM_WORLD.Recv(&all_assignments[this_node_range.fst], count,
MPI_INT, i, TAG_SEND_FINAL_RESULT);
MPI_Recv(&all_assignments[this_node_range.fst], count, MPI_INT, i,
TAG_SEND_FINAL_RESULT, MPI_COMM_WORLD, NULL);
for (int j = 0; j < count; ++j) {
label_count[all_assignments[this_node_range.fst + j]]++;
}
@ -360,8 +357,8 @@ int main(int argc, char **argv) {
for (int i = my_node_range.fst; i < my_node_range.snd; ++i) {
flat_assignments.push_back(node_label_assignment[i]);
}
MPI::COMM_WORLD.Send(flat_assignments.data(), flat_assignments.size(),
MPI_INT, 0, TAG_SEND_FINAL_RESULT);
MPI_Send(flat_assignments.data(), flat_assignments.size(), MPI_INT, 0,
TAG_SEND_FINAL_RESULT, MPI_COMM_WORLD);
}
#pragma endregion