26 void mango::MPI_Partition::print() {
31 const int buffer_length = 1000;
32 char proc_assignments_string[buffer_length];
34 sprintf(proc_assignments_string,
"Proc%5d of%5d in comm_world is in worker group%5d, has rank%5d of%5d in comm_worker_groups, and has rank%5d of%5d in comm_group_leaders.\n",rank_world, N_procs_world, worker_group, rank_worker_groups, N_procs_worker_groups, rank_group_leaders, N_procs_group_leaders);
36 MPI_Barrier(comm_world);
38 std::cout << proc_assignments_string;
39 for (tag = 1; tag < N_procs_world; tag++) {
40 MPI_Recv(proc_assignments_string, buffer_length, MPI_CHAR, tag, tag, comm_world, &status);
41 std::cout << proc_assignments_string;
45 MPI_Send(proc_assignments_string, buffer_length, MPI_CHAR, 0, tag, comm_world);
52 const int N_data_items = 8;
53 std::string columns[N_data_items] = {
"rank_world",
"N_procs_world",
"worker_group",
"N_worker_groups",
"rank_worker_groups",
"N_procs_worker_groups",
"rank_group_leaders",
"N_procs_group_leaders"};
54 int data[N_data_items] = { rank_world , N_procs_world , worker_group , N_worker_groups , rank_worker_groups , N_procs_worker_groups , rank_group_leaders , N_procs_group_leaders };
56 std::ofstream output_file;
61 output_file.open(filename.c_str());
62 if (!output_file.is_open()) {
63 std::cerr <<
"MPI_Partition output file: " << filename << std::endl;
64 throw std::runtime_error(
"Error! Unable to open MPI_Partition output file.");
68 output_file << columns[0];
69 for (j=1; j<N_data_items; j++) output_file <<
", " << columns[j];
70 output_file << std::endl;
75 MPI_Barrier(comm_world);
78 write_line(output_file, N_data_items, columns, data);
79 for (tag = 1; tag < N_procs_world; tag++) {
80 MPI_Recv(data, N_data_items, MPI_INT, tag, tag, comm_world, &status);
81 write_line(output_file, N_data_items, columns, data);
85 MPI_Send(data, N_data_items, MPI_INT, 0, tag, comm_world);
89 if (proc0_world) output_file.close();
93 void mango::MPI_Partition::write_line(std::ofstream& output_file,
int N_data_items, std::string columns[],
int data[]) {
95 output_file << std::setw(columns[0].length()) << data[0];
96 for (
int j=1; j<N_data_items; j++) output_file <<
", " << std::setw(columns[j].length()) << data[j];
97 output_file << std::endl;