<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Parallel evaluation of interaction nets: some observations and examples</article-title>
      </title-group>
      <abstract>
        <p>Interaction nets are a particular kind of graph rewriting system that have many properties that make them useful for capturing sharing and parallelism. There have been a number of research e orts towards implementing interaction nets in parallel, and these have focused on the implementation technologies. In this paper we investigate a related question: when is an interaction net system suitable for parallel evaluation? We observe that some nets are cannot bene t from parallelism (they are sequential) and some have the potential to be evaluated in a highly parallel way. This rst investigation aims to highlight a number of issues, by presenting experimental evidence for a number of case studies. We hope this can be used to help pave the way to a wider use of this technology for parallel evaluation.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>Interaction nets are a model of computation based on a restricted form of graph
rewriting: the rewrite rules must be between two nodes on the left-hand side, be
local (not change any part of graph other than the two nodes), and there must
be at most one rule for each pair of nodes. These constraints have no impact on
the expressive power of interaction nets (they are Turing complete), but they
o er a very useful feature: they are con uent by construction. Taken with the
locality constraint they lend themselves to parallel evaluation: all rewrite rules
that can apply can be rewritten in one parallel step.</p>
      <p>The question that we propose in this paper is: when is a particular interaction
net system well suited for parallel evaluation. More precisely, are some interaction
nets \more parallel" than others? A question that naturally follows from this is
can we transform a net so that it is more suited for parallel evaluation. Once
we have understood this, we can also ask the reverse question: can a net be
made sequential? The purpose of this paper is to make a start to investigate
these questions, and we begin with an empirical study of interaction systems to
identify when they are suitable for parallel evaluation or not.</p>
      <p>We take a number of typical examples (some common ones from the
literature together with some new ones we made up for this paper) to see if they
bene t from parallel evaluation. In addition, we make some observations about
how programs can be transformed so that parallelism is more useful. Using these
examples, we give some heuristics for getting more parallelism out of an
interaction net system.</p>
      <p>
        Related work. There have been a number of studies for the parallel
implementation of interaction nets: Pinto [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] and Jiresch [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] are two examples. In these
works it is the implementation of a given net that has been the focus. Here we
are interested in knowing if a net is well suited for parallel evaluation or not.
Structure. In the next section we recall the de nition of interaction nets, and
describe the notion of parallel evaluation that we are interested in. Through
examples we motivate the ideas behind this work. In Section 3 we give a few
small case studies to show how parallelism can have a signi cant impact on the
evaluation of a net. In Section 4 we give a short discussion and conclude in
Section 5.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Background and Motivation</title>
      <p>
        In the graphical rewriting system of interaction nets [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], we have a set of
symbols, which are names of the nodes in our diagrams. Each symbol has an arity
ar that determines the number of auxiliary ports that the node has. If ar( ) = n
for 2 , then has n + 1 ports: n auxiliary ports and a distinguished one
called the principal port.
      </p>
      <p>x1
xn
Nodes are drawn variably as circles, triangles or squares. A net built on is
an undirected graph with nodes at the vertices. The edges of the net connect
nodes together at the ports such that there is only one edge at every port. A
port which is not connected is called a free port.</p>
      <p>Two nodes ( ; ) 2 connected via their principal ports form an active
pair, which is the interaction nets analogue of a redex. A rule (( ; ) =) N )
replaces the pair ( ; ) by the net N . All the free ports are preserved during
reduction, and there is at most one rule for each pair of agents. The following
diagram illustrates the idea, where N is any net built from .</p>
      <p>xn
x1</p>
      <p>The most powerful property of this system is that it is one-step con uent:
the order of rewriting is not important, and all sequences of rewrites are of the
same length (in fact they are permutations). This has practical consequences: the
diagrammatic transformations can be applied in any order, or even in parallel,
to give the correct answer. It is the latter feature that we develop in this paper.</p>
      <p>We de ne some notions of nets and evaluation. A net is called sequential if
there is at most one active pair that can be reduced at each step. We say that a
net is evaluated sequentially if one active pair is reduced at each step. For our
notion of parallel evaluation, we require that all active pairs in a net are reduced
simultaneously, and then any redexes that were created are evaluated at the
next step. We do not bound the number of active pairs that can be reduced in
parallel. We remark that the number of parallel steps will always be less than
or equal to the number of sequential steps (for a sequential net, the number of
steps is the same for sequential and parallel evaluation).</p>
      <p>As an example, consider unary numbers with addition. We represent the
following term rewriting system
add(Z,y) = y
add(S(x),y) = add(x,S(y))
as a system of nets with agents Z, S, +:</p>
      <p>Z</p>
      <p>S
+
together with two rewrite rules:
We observe that addition of two numbers is sequential: at any time there is just
one active pair, and reducing this active pair creates one more active pair, and
so on. In terms of cost, reducing add(n,m) requires n + 1 interactions. If we
consider the net corresponding to the term add(add(m; n); p), then the system is
sequential, and the costs are now 2m + n + 2. Using associativity of addition, the
situation changes signi cantly. The net corresponding to add(m; add(n; p)) has
sequential cost m+1+n+1 = m+n+2, and parallel cost max(m+1; n+1). This
is signi cantly more e cient sequentially, and moreover is able to bene t from
parallel evaluation. The example becomes even more interesting if we change the
system to an alternative version of addition:
add(Z,y) = y
add(S(x),y) = S(add(x,y))
The two interaction rules are now:
+</p>
      <p>+
=)</p>
      <p>S
+
=)</p>
      <p>S
+
Z</p>
      <p>Unlike the previous system, the term add(add(m; n); p) already has scope
for parallelism. The sequential cost is now 2m + n + 2 and the parallel cost is
m + n + 2. But again, if we use associativity then we can do even better and
achieve sequential cost m + n + 2 and parallel cost max(m + 1; n + 1) for the
term add(m; add(n; p)).</p>
      <p>These examples illustrate that some nets are sequential; some nets can use
properties of the system (in this case associativity of addition) to get better
sequential and parallel behaviours; and some systems can have modi ed rules
that are more e cient, and also more appropriate to exploit parallelism. The
next section gives examples where there is scope for parallelism in nets.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Case studies</title>
      <p>The previous arithmetic example demonstrates that some systems are more
useful than others for parallel evaluation. In this section we give some empirical
case studies for a number of di erent systems to show that when a suitable
system can be found, the parallel evaluation gives signi cantly better results than
sequential evaluation.</p>
      <p>Fibonacci. The Fibonacci function is a good example where many recursive calls
generate a lot of possibilities for parallel evaluation. We build the interaction net
system that corresponds to the term rewriting system:
fib 0 = fib 1 = 1
fib n = fib(n-1) + fib(n-2)</p>
      <p>Using a direct encoding of this system together with addition de ned
previously, we can obtain an interaction system:</p>
      <p>Fib
Fib2</p>
      <p>Z
Z
⇒
⇒</p>
      <p>S
Z
S
Z</p>
      <p>Fib
Fib2</p>
      <p>S
S
⇒
⇒</p>
      <p>Fib2
Fib</p>
      <p>Fib</p>
      <p>Dup
S
S
S
Z
S</p>
      <p>S
→</p>
      <p>Fib
The following is an example of rewriting:</p>
      <p>Fib
fib 3</p>
      <p>S
S
S
Z
→</p>
      <p>Fib2
+</p>
      <p>Fib</p>
      <p>S</p>
      <p>→
Dup</p>
      <p>Fib
S
Z</p>
      <p>S
Z
+</p>
      <p>Fib
fib 1 + fib 2</p>
      <p>S
S
Z
With respect to the two versions of the addition operation introduced in
Section 2, we call the former a batch operation, which returns the computational
result after nishing processing all of the given data, and the latter a streaming
operation, which computes one (or a small number of) elements of the given data
and returns partial parts of the computational result immediately. The graphs in
Figure 1 show the number of interactions in each version, where we plot
sequential steps against parallel steps to indicate the rate of growth of each one. Both
graphs demonstrate that the sequential computation is exponential, while the
parallel one is quadratic. We remark that, in the parallel execution, the numbers
of steps with the streaming operation are less than a half of the numbers with
the batch operation. This result is illustrated in the third graph in the gure.</p>
      <p>By allowing attributes as labels of agents, we can include integer numbers in
agents. In addition, we can use conditional rewritings, preserving the one-step
con uence, when these conditions on attributes are disjoint. In this case, the
system of the Fibonacci function is written as follows:</p>
      <p>Fib
Fib
Fib
n
n
n
n=0
⇒
n=1
⇒
1
1
not(n=0) and
not(n=1)
⇒</p>
      <p>Add</p>
      <p>Fib
Fib
n-1
n-2</p>
      <p>Add</p>
      <sec id="sec-3-1">
        <title>Addn</title>
        <p>(n)
n
m
⇒
⇒</p>
      </sec>
      <sec id="sec-3-2">
        <title>Addn</title>
        <p>(n)
n+m
There is very little di erence between the load balances of fib (n 1) and
fib (n 2), and thus this system gives the following graph, demonstrating that
the growth rate for parallel computation is linear, while the sequential rate is
exponential:
1200
1000
800
Ackermann. The Ackermann function is de ned by three cases: ack 0 n = n+1,
ack m 0 = ack (m-1) 1, and ack m n = ack (m-1) (ack m (n-1)). We can
build the interaction net system on the unary natural numbers that corresponds
to the term rewriting system as follows:</p>
        <p>A
y
r</p>
        <p>Z
⇒</p>
        <p>S
y</p>
        <p>r
fib n (batch additive operation)
fib n (streaming additive operation)
0
2
4
6
8
10
12
14
0
2
4
6
8
10
12
14
0
2
4
6
8
10
12</p>
        <p>14
n
Z</p>
        <p>A
A
A
A</p>
        <p>S
Z
2
1
x
r
⇒
r</p>
        <p>Pred
x
x
r
⇒</p>
        <p>Dup
where the agent Dup duplicates S and Z agents. The following is an example of
rewriting:
Dup</p>
        <p>A</p>
        <p>A</p>
        <p>Z
→</p>
        <p>S
Z</p>
        <p>A2
y
→
Pred</p>
        <p>A
n
n
not(n=0)
⇒</p>
        <p>S
Z</p>
        <p>A
A
x</p>
        <p>S
Z</p>
        <p>A
m-1</p>
        <p>1
m-1
A</p>
        <p>Pred</p>
        <p>A</p>
        <p>r
m
n-1
1
0
When we use numbers as attributes, the system can be written as:
(a) unary natural numbers
(b) integers
On the other hand, in the case of the computation on unary natural numbers,
the A2 interacts with the streaming result of ack 0 (ack 1 0):
ack 3 n</p>
        <p>seqpuaernatlilaell
n
S
Z
A
A
A</p>
        <p>S
Z
m-1</p>
        <p>1
m-1
A
m-1
A
m
n-1
m
S
Z</p>
        <p>S
Z</p>
        <p>A2
A2(m)
A2(m)
A2(m)
→</p>
        <p>Z</p>
        <p>A
n
n
S
n=0
⇒
⇒
A</p>
        <p>A</p>
        <p>Z</p>
        <p>A2</p>
        <p>S
m
m=0
⇒
m not⇒(m=0)
m
S
⇒
⇒</p>
        <p>S
A2(m)
n+m</p>
        <p>Sum
(n+1)
Here, borrowing the S agent to denote numbers greater than 0, we change the
rules, especially in the case of ack 0 n, Addn into S as follows:
Thanks to the introduction of the S agent, A2 can be processed without waiting
for the result of ack 1 0. This therefore gives a streaming operation:</p>
        <p>Sum
(0)
Sum
(0)
A2(1)</p>
        <p>
          S
In addition, the benchmark graph shows that the improved system is more e
cient and more appropriate to exploit parallelism:
ack 3 n (integers, streaming)
ack 3 n (integers, in parallel)
A
n
Sorting. Bubble sort is a very simple sorting algorithm that can bene t from
parallel evaluation in interaction nets. One version of this algorithm, written in
Standard ML [
          <xref ref-type="bibr" rid="ref5">5</xref>
          ], is as follows:
fun bsortsub (x::x2::xs) =
        </p>
        <p>if x &gt; x2 then x2::(bsortsub (x::xs)) else x::(bsortsub(x2::xs))
| bsortsub x = x
fun bsort t =
let val s = bsortsub t
in if t=s then s else bsort s
end;
Using a direct encoding of this program, we obtain the interaction system:
BS
BS</p>
        <p>Nil
x
⇒
⇒</p>
        <p>Nil
EQn(x)
y
y
x = y
⇒
not⇒(x= y)
Nil
n
⇒
⇒</p>
        <p>Nil
Nil
n
n</p>
        <p>y
For instance, a list [3; 4; 2] is sorted as follows:
3
4
2</p>
        <p>Nil
→</p>
        <p>EQn(3)
where the
and
agents are de ned as a duplicator and an eraser:</p>
        <p>EQ
EQ
x
⇒
⇒
l
i</p>
        <p>N
This system shows that parallel bubble sorting is linear, whereas sequential
evaluation is quadratic, as indicated in the graph below.</p>
        <p>BS
→
→
→
→
→</p>
        <p>BS
BS</p>
        <p>BS
BS
BS
BS
2
3</p>
        <p>Nil
x
4
3
3
2
B(2)
3
However, it contains the equality test operation by EQ and EQn to check whether
the sorted list is the same as the given list. In comparison to the typical functional
programming languages, interaction nets require copying and erasing of lists for
the test that can cause ine cient computation. Moreover, the sorting process
is applied to the sorted list by B again and again. Taking into account that the
B moves the maximum number in the given unsorted list into the head of the
sorted list, we can obtain a more e cient system:
For instance, a list [3; 4; 2] is sorted as follows:
The system reduces the number of computational steps signi cantly, and gives
the best expected behaviour as follows:</p>
        <p>B(x)
Nil
y
y
⇒
x y
⇒</p>
        <p>direct
improved
10
20
30
50
60</p>
        <p>70
40
length
0
Summary/discussion. All these examples show the scope for harnessing
parallelism from an empirical study: some systems do not bene t, whereas others
allow quadratic computations be executed in linear parallel complexity.
However, these results give a avour of the potential, and do not necessarily mean
that they can be implemented like this in practice.
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Discussion</title>
      <p>In this section we examine the potential of parallelism illustrated by the graphs
in Section 3, by using a multi-threaded parallel interpreter of interaction nets,
called Inpla, implemented with gcc 4.6.3 and the Posix-thread library.</p>
      <p>We compare the execution time of Inpla with other evaluators and
interpreters. The programs were run on a Linux PC (2.4GHz, Core i7, 16GB) and
the execution time was measured using the UNIX time command as the average
of ve executions.</p>
      <p>
        First, in executions of the pure interaction nets, we take INET [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] and
