a3 fix
This commit is contained in:
parent
9ce233b671
commit
dfa2024001
2 changed files with 30 additions and 5 deletions
3
assignments/03/.gitignore
vendored
3
assignments/03/.gitignore
vendored
|
@ -6,4 +6,5 @@ report.pdf
|
||||||
out.txt
|
out.txt
|
||||||
|
|
||||||
dataset/gen_*.txt
|
dataset/gen_*.txt
|
||||||
.direnv
|
.direnv
|
||||||
|
labels.txt
|
|
@ -36,6 +36,15 @@ void pair_vector_init(struct pair_vector *);
|
||||||
void pair_vector_clear(struct pair_vector *);
|
void pair_vector_clear(struct pair_vector *);
|
||||||
void pair_vector_push(struct pair_vector *v, int fst, int snd);
|
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) {
|
int main(int argc, char **argv) {
|
||||||
MPI::Init(argc, argv);
|
MPI::Init(argc, argv);
|
||||||
int rank = MPI::COMM_WORLD.Get_rank(), p = MPI::COMM_WORLD.Get_size();
|
int rank = MPI::COMM_WORLD.Get_rank(), p = MPI::COMM_WORLD.Get_size();
|
||||||
|
@ -336,13 +345,10 @@ int main(int argc, char **argv) {
|
||||||
} else {
|
} else {
|
||||||
MPI::COMM_WORLD.Recv(&all_assignments[this_node_range.first], count,
|
MPI::COMM_WORLD.Recv(&all_assignments[this_node_range.first], count,
|
||||||
MPI::INT, i, TAG_SEND_FINAL_RESULT);
|
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 {
|
} else {
|
||||||
std::vector<int> flat_assignments;
|
std::vector<int> flat_assignments;
|
||||||
for (int i = my_node_range.first; i < my_node_range.second; ++i) {
|
for (int i = my_node_range.first; i < my_node_range.second; ++i) {
|
||||||
|
@ -393,4 +399,22 @@ void pair_vector_push(struct pair_vector *v, int fst, int snd) {
|
||||||
v->ptr[v->len].fst = fst;
|
v->ptr[v->len].fst = fst;
|
||||||
v->ptr[v->len].snd = snd;
|
v->ptr[v->len].snd = snd;
|
||||||
v->len++;
|
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);
|
||||||
}
|
}
|
Loading…
Reference in a new issue