<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 1/13/2012 8:46 PM, Mark Brown wrote:
<blockquote
cite="mid:20120114044600.GA28084@mundula.csse.unimelb.edu.au"
type="cite">
<pre wrap="">Hi Jeff,
On 12-Jan-2012, Jeff Thompson <a class="moz-txt-link-rfc2396E" href="mailto:jeff@thefirst.org"><jeff@thefirst.org></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 1/9/2012 11:15 PM, Jeff Thompson wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On 1/8/2012 8:58 PM, Mark Brown wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi Jeff,
On 06-Jan-2012, Jeff Thompson<a class="moz-txt-link-rfc2396E" href="mailto:jeff@thefirst.org"><jeff@thefirst.org></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hello again. I'm using the csharp grade to compile the following.
:- pred multiPred(int::out) is multi.
multiPred(1).
multiPred(2).
:- pred test is semidet.
test :- if multiPred(X), X> 0 then true else fail.
In pred test, in the if statement, when "multiPred(X), X> 0" first
succeeds, the predicate succeeds, else fails. The compiled C# code
works
correctly. But the implementation throws a new runtime.Commit()
exception
when it first succeeds, and catches this in an outer try/catch block
(see
below). I can understand why the authors would have implemented it this
way, but using exceptions for message passing in normal operation is
very
inefficient.
Is there another way (where the implementation doesn't use try/catch) to
make a semidet predicate which succeeds on the first solution of some
code
block?
</pre>
</blockquote>
<pre wrap="">I don't think there is a more efficient solution,
</pre>
</blockquote>
</blockquote>
</blockquote>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">short of avoiding
nondet
code to begin with (i.e., implement your own search in det/semidet code).
</pre>
</blockquote>
</blockquote>
<pre wrap="">
I'm still struggling with this one. I set pred test to the "fast version"
which tests "X > 2" which fails and does not throw an exception. A
benchmark with 10,000,000 calls to this takes only 0.45 seconds. (Awesome!)
When I set the test back to "X > 0" where it throws the exception, the
benchmark takes 171 seconds. That's 380 times as long. This is what
"message passing with exceptions is inefficient" means. It really hurts.
Is there no help to be gotten from the compiler?
</pre>
</blockquote>
<pre wrap="">
Well, the first case never "succeeds on the first solution", so it doesn't
actually measure the functionality you're asking for. </pre>
</blockquote>
<br>
Thanks for the feedback. I did the first case where it doesn't
throw the exception as a base line to test how quickly the generated
code can search through all the cases (very quickly). The idea is
that if I only need it to search through one case, it could be even
quicker if it used an efficient mechanism to commit.<br>
<br>
<blockquote
cite="mid:20120114044600.GA28084@mundula.csse.unimelb.edu.au"
type="cite">
<pre wrap="">How does the version
using exceptions compare to the handwritten version using yield?</pre>
</blockquote>
<br>
As above, the times for Mercury code are 0.45 seconds for the
baseline and 171 seconds if it commits. For the "yield" code it is
2.33 seconds for the baseline and 2.03 if it commits after one
solution. As expected, since the "yield" code uses the same
infrastructure in both cases, it takes less time to search less
solutions. But the baseline Mercury code is faster than the "yield"
code which allocates an iterator object on the heap for every
"foreach" loop (as opposed to Mercury's more efficient approach of
using continuations).<br>
<br>
<table style="border-collapse: collapse;width:181pt" border="0"
cellpadding="0" cellspacing="0" width="241">
<colgroup><col
style="mso-width-source:userset;mso-width-alt:3986;width:82pt"
width="109"> <col style="width:48pt" width="64"> <col
style="mso-width-source:userset;mso-width-alt:2486;width:51pt"
width="68"> </colgroup><tbody>
<tr style="height:15.0pt" height="20">
<td style="height:15.0pt;width:82pt" height="20" width="109"><br>
</td>
<td style="width:48pt" width="64">X > 2</td>
<td style="width:51pt" width="68">X > 0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td style="height:15.0pt" height="20">Mercury 11.07</td>
<td align="right">0.45</td>
<td align="right">171</td>
</tr>
<tr style="height:15.0pt" height="20">
<td style="height:15.0pt" height="20">"yield"</td>
<td align="right">2.33</td>
<td align="right">2.03</td>
</tr>
</tbody>
</table>
<br>
<blockquote
cite="mid:20120114044600.GA28084@mundula.csse.unimelb.edu.au"
type="cite">
<pre wrap="">
Also, how do the savings, if any, compare to the amount of time required to
perform a typical search? The reason I ask is that the project I work on
uses nondet search extensively, but the searches are millisecond-scale at
the very least. Hence microsecond-scale costs of exceptions are not as
painful for us as the rule-of-thumb would suggest.
</pre>
</blockquote>
Can you give a concrete example or a reference for a nondet search
so I know we are talking about the same thing? (All I can think is
that you are talking about converting all my code to run in a meta
interpreter.)<br>
<br>
Thanks,<br>
- Jeff<br>
</body>
</html>