MCPcopy Create free account
hub / github.com/NanoComp/meep / optimize_comms_operations

Function optimize_comms_operations

src/boundaries.cpp:37–75  ·  view source on GitHub ↗

Creates an optimized comms_sequence from a vector of comms_operations. Send operations are prioritized in descending order by the amount of data that is transferred.

Source from the content-addressed store, hash-verified

35// Creates an optimized comms_sequence from a vector of comms_operations.
36// Send operations are prioritized in descending order by the amount of data that is transferred.
37comms_sequence optimize_comms_operations(const std::vector<comms_operation> &operations) {
38 comms_sequence ret;
39 std::map<int, size_t> send_size_by_my_chunk_idx;
40 std::map<int, std::vector<comms_operation> > send_ops_by_my_chunk_idx;
41
42 for (const auto &op : operations) {
43 if (op.comm_direction == Incoming) {
44 ret.receive_ops.push_back(op);
45 continue;
46 }
47
48 // Group send operations by source chunk and accumulate the transfer size - excluding chunk
49 // pairs that reside on the same processor.
50 if (op.other_proc_id != my_rank()) {
51 send_size_by_my_chunk_idx[op.my_chunk_idx] += op.transfer_size;
52 }
53 else {
54 // Make sure that op.my_chunk_idx is represented in the map.
55 send_size_by_my_chunk_idx[op.my_chunk_idx] += 0;
56 }
57 send_ops_by_my_chunk_idx[op.my_chunk_idx].push_back(op);
58 }
59
60 // Sort in descending order to prioritize large transfers.
61 std::vector<std::pair<int, size_t> > send_op_sizes(send_size_by_my_chunk_idx.begin(),
62 send_size_by_my_chunk_idx.end());
63 std::sort(send_op_sizes.begin(), send_op_sizes.end(),
64 [](const std::pair<int, size_t> &a, const std::pair<int, size_t> &b) -> bool {
65 return a.second > b.second;
66 });
67
68 // Assemble send operations.
69 for (const auto &size_pair : send_op_sizes) {
70 int my_chunk_idx = size_pair.first;
71 const auto &ops_vector = send_ops_by_my_chunk_idx[my_chunk_idx];
72 ret.send_ops.insert(std::end(ret.send_ops), std::begin(ops_vector), std::end(ops_vector));
73 }
74 return ret;
75}
76
77} // namespace
78

Callers 1

FOR_FIELD_TYPESFunction · 0.85

Calls 1

my_rankFunction · 0.85

Tested by

no test coverage detected