This commit is contained in:
Michael Zhang 2023-12-28 23:53:30 -05:00
parent 9ce233b671
commit dfa2024001
2 changed files with 30 additions and 5 deletions

View file

@ -7,3 +7,4 @@ out.txt
dataset/gen_*.txt
.direnv
labels.txt

View file

@ -36,6 +36,15 @@ void pair_vector_init(struct pair_vector *);
void pair_vector_clear(struct pair_vector *);
void pair_vector_push(struct pair_vector *v, int fst, int snd);
/**
* @brief Write a vector of labels to a file.
*
* @param filename The name of the file to write to.
* @param labels The array of labels.
* @param nlabels How many labels to write.
*/
static void print_labels(char *filename, int *labels, size_t const nlabels);
int main(int argc, char **argv) {
MPI::Init(argc, argv);
int rank = MPI::COMM_WORLD.Get_rank(), p = MPI::COMM_WORLD.Get_size();
@ -336,13 +345,10 @@ int main(int argc, char **argv) {
} else {
MPI::COMM_WORLD.Recv(&all_assignments[this_node_range.first], count,
MPI::INT, i, TAG_SEND_FINAL_RESULT);
// for (int j = 0; j < count; ++j) {
// label_count[all_assignments[this_node_range.first + j]]++;
// }
}
}
// std::cout << "Done! " << label_count.size() << std::endl;
print_labels(argv[2], all_assignments.data(), all_assignments.size());
} else {
std::vector<int> flat_assignments;
for (int i = my_node_range.first; i < my_node_range.second; ++i) {
@ -394,3 +400,21 @@ void pair_vector_push(struct pair_vector *v, int fst, int snd) {
v->ptr[v->len].snd = snd;
v->len++;
}
static void print_labels(char *filename, int *labels, size_t const nlabels) {
size_t i;
FILE *fout;
/* open file */
if ((fout = fopen(filename, "w")) == NULL) {
fprintf(stderr, "error opening '%s'\n", filename);
abort();
}
/* write labels to fout */
for (i = 0; i < nlabels; ++i) {
fprintf(fout, "%u\n", labels[i]);
}
fclose(fout);
}