Sripriya G wrote:
> ===============About proxies=================
> When a proxy is made from a function, what happens to side-effects?
>
> Eg1:
>
>     val myCh1 = Channel.channel();Channel.put(myCh1,1);Channel.put(myCh1,2);
>     Channel.put(myCh1,3); Channel.put(myCh1,4);
>
>     fun g = Channel.put(myCh2, (Channel.get myCh1)*10);
>     val g1 = Remote.proxy g;
>
> Here both g and g1 behave the same way.
>
> Eg2:
>
>     fun f a b = (a:=b)
>     val f1 = Remote.proxy f;
>
>     val a = ref 2;
>     val _ = f a 3;  (* a is now ref 3 *)
>     val _ = f1 a 4; (* a is still ref 3 *)
>
> Here, f and f1 have different behaviours, because of the cloning bit  
> of proxies.
>   

Are you sure? This shouldn't be, and I certainly cannot reproduce it:

val r = ref 0;
- fun f n = r := n;
val f : int -> unit = _fn
- val g = Remote.proxy f;
val g : int -> unit = _fn
- g 4;
val it : unit = ()
- r;
val it : int ref = ref 4

A proxy really is just that, a proxy. It doesn't duplicate or modify 
state or change behaviour.

(The only way in which a proxy call differs from a direct call to the 
target function (locally) is that argument and result are pickled 
temporarily, so you might get failure if they contain something that is 
sited.)

> ===============About Remote execution=================
>
> I have an agent which has the following functionality:
>
> Takes:  (n, s1, s2)
> Take an integer(n), read something off a channel (given by the ticket : s1)
> do some work and post something to another channel (given by the ticket : s2)
>   

Do you mean tickets in the Alice sense? I'm not sure I understand why 
you would want to identify channels with tickets.

> The agent has the following signature:
>
> signature MY_AGENT =
> sig
>     val doJob :  int -> string -> string -> unit
> end
>
> structure myAgent : MY_AGENT =
> struct
> ...
> end
>
> I want to offer this as a service that can be remotely invoked.
> Here is what I did:
>
> structure myAgentProxy  =
>      Remote.Proxy (signature S = MY_AGENT
>                    structure X = myAgent
>                    )
>   

This creates a proxy to your structure, i.e., a structure of individual 
proxies (in this case only one).

> val myAgentProxyComp = Component.fromPackage (pack myAgentProxy :MY_AGENT);
>   

This creates a component that does not do anything except exporting the 
original proxy, i.e., a proxy to a function on the original site (in 
particular, the component does not contain the target function itself).

> val hosts = ["h1","h2"]
> val myAgentList =
> List.map
> ( fn h =>
>    let
>     structure s1 =
>     spawn unpack Remote.run (h, myAgentProxyComp):
>      (val doJob :  int -> string -> string -> unit)
>    in
>      s1.doJob;
>    end
>    )
>   

You are now running the component on remote sites but that does nothing 
but re-importing the original proxy to your own local function (and each 
invocation gives you that same proxy).

> Now, doing
> val _ = List.nth(myAgentList, 0) 2 t1 t2
>
> does not run the function on h1, but in the host where myAgentProxy  
> was made ??
>   

Yes. The function never moved, because you created a local proxy right 
away and passed around that instead.

I think what you are trying to do is transferring the doJob function to 
the remote sites and get back proxies from there. Is that correct? To do 
so, you have to create the proxies on the remote sites.

val myAgentComp =
    comp
        import structure Remote from "x-alice:/lib/distribution/Remote"
    in
        val doJob : int -> string -> string -> unit
    with
        fun doJob' (n, s1, s2) = ...
        val doJob = Remote.proxy doJob'
    end

val hosts = ["h1", "h2"]
val myAgents =
    List.map
        (fn h => spawn
         let
             structure Agent = unpack Remote.run (h, myAgentComp) : MY_AGENT
         in
             Agent.doJob
         end) hosts

Note that myAgentComp creates a proxy each time it's run on a remote 
site. For that it has to import the Remote module on the respective 
site. The component contains the full code of doJob (which has to be 
unsited to be picklable, i.e. may not refer to any resources from the 
local site; you have to add local imports for all resources you need).

Hope that helps,
- Andreas


_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users

Reply via email to