|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
JPL : getting next solutions in any order from several queries ...Hello,
I have a question about queries with JPL. This is the kind of thing I am trying to : I want several concurrent "things" doing queries to prolog, and retrieving the solution in the order (I mean the order between different queries, not the solution of one query) they want. For example two "things" t1 and t2 create each a query q1 and q2, and t1 get the first solution of q1, then t2 get two solutions for q2, and t1 then get a solution for q1, then t2 close q2, then t1 get another solution of q1. So this is a classical concurrent use of prolog. What I am doing to "implement" this is to have an actor (an actor is a mailbox that can receive and send to other actors, anb that cab be thread based, but also event based, using available threads when it needs to do something ...) that do the query to the prolog engine, and the "things" are threads or actor or whatyouwant that create an object query that send a message to the prolog actor and get the result. So it is transparent for the "things", they just use a Query object, and the query object does the job of asking to the actor (what is good with actor is that I don't have to think about concurrence, since they are treating messages sequentially) And my problem is that sometimes I get exceptions like that : jpl.JPLException: this Query (9004539:logtalk_load( '.'(negociation(seller), []), [] )) is not topmost (8814217:logtalk_load( '.'(negociation(buyer), []), [] )) within its engine[-1254103840] I think there is something bad with my design and threads, but since I don't know how are things working inside JPL, I can't solve it by myself. If someone have a better idea to make these queries ... A note about actors : if they are thread based my design was working at a time, but if they are event based, then they use a thread available in a thread pool and then it seems to make a problem with JPL ... Thanks you for any help :) Victor |
|
|
Re: JPL : getting next solutions in any order from several queries ...Hi Noel
> I have a question about queries with JPL. > > This is the kind of thing I am trying to : > I want several concurrent "things" doing queries to prolog, and > retrieving the solution in the order (I mean the order between > different queries, not the solution of one query) they want. Yes you can do this with JPL > For example two "things" t1 and t2 create each a query q1 and q2, > and t1 get the first solution of q1, then t2 get two solutions for > q2, and t1 then get a solution for q1, then t2 close q2, then t1 > get another solution of q1. > > So this is a classical concurrent use of prolog. > > What I am doing to "implement" this is to have an actor (an actor > is a mailbox that can receive and send to other actors, anb that > cab be thread based, but also event based, using available threads > when it needs to do something ...) that do the query to the prolog > engine, and the "things" are threads or actor or whatyouwant that > create an object query that send a message to the prolog actor and > get the result. > > So it is transparent for the "things", they just use a Query > object, and the query object does the job of asking to the actor > (what is good with actor is that I don't have to think about > concurrence, since they are treating messages sequentially) > > And my problem is that sometimes I get exceptions like that : > jpl.JPLException: this Query (9004539:logtalk_load( > '.'(negociation(seller), []), [] )) is not topmost > (8814217:logtalk_load( '.'(negociation(buyer), []), [] )) within > its engine[-1254103840] > > > I think there is something bad with my design and threads, but > since I don't know how are things working inside JPL, I can't > solve it by myself. OK, your program has got its knickers in a twist :-) JPL is just a library, interfacing SWI-Prolog's public FLI to a JVM's public JNI. Understanding the FLI is a good basis for understanding JPL and its exceptions. I believe the following is true of FLI and JPL. You can have several engines, but at most one per thread. If you open a query in an engine while another query is still open there, the new query is stacked on top of the previous one. You must exhaust or otherwise close the new before trying to get a further solution from the old. If you break this rule, JPL throws an exception just like the above (I forget what FLI does). So for each new query you must decide, are you happy to stack it on an existing query or must it have its own engine (hence its own thread). For independent, concurrent queries you should easily be able to wrap jpl.Query in a new class which runs it in a private thread? > If someone have a better idea to make these queries ... > > A note about actors : if they are thread based my design was > working at a time, but if they are event based, then they use a > thread available in a thread pool and then it seems to make a > problem with JPL ... That encourages me to believe that you are just reusing engines inappropriately. JPL maintains its own engine pool, returning an engine when a thread's (bottom-most) query is closed, so I can't see any need for (or benefit from) another pool: try creating concurrent queries as suggested. How many queries might you need open concurrently? JPL arbitrarily limits you to 10 in jpl.c #define JPL_MAX_POOL_ENGINES 10 /* max pooled Prolog engines */ #define JPL_INITIAL_POOL_ENGINES 1 /* initially created ones */ > Thanks you for any help :) > > Victor regards Paul Singleton _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: JPL : getting next solutions in any order from several queries ...On Wed, May 28, 2008 at 11:49:16AM +0100, Paul Singleton wrote:
> Hi Noel > > OK, your program has got its knickers in a twist :-) > > JPL is just a library, interfacing SWI-Prolog's public FLI to a > JVM's public JNI. Understanding the FLI is a good basis for > understanding JPL and its exceptions. I believe the following > is true of FLI and JPL. > > You can have several engines, but at most one per thread. If you > open a query in an engine while another query is still open there, > the new query is stacked on top of the previous one. You must > exhaust or otherwise close the new before trying to get a further > solution from the old. If you break this rule, JPL throws an > exception just like the above (I forget what FLI does). > > So for each new query you must decide, are you happy to stack it > on an existing query or must it have its own engine (hence its > own thread). > > For independent, concurrent queries you should easily be able to > wrap jpl.Query in a new class which runs it in a private thread? Instead of having an actor/thread for prolog, I will have an actor/thread for each query. Since, each "things" (that are agents in my case) are creating queries sequentially, I think I will be limited by the number of agents run at the same time, but for now, this is not really my problem, since I am only doing some work for 2 agents at the same time :) Maybe later it will be a problem ... Is there a reason to why the limit of 10 engine is set in hard in the code instead of an initialisation option ? Anyway, I will try to implement it like that and I will be back if I have problems. Thanks for your clear explanation, it helped me a lot. Victor |
|
|
Re: JPL : getting next solutions in any order from several queries ...On 2008/05/28, at 10:04, Victor NOEL wrote: > I have a question about queries with JPL. > > This is the kind of thing I am trying to : > I want several concurrent "things" doing queries to prolog, and > retrieving the solution in the order (I mean the order between > different queries, not the solution of one query) they want. > > For example two "things" t1 and t2 create each a query q1 and q2, > and t1 get the first solution of q1, then t2 get two solutions for > q2, and t1 then get a solution for q1, then t2 close q2, then t1 > get another solution of q1. You can get this behavior with Logtalk (which you're already using) multi-threading features. The built-in predicates threaded_call/1-2 and threaded_exit/1-2 allows you to suspend a non-deterministic goal running in a thread and to backtrack over all solutions. Of course, the functionality of these predicates may, or may not be, exactly what you want. > So this is a classical concurrent use of prolog. > > What I am doing to "implement" this is to have an actor (an actor > is a mailbox that can receive and send to other actors, anb that > cab be thread based, but also event based, using available threads > when it needs to do something ...) that do the query to the prolog > engine, and the "things" are threads or actor or whatyouwant that > create an object query that send a message to the prolog actor and > get the result. That functionality is already available in the Logtalk+SWI-Prolog side, including all the support you need for event-driven programming. > So it is transparent for the "things", they just use a Query > object, and the query object does the job of asking to the actor > (what is good with actor is that I don't have to think about > concurrence, since they are treating messages sequentially) > > And my problem is that sometimes I get exceptions like that : > jpl.JPLException: this Query (9004539:logtalk_load( > '.'(negociation(seller), []), [] )) is not topmost > (8814217:logtalk_load( '.'(negociation(buyer), []), [] )) within > its engine[-1254103840] As we discussed in the Logtalk discussion forums, predicates that use the Logtalk compiler such as logtalk_load/1 or create_object/4 need to be synchronized. Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 4.3 Ext. 3257 Phone: +351 275319891 Fax: +351 275319899 Email: <mailto:pmoura@...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> ----------------------------------------------------------------- _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Mac OS 10.5.3 font fixHello all,
Apple has just released OS 10.5.3 and, after downloading it via Software Update, I find that the serious problem that affected XPCE's rendering of Helvetica font on my Leopard systems seems to have been fixed. I never got to the root of that problem and nobody on this list was able to confirm that it affected them too. But according to: -- OS 10.5.3 'fixes a font issue that could result in Helvetica Narrow being used in applications instead of Helvetica'.So I guess that might be closure on this one -- fingers crossed! Best wishes, Tom PS I believe that installing the OS 10.5.3 upgrade automatically updates X11 too (and makes hundreds of other changes besides). |
| Free Forum Powered by Nabble | Forum Help |