MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems...

35
MC# 2.0: a language for concurrent distributed programming based on .NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky, Russia

Transcript of MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems...

Page 1: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

MC# 2.0: a language for concurrent distributed programming based on .NET

Yury SerdyukProgram Systems Institute of Russian Academy of Sciences,Pereslavl-Zalessky, Russia

Page 2: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Contents

1. Introduction: MC# - a language for .NET-based concurrent distributed programming.

2. Novel constructs of MC#: movable methods, channels, handlers.

3. Programming in MC#:

- finding prime numbers,

- interaction of distributed processes.

4. Implementation.

5. Conclusions.

Page 3: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Introduction

Tools for organizing parallel computations:- MPI ( for systems with message passing),- OpenMP (for systems with shared memory)

have been implemented for C and Fortran languagesand hence are

- very low-level and- inadequate for OO languages like C++,C#,Java.

MPI and OpenMP interfaces rely on the use of- libraries, rather then on

- appropriate programming language constructs.

Page 4: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Introduction

A modern high-level programming language consist of:

1) basic constructs of the language itself, and

2) a collection of specialized libraries accessible through appropriate APIs.

A modern tendency to transfer key concepts of most important APIs into corresponding native constructs of programming languages:

- Polyphonic C# = C# + asynchronous methods

(instead of System.Threading library)

- C = C# + new data type constructors along with query definition tools

(instead of ADO.NET data subsystem)

Page 5: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Introduction

Next step in this direction:

MC# = C# + high-level constructs for concurrent distributed programming

(instead of System.Remoting and System.Threading libraries)

Goal of MC# - to replace C and Fortran languages along with MPI and OpenMP interfaces in the area of industrial concurrent distributed programs

X10 language (IBM PERCS project – Productive Easy-to-use Reliable Computer Systems) –

“non-uniform cluster computing”

Page 6: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Introduction

MC# language –

1) there is no need to distribute computational processes over cluster nodes explicitly,

2) new computational processes can be created and distributed over accessible nodes during program execution dynamically,

3) there is no necessity to code by hand an object (data) serialization / deserialization.

Page 7: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Introduction

MC# language is an adaptation of the basic idea of the Polyphonic C# language (Benton N., Cardelli L., Fournet C. – Microsoft Research Laboratory, Cambridge, UK)for the case of concurrent distributed programming

In Polyphonic C asynchronous methods can be used either

1) on a single computer, or

2) on a set of machines where they have been fixed and interact through the remote method calls

Page 8: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Introduction

In MC# language

1) execution of an autonomous asynchronous method can be scheduled on a different machine selected (in a typical case) automatically by Runtime-system,

2) interaction of asynchronous methods that are executed on different machines is implemented using channels and channel message handlers,

3) channels and handlers are defined using chords in the Polyphonic C# style.

Page 9: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Introduction

MC# 2.0 :

1) channel message handlers

(instead the bidirectional channels),

2) different semantical treatment of channels and handlers.

Page 10: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Novel constructs of MC#

In Polyphonic C#, asynchronous methods are intended for playing two major roles:

1) the role of autonomous methods implementing the basic algorithm and executed in separate threads, and

2) that of the methods intended for delivering data to conventional, synchronous methods.

In MC# these two kind of methods form special syntactic categories of

1) movable methods and

2) channels

respectively.

Page 11: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Novel constructs of MC#

In Polyphonic C#

asynchronous methods used for data delivery are usually declared together with synchronous methods.

In MC#

such synchronous methods form another special syntactic category of channel message handlers

(or handlers for short).

Page 12: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Movable methods

Writing a parallel program in MC# reduces to labeling by keyword movable the methods that may be transferred to other machines for execution:

modifiers movable method_name (arguments) {

< method body >

}

In MC#, movable methods are the only way to create and run concurrent distributed processes.

Page 13: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Movable methods

The first key feature of MC# language:in general, during a movable method call, all necessary data, namely,

1) the object itself to which given movable method belongs, and

2) arguments for the latter

are only copied (but not moved !) to the remote machine.Changes made afterwards to the copy will not affect theoriginal object.

Page 14: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Movable methods

Two modes of parallelizing MC# programs:

- functional: an object for which a movable method is called, is not transferred to a remote machine,

- nonfunctional: forces the object to be moved to the remote machine.

These modes are defined by the corresponding modifiers in the movable method declaration (the default value is functional ).

Page 15: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Channels and handlers

Channels and handlers are the tools to support the interaction of distributed objects.

CHandler getInt int ( ) & Channel sendInt ( int x ) {

return ( x );

}

Channels and handlers cannot have a static modifier, and so they are always bound to some object:

Object

h c

Page 16: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Channels and handlers

a.sendInt ( x )

- send an integer x by the channel sendInt

A handler is used to receive values from its jointly defined channel (or group of channels):

int m = a.getInt ()

Page 17: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Channels and handlers

Similarly to Polyphonic C#, it is possible to define several channels in a single chord:

