2011-10-14 1 views
2

WCFおよびC#(またはF#)を使用したGather-Scatterのような操作を実装する最善の方法は何ですか?WCFおよびC#(またはF#)を使用した散布的な操作の収集

  1. 私は20ノード(コンピュータ)がWCFで接続されていると言います。
  2. 各ノードはtime durationの値を計算し、この値をmain nodeに送信します。
  3. main nodeは、すべての情報の最小値をとり、この情報をすべてのノードに返します。

EDIT:

結果コード:

open System.ServiceModel 
open System.ServiceModel.Channels 

let numberOfClients = 10 

type IMyContractCallback = 
    [<OperationContract>] 
    abstract GetDuration: duration: float -> unit 

[<ServiceContract(CallbackContract = typeof<IMyContractCallback>)>] 
type IMyContract = 
    [<OperationContract>] 
    abstract SendDuration: duration: float -> unit 

[<ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Reentrant)>] 
type MyService() = 

    let mutable totDuration = 1. 
    let callbacks = System.Collections.Generic.Stack() 

    interface IMyContract with 
    member o.SendDuration (duration) = 
     totDuration <- min totDuration duration 
     callbacks.Push (OperationContext.Current.GetCallbackChannel<IMyContractCallback>()) 
     printfn "N = %d" callbacks.Count 
     if callbacks.Count = numberOfClients then 
      for c in callbacks do c.GetDuration (totDuration) 

    interface IMyContractCallback with 
    member o.GetDuration (duration) = printfn "Minimum duration = %g" duration 

let address = "net.pipe://localhost/aaa" 

let service = MyService() 
let pipe = new NetNamedPipeBinding() 

let host = new ServiceHost(service) 
host.AddServiceEndpoint(typeof<IMyContract>, pipe, address) |> ignore 
host.Open() 

for i in 0 .. numberOfClients - 1 do 
    let client1 = System.Threading.Thread (fun() -> 
    let fact = new DuplexChannelFactory<IMyContract>(new InstanceContext(service), pipe, address) 
    let ch = fact.CreateChannel() 
    ch.SendDuration (0.4 + float i)) 
    client1.Start() 

答えて

3

あなたが簡単にWCFでこれを行うことができます。 最小値を計算した後にサーバーが起動するクライアントノードでコールバックを実装します。

WCF Callbacks; a beginners guide

+0

ありがとうございました。このヒントは多くの助けになりました。今、それは魅力のように機能します(私の最初の記事を見てください)。 –