Skip to content

96 improvements in cost calculation#97

Merged
francosansone merged 13 commits into
sb-graph-devfrom
96-improvements-in-cost-calculation
Sep 9, 2025
Merged

96 improvements in cost calculation#97
francosansone merged 13 commits into
sb-graph-devfrom
96-improvements-in-cost-calculation

Conversation

@francosansone

@francosansone francosansone commented Aug 26, 2025

Copy link
Copy Markdown
Collaborator

Some improvements in:

  • The way that cost communication is computed.
  • The software design.

New way to compute external communication by partition. This replaces $\mathbf{compute\_EC\_IC}$ for a more efficient alternative.

  • $\mathbf{for}(i \in 1:N):$
    • $P_i = PARTITIONS[i]$
    • $partition\_communication = \emptyset$
    • $internal\_communication\_partition = \emptyset$
    • $\mathbf{for} set\_piece \in P_i:$
      • $edges = communication\_by\_set\_piece[set\_piece]$
      • $conn\_edges = edges \cap partition\_communication$
      • $internal\_communication\_partition = conn\_edges \cup internal\_communication\_partition$ // if $nodes$ is connected to other nodes within the partition, it will be a non-empty intersection.
      • $partition\_communication = partition\_communication \cup edges$
    • $ec\_partition\_i = partition\_communication \setminus internal\_communication\_partition$
    • $communication\_by\_partition.insert(partition\_communication)$
    • $ec\_by\_partition.insert(ec\_partition\_i)$

$communication\_by\_set\_piece$ is a hashtable, with set pieces as keys and edges as values, where each key is associated to the edges that connect it with other nodes. It is pre-computed at the beginning.

Then, to compute External and Internal cost, we only need to compute the difference between the entire communication and the external one.

Regarding software design:

ICommunicationCost was defined, it is the interface to compute communication between nodes and/or set pieces. Then, two classes are implemented, CommunicationCost does the actual operations, CommunicationCostSync it is a wrapper that prevents from data races.

Furthermore, two flags were added:

-t, --enable-multithreading          Enable multithreading during optimization.
-i, --initial-partition-strategy   Choose a particular initial partition strategy. If this flag is disbaled,
all strategies will be computed and the best partition will be chosen.
        Value   Searching algorithm     Strategy        Order
        0       Depth first search      Distributive    preorder
        1       Depth first search      Distributive    postorder
        2       Depth first search      Greedy          preorder
        3       Depth first search      Greedy          postorder

Regarding performance:

For the air conditioners with a controller, 4 sections, size of 1000 and 4 partitions:

Branch Time to partitionate
sb-graph-dev 187,0774 ms
96-improvements-in-cost-calculation 119,8262 ms

For the spiking neurons with size of 1000, 10 connections, 100 inputs and 4 partitions:

Branch Time to partitionate
sb-graph-dev 1197,746 ms
96-improvements-in-cost-calculation 809,6248 ms

Examples were executed in a single thread.

@francosansone francosansone self-assigned this Aug 26, 2025
@francosansone francosansone linked an issue Aug 26, 2025 that may be closed by this pull request

@joaquinffernandez joaquinffernandez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👏 👏

GainObjectImbalance max_gain = GainObjectImbalance{
numeric_limits<size_t>::infinity(),
numeric_limits<size_t>::infinity(),
-numeric_limits<size_t>::infinity(),

@francosansone francosansone Sep 3, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just made a very simple change since max_gain here and in update_diff was not properly initialized, they both were initialized with gain = 0. FYI @joaquinffernandez .

SBG::LIB::UnordAF set_fact;
SBG::LIB::MapAF map_fact(set_fact);
SBG::LIB::UnordPWMapAF pw_fact(map_fact);
SBG::LIB::UnordAF set_fact;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnordAF creates unordered sets, that for uni-dimensional dense intervals is inefficient.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this, should we use OrdDenseAF when dealing with uni-dimensional intervals?


virtual ~CommunicationCost() = default;

virtual void update_partitions(PartitionMap& partitions, std::optional<std::reference_wrapper<const std::list<size_t>>> modified_partitions = std::nullopt);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that functions should actually override the virtual ones in ICommunicationCost, so they shouldn't be declared as virtual.

@francosansone francosansone merged commit 3acb706 into sb-graph-dev Sep 9, 2025
2 checks passed
@francosansone francosansone deleted the 96-improvements-in-cost-calculation branch September 9, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvements in cost calculation

3 participants