<commit_before># Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, 2013 ETH Zurich.

import pdb
import logging
import topology_parser
import config
import helpers
import re

from pygraph.algorithms.minmax import shortest_path
from pygraph.classes.graph import graph
from pygraph.classes.digraph import digraph

# --------------------------------------------------
class Model(object):

    evaluation = None
    send_cost = {}
    recv_cost = {}

    def __init__(self, graph):
        """
        We initialize models with the graph
        """
        assert (len(graph.nodes())>0)
        self.graph = graph
        try:
            print 'Looking for measurements/coresenum_print_%s' % \
                self.get_name()
            self.machine_topology = topology_parser.parse_machine_db(self.get_name())
        except:
            print 'Warning, did not find coresenum data for machine'
            self.machine_topology = None
            pass


    # --------------------------------------------------
    # Characteritics of model
    def get_name(self):
        return None

    def get_num_numa_nodes(self):
        return None

    def get_num_cores(self):
        return None

    def get_cores_per_node(self):
        print helpers.bcolors.WARNING + "Warning: Deprecated?" + helpers.bcolors.ENDC
        assert self.get_num_numa_nodes() is not None # Should be overriden in childs
        if self.get_num_numa_nodes()>0:
            return self.get_num_cores() / self.get_num_numa_nodes()
        else:
            return self.get_num_cores()

    # Transport cost
    def get_cost_within_numa(self):
        print helpers.bcolors.WARNING + "Warning: Deprecated?" + helpers.bcolors.ENDC
        return 1

    def get_cost_across_numa(self):
        print helpers.bcolors.WARNING + "Warning: Deprecated?" + helpers.bcolors.ENDC
        return 10

    # Node processing cost
    def get_receive_cost(self, src, dest):
        """
        The cost of receive operations on dest for messages from
        src. This is essentially the time required for the memory read
        in case of a new message, which in turn is the time required
        by the cache-coherency protocol to update the (at this point
        invalid) cache-line in the local cache with the updates
        version in the senders cache.
        """
        return self._get_receive_cost(src, dest)

    def get_send_cost(self, src, dest):
        """
        The cost of the send operation (e.g. to work to done on the
        sending node) when sending a message to core dest
        """
        return self._get_send_cost(src, dest)

    def get_numa_information(self):
        """
        Return information on NUMA nodes. This is a a list of
        list. Every element of the outer list represents a NUMA node
        and the inner list the cores in that NUMA node.
        """
        return None

    # --------------------------------------------------
    # Helpers
    def get_cores(self, only_active=False):
        """Return a list of cores

        @param only_active If set to true, only return nodes that
        participate in multicast.

        """
        n = [ c for c in range(self.get_num_cores()) ]
        n = self.filter_active_cores(n, only_active)
        return n


    def filter_active_cores(self, n, only_active):
        
        if only_active:
            n = [ n_ for n_ in n if n_ in map(int, config.get_mc_group()) ]

        return n


    def output_graph(self):
        """ Write the graph out to disk as <machine_name>_graph
        """
        helpers.output_graph(self.graph, '%s_graph' % self.get_name())
<commit_msg>Fixed creation of broadcast tree (in absence of multicast group)<commit_after># Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, 2013 ETH Zurich.

import pdb
import logging
import topology_parser
import config
import helpers
import re

from pygraph.algorithms.minmax import shortest_path
from pygraph.classes.graph import graph
from pygraph.classes.digraph import digraph

# --------------------------------------------------
class Model(object):

    evaluation = None
    send_cost = {}
    recv_cost = {}

    def __init__(self, graph):
        """
        We initialize models with the graph
        """
        assert (len(graph.nodes())>0)
        self.graph = graph
        try:
            print 'Looking for measurements/coresenum_print_%s' % \
                self.get_name()
            self.machine_topology = topology_parser.parse_machine_db(self.get_name())
        except:
            print 'Warning, did not find coresenum data for machine'
            self.machine_topology = None
            pass


    # --------------------------------------------------
    # Characteritics of model
    def get_name(self):
        return None

    def get_num_numa_nodes(self):
        return None

    def get_num_cores(self):
        return None

    def get_cores_per_node(self):
        print helpers.bcolors.WARNING + "Warning: Deprecated?" + helpers.bcolors.ENDC
        assert self.get_num_numa_nodes() is not None # Should be overriden in childs
        if self.get_num_numa_nodes()>0:
            return self.get_num_cores() / self.get_num_numa_nodes()
        else:
            return self.get_num_cores()

    # Transport cost
    def get_cost_within_numa(self):
        print helpers.bcolors.WARNING + "Warning: Deprecated?" + helpers.bcolors.ENDC
        return 1

    def get_cost_across_numa(self):
        print helpers.bcolors.WARNING + "Warning: Deprecated?" + helpers.bcolors.ENDC
        return 10

    # Node processing cost
    def get_receive_cost(self, src, dest):
        """
        The cost of receive operations on dest for messages from
        src. This is essentially the time required for the memory read
        in case of a new message, which in turn is the time required
        by the cache-coherency protocol to update the (at this point
        invalid) cache-line in the local cache with the updates
        version in the senders cache.
        """
        return self._get_receive_cost(src, dest)

    def get_send_cost(self, src, dest):
        """
        The cost of the send operation (e.g. to work to done on the
        sending node) when sending a message to core dest
        """
        return self._get_send_cost(src, dest)

    def get_numa_information(self):
        """
        Return information on NUMA nodes. This is a a list of
        list. Every element of the outer list represents a NUMA node
        and the inner list the cores in that NUMA node.
        """
        return None

    # --------------------------------------------------
    # Helpers
    def get_cores(self, only_active=False):
        """Return a list of cores

        @param only_active If set to true, only return nodes that
        participate in multicast.

        """
        n = [ c for c in range(self.get_num_cores()) ]
        n = self.filter_active_cores(n, only_active)
        return n


    def filter_active_cores(self, n, only_active):
        
        if config.args.multicast and only_active:
            n = [ n_ for n_ in n if n_ in map(int, config.get_mc_group()) ]

        return n


    def output_graph(self):
        """ Write the graph out to disk as <machine_name>_graph
        """
        helpers.output_graph(self.graph, '%s_graph' % self.get_name())

{'fraction_non_alphanumeric': 0.11350984385607603, 'fraction_numerical': 0.008961303462321792, 'mean_word_length': 2.013911620294599, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '269929', 'n_tokens_mistral': 2162, 'n_tokens_neox': 2017, 'n_words': 679}