amineLight [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] and compare Inpla with those by using programs { Fibonacci function
(streaming additive operation) and Ackermann function. Table 1 shows
execution time in seconds among interaction nets evaluators. We see that Inpla runs
faster than INET since Inpla is a re ned version of amineLight, which is the
fastest interaction nets evaluator [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. In the table the subscript of Inpla gives
the number of threads in the thread pool, for instance Inpla2 means that it was
executed by using two threads. Generally, since Core i7 processor has four cores,
it tends to reach the peak with four execution threads.
      </p>
      <p>
        Next, we compare Inpla with Standard ML of New Jersey (SML v110.74) [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]
and Python (2.7.3) [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] in the extended framework of interaction nets which
includes integer numbers and lists. SML is a functional programming language
and it has the eager evaluation strategy that is similar to the execution method
in interaction nets. Python is a widely-used interpreter, and thus the
comparison with Python gives a good indication on e ciency. Here we benchmark the
Fibonacci function and the streaming operation versions of Ackermann and the
improved version of Bubble Sort algorithm for randomly generated list elements.
Table 2 shows that SML computes those arithmetic functions fastest. Inpla uses
agents to represent the functions and integer numbers, and those agents are
consumed and reproduced repeatedly during computation. Thus the execution time
becomes slower eventually, compared to the execution in SML that performs
computation by function calls and managing stacked arguments. In comparison
with Python, Inpla computes those functions faster. The sort algorithm is a
special case in that interaction nets are e cient to implement these algorithms.
1 RuntimeError: maximum recursion depth exceeded
      </p>
      <p>Next we analyse the results of the parallel execution in Inpla by using graphs
in Section 3, which show the trends of steps in parallel execution on the
assumption of the unbounded resources. We may write \parallel(n)" in the following
graphs to make explicit that Inplan is used for the experiment.</p>
      <p>Fibonacci function. Figure 3 shows the execution time of each program for
Fibonacci function by using Inpla. We see that each the sequential execution is
exponential as shown in the graphs on the assumption of the unbounded
resources. The increase rate of execution time in the parallel execution by Inpla
gradually becomes close to, according to increasing the number of threads, the
trends of the parallel computation in the graphs on the assumption.</p>
      <p>We note that, in the computation of unary natural numbers, the execution
of the streaming version is slower than the batch version as shown in the graph
on the left side in Figure 4. The graph on the right side shows the ratio of steps
in the streaming version to steps in the batch version on the assumption of the
fib n (unary natural numbers, batch-add, Inpla)
6.0
fib n (unary natural numbers, streaming-add, Inpla)
6.0
unbounded resources. The ratio becomes around 0.4 according to increasing n
in ack 3 n. This means that there is a limited bene t of the parallelism, even
if we assume unbounded resources. In the real computation, the cost of parallel
execution more a ects the execution time in comparison to the bene t of the
parallelism, and thus the streaming version becomes slower.</p>
      <p>Ackermann function. Figure 5 shows the execution time of each program for
Ackermann function by using Inpla. We see that, except for the batch operation
version, the parallel computation follows well the trends on the assumption of
the unbounded resources. On the other hand, the parallel execution of the batch
operation version takes quite a long time compared to the streaming version.
This is because, in the unbounded resources, not only that there is no signi
cant di erence in sequential and parallel execution, but also that there is a cost
of parallel execution such as scheduling of threads execution uselessly. These
are some of the reasons why the parallel execution does not always have good
performance, but are improved in the streaming version.</p>
      <p>Bubble sort. Figure 6 shows the execution time of the two programs for Bubble
sort using Inpla. As anticipated by the graphs on the assumption of the
unbounded resources, we see that the improved version performs best as expected.</p>
      <p>Fig. 5. The execution time of Ackermann function by Inpla
Although discussed for many years, we believe that parallel implementations of
interaction nets is still a very new area and much needs to be done. In this work
we have assumed unbounded resources in terms of the number of processing
elements available. This is a reasonable assumption with GPU when many
thousands of processing elements are available. We analysed the execution result of
the multi-threaded execution by using the investigation result on the
assumption, and also showed that, on the one hand, these perform as the best expected,
and on the other hand, some of execution results take something away from the
investigation results due to an overhead of using parallel technologies as
anticipated by the investigation. We hope the ideas in this paper may help in moving
this work forward.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>A.</given-names>
            <surname>Hassan</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Mackie</surname>
          </string-name>
          , and
          <string-name>
            <given-names>S.</given-names>
            <surname>Sato</surname>
          </string-name>
          .
          <article-title>Compilation of interaction nets</article-title>
          .
          <source>Electr. Notes Theor. Comput. Sci.</source>
          ,
          <volume>253</volume>
          (
          <issue>4</issue>
          ):
          <volume>73</volume>
          {
          <fpage>90</fpage>
          ,
          <year>2009</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>A.</given-names>
            <surname>Hassan</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Mackie</surname>
          </string-name>
          , and
          <string-name>
            <given-names>S.</given-names>
            <surname>Sato</surname>
          </string-name>
          .
          <article-title>A lightweight abstract machine for interaction nets</article-title>
          .
          <source>ECEASST</source>
          ,
          <volume>29</volume>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>E.</given-names>
            <surname>Jiresch</surname>
          </string-name>
          .
          <article-title>Towards a gpu-based implementation of interaction nets</article-title>
          . In B. Lowe and G. Winskel, editors, DCM, volume
          <volume>143</volume>
          <source>of EPTCS</source>
          , pages
          <volume>41</volume>
          {
          <fpage>53</fpage>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>Y.</given-names>
            <surname>Lafont</surname>
          </string-name>
          .
          <article-title>Interaction nets</article-title>
          .
          <source>In Proceedings of the 17th ACM Symposium on Principles of Programming Languages (POPL'90)</source>
          , pages
          <fpage>95</fpage>
          {
          <fpage>108</fpage>
          . ACM Press,
          <year>1990</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>R.</given-names>
            <surname>Milner</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Tofte</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Harper</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>MacQueen. The</surname>
          </string-name>
          <article-title>De nition of Standard ML (Revised)</article-title>
          . MIT Press,
          <year>1997</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>J. S.</given-names>
            <surname>Pinto</surname>
          </string-name>
          .
          <article-title>Sequential and Concurrent Abstract Machines for Interaction Nets</article-title>
          . In J. Tiuryn, editor,
          <source>Proceedings of Foundations of Software Science and Computation Structures (FOSSACS)</source>
          ,
          <source>number 1784 in Lecture Notes in Computer Science</source>
          , pages
          <volume>267</volume>
          {
          <fpage>282</fpage>
          . Springer-Verlag,
          <year>2000</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7. G. van Rossum and
          <string-name>
            <given-names>F. L.</given-names>
            <surname>Drake. The Python Language Reference Manual</surname>
          </string-name>
          .
          <source>Network Theory Ltd.</source>
          ,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>