External memory graph traversal

External memory graph traversal is a type of graph traversal optimized for accessing externally stored memory.

Background

Graph traversal is a subroutine in most graph algorithms. The goal of a graph traversal algorithm is to visit (and / or process) every node of a graph. Graph traversal algorithms, like breadth-first search and depth-first search, are analyzed using the von Neumann model, which assumes uniform memory access cost. This view neglects the fact, that for huge instances part of the graph resides on disk rather than internal memory. Since accessing the disk is magnitudes slower than accessing internal memory, the need for efficient traversal of external memory exists.

External memory model

For external memory algorithms the external memory model by Aggarwal and Vitter{{cite journal|last1=Aggarwal|first1=Alok|last2=Vitter|first2=Jeffrey|author2-link=Jeffrey Vitter|title=The input/output complexity of sorting and related problems|journal=Communications of the ACM|volume=31|issue=9|pages=1116–1127|date=1988|doi=10.1145/48529.48535|url=https://hal.inria.fr/inria-00075827|doi-access=free}} is used for analysis. A machine is specified by three parameters: M, B and D.

M is the size of the internal memory, B is the block size of a disk and D is the number of parallel disks.

The measure of performance for an external memory algorithm is the number of I/Os it performs.

= Munagala and Ranade =

File:Mr alg.gif algorithm.]]

For an undirected graph G, Munagala and Ranade{{Cite conference |title=I/O-complexity of Graph Algorithms |last1=Munagala |first1=Kameshwar |last2=Ranade |first2=Abhiram | date=1999| publisher=Society for Industrial and Applied Mathematics |book-title=Proceedings of the Tenth Annual ACM-SIAM Symposium on Discrete Algorithms |pages=687–694 |conference=SODA '99 | location=Baltimore, Maryland, USA }} proposed the following external memory algorithm:

Let L(t) denote the nodes in breadth-first search level t and let A(t):=N(L(t-1)) be the multi-set of neighbors of level t-1. For every t, L(t) can be constructed from A(t) by transforming it into a set and excluding previously visited nodes from it.

  1. Create A(t) by accessing the adjacency list of every vertex in L(t-1). This step requires O(|L(t-1)|+|A(t)|/(D\cdot B)) I/Os.
  2. Next A'(t) is created from A(t) by removing duplicates. This can be achieved via sorting of A(t), followed by a scan and compaction phase needing O(\operatorname{sort}(|A|)) I/Os.
  3. L(t):=A'(t)\backslash\{L(t-1)\cup L(t-2)\} is calculated by a parallel scan over L(t-1) and L(t-2) and requires O((|A(t)|+|L(t-1)|+|L(t-2)|)/(D\cdot B)) I/Os.

The overall number of I/Os of this algorithm follows with consideration that \sum_t |A(t)|=O(m) and \sum_t |L(t)|=O(n) and is O(n+\operatorname{sort}(n+m)).

A visualization of the three described steps necessary to compute L(t) is depicted in the figure on the right.

= Mehlhorn and Meyer =

Mehlhorn and Meyer{{Cite conference |title=External-Memory Breadth-First Search with Sublinear I/O |last1=Mehlhorn |first1=Kurt |last2=Meyer |first2=Ulrich | date=2002| publisher=Springer Berlin Heidelberg |book-title=Algorithms -- ESA 2002 |pages=723–735 |conference=ESA 2002 | location=Rome, Italy }} proposed an algorithm that is based on the algorithm of Munagala and Ranade (MR) and improves their result.

It consists of two phases. In the first phase the graph is preprocessed, the second phase performs a breadth-first search using the information gathered in phase one.

During the preprocessing phase the graph is partitioned into disjointed subgraphs S_i,\,0\leq i\leq K with small diameter. It further partitions the adjacency lists accordingly, by constructing an external file F=F_0F_1\dots F_{K-1}, where F_i contains the adjacency list for all nodes in S_i.

The breadth-first search phase is similar to the MR algorithm. In addition the algorithm maintains a sorted external file {{mvar|H}}. This file is initialized with F_0. Further, the nodes of any created breadth-first search level carry identifiers for the files F_i of their respective subgraphs S_i. Instead of using random accesses to construct L(t) the file {{mvar|H}} is used.

  1. Perform a parallel scan of sorted list L(t-1) and {{mvar|H}}. Extract the adjacency lists for nodes v\in L(t-1), that can be found in {{mvar|H}}.
  2. The adjacency lists for the remaining nodes that could not be found in {{mvar|H}} need to be fetched. A scan over L(t-1) yields the partition identifiers. After sorting and deletion of duplicates, the respective files F_i can be concatenated into a temporary file {{mvar|F'}}.
  3. The missing adjacency lists can be extracted from {{mvar|F'}} with a scan. Next, the remaining adjacency lists are merged into {{mvar|H}} with a single pass.
  4. A(t) is created by a simple scan. The partition information is attached to each node in A(t).
  5. The algorithm proceeds like the MR algorithm.

Edges might be scanned more often in {{mvar|H}}, but unstructured I/Os in order to fetch adjacency lists are reduced.

The overall number of I/Os for this algorithm is O\left(\sqrt\frac{n\cdot(n+m)}{D\cdot B}+\operatorname{sort}(n+m)\right)

References