Skip to content

Reader function 'nodes_of_elems' bottlenecks code on large datasets. #1

@aczerepak

Description

@aczerepak

When profiling code that utilized the reader functions, it was noticed that the 'nodes_of_elems' function took a disproportionate amount of time on a large mili database. I don't claim to be an ace Python developer but I made some modifications to a few lines that took the runtime down by two orders of magnitude. The function in question is shown below, with the original lines commented out and my changes noted.

def nodes_of_elems( self, class_sname, elem_labels ):
    ''' Find nodes associated with elements by label '''
    if type(elem_labels) is not list:
      if iterable(elem_labels):
        elem_labels = list(elem_labels)
      else:
        elem_labels = [ elem_labels ]
    if class_sname not in self.__class_to_sclass:
      return np.empty([1,0],dtype=np.int32)
    if class_sname not in self.__conns:
      return np.empty([1,0],dtype=np.int32)
# Original code
    #if any( label not in self.__labels[class_sname] for label in elem_labels ):
    #  return np.empty([1,0],dtype=np.int32)
# Changes
    if not all(np.isin(elem_labels, self.__labels[class_sname] )):
      return np.empty([1,0],dtype=np.int32)

    # get the indices of the labels we're querying in the list of local labels of the element class, so we can retrieve their connectivity

# Original code
    #indices = (self.__labels[class_sname][:,None] == elem_labels).argmax(axis=0)
    #elem_conn = self.__conns[class_sname][indices][:,:-1]
# Changes
    indices=np.searchsorted(elem_labels,self.__labels[class_sname][:,None])
    elem_conn = self.__conns[class_sname][indices][:,-1][:,0:-1]
    return self.__labels['node'][elem_conn], self.__labels[class_sname][indices,None]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions