MC - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

MC

Description:

async postEvent ( EventInfo data ) { ???? ??????. async IntChannel ( int value ) ... 'bluesky' 'skyblue' class Buffer { int Get() & async Put ( int n ) { return n; ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 35
Provided by: vad51
Category:
Tags: bluesky | data

less

Transcript and Presenter's Notes

Title: MC


1
MC ?????????? ????? C ??? ????????????????
?? ?????????? ? GRID-????????????
2
??????????
  • ???????? ?????????? ????? ? ??????????
    ???????????? ????????????? ????????????????
  •   ??????????? ?????? ? ?????? ???????
    ?????????????
  •   ???????????????? ?? ????? MC ????????????
    ?????? ? ??????
  •   ?????? ?????????? ??????????? ????????????
    ???????????
  •   MPI ??? C vs. ?????? .NET-??????????

3
Polyphonic C - ?????????? ????? C ??????????
???????????? ????????????? ????????????????
Nick Benton, Luca Cardelli, Cedric Fournet (
Microsoft Research, Cambridge ).
Modern Concurrency Abstractions for C -    to
appear in ACM Transactions on Programming
Languages and Systems
http//research.microsoft.com/nick/polyphony
4
? - ?????????? ( R. Milner, 1992 )
Join ?????????? ( ?. Fournet, G.Gonthier, 1996
)
C ? Polyphonic C ( N.Benton, L.Cardelli,
C.Fournet, 2002 )
Polyphonic C C
??????????? ?????? ?????? ( chords )
5
?????????? ?????? ?????????? ?????????
??????? ??????????
?????????? ??????
??????????? ?????? ?) ????? ?????????????, ??
????????, ??????????
?) ??????? ?? ??????????
???????????
?) ??????????? ? ??????? ????????? ?????
async
?????? void
?) ??????????? ??? ?????????? ? ??????
??????
( ??? ????? ??? ??????? ?? ?????????? ???? ).
async postEvent ( EventInfo data )   ????
??????
async IntChannel ( int value ) . . .
6
?????? ( ????? ?????????????, ????? ?????????? )
????????? ????
class Buffer   string Get() async Put (
string s ) return s  
  • ?????????? ?????? Buffer ?? ??????? ??????????
    ????? ??????? ???? ?????? ??????????? ? ?????
    ?????????? ??????, ??????? ?????? ????? Get
  • ????? ??????? ?????? ????? ????????? ??????
    ???? ?????????? ?????

7
Buffer buff new Buffer() buff.Put ( blue
) buff.Put ( sky ) Console.WriteLine (
buff.Get() buff.Get() )
bluesky
skyblue
  • ???????????? ???? ? ??????????????? ????? (
    ?????????? ???????? )
  • ?????????????? ???????????? ???????????
    ?????????? ?????? ??? ?????? ?????????? ?????? ??
    ?? ?????????, ???????? ??????????? ??????? ??
    ????????, ???????????? ???? ?????? ??? ??????????
    ???????? ????????? ?????????.

8
class Buffer int Get() async Put ( int
n ) return n string Get()
async Put ( int n ) return
n.ToString()
  • ????????????? ???? ??????? ?????????
    ??????????? ??????????? ??????? Get , ?? ????? ??
    ??? ????? ??????????????? ? ??????????? ???????
    Put , ???????? ?????????????? ?? ?????? ?????????
    ?????.

9
????????? ? ?????????? ????? C
return-type type void async
? ??????????? ??????? ??????, method-declaration
?????????? ?? chord-declaration
chord-declaration method-header
method-header body
method-header attributes modifiers
return-type member-name (
formals )
10
?????? 1 ????? OneCell
get()
return o
empty
contains(o)
class OneCell public OneCell ()
empty()   public void Put ( object o )
private async empty()
contains ( o )   public object Get ( )
private async contains ( object
o ) empty() return o  
put(o)
11
?????? 2 ?????? Readers - Writers
  • ??????????? ?????? ??? ??????? ?????????
  • ?????? ??? ????????????? ??????? ? ??????????

Exclusive
Shared
??????
ReleaseShared
ReleaseExclusive
??????

12
class ReaderWriter ReaderWriter () idle()
public void Shared() async idle() s ( 1
) public void Shared() async s ( int n
) s ( n 1 ) public void
ReleaseShared() async s ( int n ) if (
n 1 ) idle () else s ( n 1 )
public void Exclusive() async idle()
public void ReleaseExclusive() idle()
13
class ReaderWriterPrivate ReaderWriterPrivate(
) idle() private int n 0 public void
Shared() async idle() n 1 s() public
void Shared() async s() n s() public
void ReleaseShared() async s() if (
--n 0 ) idle() else s() public void
Exclusive() async idle() public void
ReleaseExclusive() idle()
14
class ReaderWriterFair . . . //
?????????? ReaderWriterPrivate public void
Exclusive ( ) async s() t () // ?????
?????? ?? ??????????? wait ( ) public
void ReleaseShared ( ) async t () if (
-- n 0 ) // ?????????? ?????
??????????? ????? idleExclusive ()
else t() void wait () async
idleExclusive ( )
15
??????????? ??????????? ?????????
Service
Request
channel
r
arg , channel
arg1 , ic1
arg2 , ic2
ic1
Client
ic2
wait
16
public delegate async IntChannel ( int v
) public class Service public async Request
( string arg, IntChannel ic ) int r .
. . // ????????? ??????? ic ( r )
17
class Join2 public void wait ( out int x, out
int y ) public async ic1 ( int v1 ) public
async ic2 ( int v2 ) x v1 y v2
class Client public static void Main (
string args ) Service s . . . Join2
j2 . . . s.Request ( args 1 , new
IntChannel ( j2.ic1 ) ) s.Request ( args 2
, new IntChannel ( j2.ic2 ) ) . . . int
i, j j2.wait ( out i, out j ) . . .
18
?????? 3 ????????? ?????????? ????? ????????? ??
????? MC
public delegate async IntChannel ( int v ) class
Fib public async Compute ( int n, IntChannel
ic ) if ( n lt 20 ) ic ( cfib ( n ) ) else
Compute ( n 1, new IntChannel ( ic1 ) )
Compute ( n 2, new IntChannel ( ic2 ) )
public int Get() async ic1 ( int x )
async ic2 ( int y )
return ( x y ) public int cfib ( int n )
. . .
19
?????? 3 ????????? ?????????? ????? ????????? ??
????? MC
class ComputeFib public static void Main (
string args ) int n System.Convert.ToIn
t32 ( args 0 ) Fib fib new Fib()
fib.Compute ( n, new IntChannel ( c ) )
Console.WriteLine ( n n result Get()
) public static int Get() async c ( int
x ) return ( x )
20
?????? 3 ????????? ?????????? ????? ????????? ??
????? MC
class Fib public movable Compute ( int n,
Channel c ) if ( n lt 20 ) c ( cfib (
n ) ) else Compute ( n 1 , ic1 )
Compute ( n 2 , ic2 ) public
int Get() Channel ic1 ( int x )
Channel ic2 ( int y )
return ( x y ) public int cfib ( int n )
. . .
21
?????? 3 ????????? ?????????? ????? ????????? ??
????? MC
class ComputeFib public static void Main (
string args ) int n System.Convert.ToIn
t32 ( args 0 ) ComputeFib cf new
ComputeFib () Fib fib new Fib()
fib.Compute ( n, cf.c ) Console.WriteLine (
n n result cf.Get() ) public
int Get() Channel c ( int x ) return ( x )

22
?????? 4 ????????? ?????? ????????? ?????? ?? MC
public class BinTree public BinTree left
public BinTree right public int value
public BinTree ( int depth ) value 1
if ( depth lt 1 ) left null right
null else left new BinTree
( depth 1 ) right new BinTree ( depth
1 )
23
?????? 4 ????????? ?????? ????????? ?????? ?? MC
class SumBinTree public static void Main (
string args ) int depth
System.Convert.ToInt32 ( args 0 )
SumBinTree sbt new SumBinTree () BinTree
btree new BinTree ( depth ) sbt.Sum (
btree, sbt.c ) Console.WriteLine ( Sum
sbt.Get() ) int Get () Channel c (
int x ) return ( x ) public movable Sum (
BinTree btree, Channel c ) if ( bt.left
null ) c ( bt.value ) else Sum (
btree.left , c1 ) Sum ( btree.right , c2 ) c (
Get2 () ) int Get2 () Channel c1 (
int x ) Channel c2 ( int y )
return ( x y )
24
??????????????? ?????? ?? MC
  • - ?????????? c ! v
  • c ? x . P
  • MC int Get() Channel c
    ( int x )
  • return x
  • public class BDChannel
  • public BDChannel ( )
  • private int r ( ) private Channel c ( int x )
  • return x
  • public void send ( int x ) c ( x )
  • public int receive ( ) r ( )

25
?????? 5 ???????? ?????? ??????????
movable Sieve ( BDChannel in, BDChannel out )
int head in.receive () if ( head -1 )
out.send ( -1 ) else out.send ( head
) BDChannel inter new BDChannel ()
Sieve ( inter, out ) filter ( header, in,
inter ) . . . Main ( string args )
int N System.Convert.ToInt32 ( args 0 )
BDChannel nats new BDChannel() BDChannel
primes new BDChannel() Sieve ( nats, primes
) for ( int i 2 i lt N i ) nats.send
( -1 ) while ( ( int p primes.receive() ) !
-1 ) Console.WriteLine ( p )
26
?????? ?????????? ??????????? ????????????
???????????
??????? ????????????? ????????? ?????????
class intQ private Queue q public intQ ( )
q new Queue ( ) public void add ( int i )
q.Enqueue ( i ) public int get ( ) return
( int ) q.Dequeue ( ) public bool empty get
return q.Count 0
27
?????? ?????????? ??????????? ????????????
???????????
??????? ??????????? ??????? ( ?????????? ???????
)
class threadQ private Queue q public
threadQ ( ) q new Queue ( ) public bool
empty get return ( q.Count 0 )
public void yield ( object myCurrentLock )
q.Enqueue ( Thread.CurrentThread )
Monitor.Exit ( myCurrentLock ) try
Thread.Sleep ( Timeout.Infinite ) catch
( ThreadInterruptedException )
Monitor.Enter ( myCurrentLock ) q.Dequeue()
public void wakeup ( ) ( (Thread) q.Peek()
).Interrupt()
28
?????? ?????????? ??????????? ????????????
???????????
class Test public Test ( . . . ) . . .
public int Receive ( ) public async Send ( int
i ) return ( i ) class Test
private const int mReceive 1 ltlt 0 private
const int mSend 1 ltlt 1 private threadQ
ReceiveQ new threadQ ( ) private intQ SendQ
new intQ ( ) private const int mReceiveSend
mReceive mSend private BitMask s new
BitMask ( ) private object mlock ReceiveQ
public Test ( . . . ) . . . . . .
29
?????? ?????????? ??????????? ????????????
???????????
. . . private void scan ( ) if ( s.match (
mReceiveSend ) ) ReceiveQ.wakeup(
) OneWay public void Send ( int i )
lock ( mlock ) SendQ.add ( i ) if ( !
s.match ( mSend ) ) s.set ( mSend )
scan( ) . . .
30
?????? ?????????? ??????????? ????????????
???????????
. . . public int Receive ( )
Monitor.Enter ( mlock ) if ( ! s.match (
mReceive ) ) goto now later ReceiveQ.yield
( mlock ) if ( ReceiveQ.empty ) s.clear (
mReceive ) now if ( s.match ( mSend ) )
int i SendQ.get() if ( SendQ.empty )
s.clear ( mSend ) scan ()
Monitor.Exit ( mlock ) return ( i )
else s.set ( mReceive ) goto later
31
MPI ??? C
J. Willcock, A.Lumsdaine, A.Robinson
Using MPI with C and the Common Language
Infrastucture,
  • Java Grande / ISCOPE 2002 Conference, Seatle,
    USA, 3-5 Nov., 2002.
  • Native-????????? ? MPI
  • ????????-??????????????? ????????? ? MPI
  • LAM/MPI 6.5.6
  • FreeBSD 4.5
  • Rotor-?????????? C
  • Platform Invocation Service .NET ??? ?????? C
    MPI-???????

32
?????? .NET-?????????? ?????????????? ????????
?????????? movable-???????
  • ?????????? private-?????? ??? ??????? ?????????
  • ?? TCP-??????????
  • ?????????? ????? ?????????? ?????????? , ???????
    ?????????? ? ????????? ????
  • ?????? ??????????? ??????? ?? ??????? ??????????
    ? private-?????? ?? ?.1
  • ?????? ??????? movable-??????? ???????? ??????? ?
    ????????? ????????????? ????????

33
??????????? ????????? ???????? ????
??????? ????????? WorkNode
Communicator
??????? ????????
movable- ??????
CommExec
. . .
??????? ????????? ?????????
?? ????????? ????????- ?????? ????????
. . .
?????? ?????????? movable-???????
????????? ?????????
34
??????? ??? C, C, ? ( ?????????????? ??????,
2 ?????????? ), C(skif), T-system
????????? 1,6 ??? ?? 256 ??
Write a Comment
User Comments (0)
About PowerShow.com