CHandler equals bool ( ) & Channel c1 ( int x )

& Channel c2 ( int y ) {

if ( x == y )

return ( true );

else return ( false );

}

A general rule for chord triggering:

the body of a chord is executed only after all methods declared in the chord header have been called.

Page 18: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Channels and handlers

An object with a single handler for multiple channels

Object

h

c1

c2

Page 19: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Channels and handlers

An object with a “shared” channel

Object

h1

h2

c1

c2

c3

Page 20: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Channels and handlers

The second key feature of MC#:

the channels and handlers can be passed as arguments to the methods (in particularly, to the movable methods) separately from the object to which they belong.

Message sending by remote channel:

(0) copying of the channel to remote site,

(1) message sending by (remote) channel,

(2) message redirection to the original site.

Site s Object a

hs cs

Site r

( 0 ) ( 1 ) cs

( 2 )

Page 21: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Channels and handlers

The third key feature of MC#:

if channels and handlers were copied to a remote site autonomously or as part of some object, then they become proxy objects

Message reading from remote handler:

(0) copying of the handler to remote site,

(1) message reading from (remote) handler,

(2) reading redirection to the original site,

(3)message return from the original site,

(4)result message return.

Site s Object a

hs cs

Site r ( 0 ) (4)

hs

(2) (1)

(3)

Page 22: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Programming in MC#

Example - finding prime numbers by the sieve method (“Eratosthenes sieve”)

for given a natural number N, enumerate all primes in the interval from 2 to N.

Page 23: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Eratosthenes sieve

Sieve

couthinhinhinhin

Site i

sendPrime

Page 24: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Eratosthenes sieve

Sieve

couthinhinhinhin

Site i

sendPrime

Sieve

couthinhinhinhin

Site i + 1

Page 25: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Eratosthenes sieve

movable Sieve ( CHandler int() getList, Channel (int) sendPrime ) { int p = getList(); sendPrime ( p ); if ( p != -1 ) { new CSieve().Sieve ( hin, sendPrime ); filter ( p, getList, cout ); } }

CHandler hin int() & Channel cout ( int x ) { return ( x ); }

Page 26: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Programming in MC#

Example – an interaction inside a set of distributed processes in accordance with the “all to all” principle

class BDChannel {

CHandler Receive object()

& Channel Send (object obj ) {

return ( obj );

}

}

Page 27: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

All2all example

SendReceive

SendReceive

DistribProcess1 DistribProcess2

bdc1

bdc2

Page 28: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

All2all example

SendReceive

SendReceive

DistribProcess1 DistribProcess2

bdc1

bdc2

SendReceive

bdc2

SendReceive

bdc1

Page 29: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

All2all example

class DistribProcess { movable Start ( int i, … ) { // i is a process proper number BDChannel bdc = new BDChannel(); sendBDC ( i, bdc ); BDChannel[] bdchans = (BDChannel[]) bdc.Receive(); // Send messages to other processes for ( j = 0; j < bdchans.Size; j++ ) if ( j != i ) bdchans[j].Send ( “ … “); // Receive messages from other processes for ( j = 0; j < bdchans.Size - 1; j++ ) Console.WriteLine ( (string) bdc.Receive() ); }}

Page 30: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Implementation

Current implementation based on “bidirectional channels”:

1) compiler from MC# to C#,

2) Runtime-system.

The compiler’s main function –

to replace movable methods calls by queries to the Runtime-system which schedules execution for the methods.

Page 31: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Implementation

Main components of the Runtime-system:

1) Resource Manager – a process implementing (currently, the simplest) centralized scheduling of resources (the cluster nodes),

2) WorkNode – a process running on each cluster node; it’s purpose – to accept the movable methods scheduled for execution on the given node and to run them in separate threads

Page 32: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Implementation

Compiler & Runtime-system:

both Windows and Linux versions

.NET for Linux – the Mono system (www.mono-project.com): a free implementation of .NET for Unix-like systems

Page 33: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Implementation

MC# applications:

- fractal calculation,

- (simple) 3D rendering,

- radar-tracking signals processing,

- computational molecular dynamics

etc.

Page 34: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Implementation

Processing time (in sec.) for 40 Mb input file

for radar-tracking signals processing task

The tests were conducted on the “SKIF K-1000” cluster

(98th in Top500, November 2004) of the United Institute of Informatics Problems, National Academy of Sciences of Belarus

0,05,0

10,0

15,020,025,030,035,0

40,045,050,0

1 2 4 8 12 16 20 24 28 32

Page 35: MC# 2.0: a language for concurrent distributed programming based on.NET Yury Serdyuk Program Systems Institute of Russian Academy of Sciences, Pereslavl-Zalessky,

Conclusion

MC# project site - http://u.pereslavl.ru/~vadim/MCSharp

Future work:

1) implementing MC# in full accordance with the ideas put forward in the given presentation,

2) decentralized scheduling of movable methods calls,

3) providing support for modern fast interconnects

(infiniband),

4) developing MC# programming system for metacluster computations.