Welcome to the homepage of MC# language!
MC# Project
Home page 
MC# language 
Documentation 
Publications 
 Code examples 
FAQ 

 
Downloads
MC# Programming 
System
 

 
Related links
Parallel C# 
Polyphonic C# 
SKIF Project 

 
Contacts
 Contacts 


Mono powered

Microsoft .Net powered


 
   MC# as a language for multi-threaded programming

MC# as a language for multi-threaded programming

 

Asynchronous methods implemented in MC# language are the analogue of corresponding methods from Polyphonic C# language. The difference between asynchronous and movable methods is that first ones are always scheduled for execution locally, i.e. on the same machine where method was called. In conjunction with channels they represent high level mechanism which in most cases can eliminate the need in conventional .NET threads.

 

The definition of asynchronous methods in MC# programs is identical to definition of movable methods:

 

modifiers async method_name( formal parameters )

{

 < method body >

}

 

For synchronization and interaction between asynchronous methods traditional methods can be used (for example, shared variables in conjunction with locking mechanisms) as well as more preferable and convenient mechanisms of channels from MC# language.

 

Below you can see some test programs written in C# (sequential algorithms) and MC# (parallel algorithms written for computers with 2-cores/processors), as well as some comparison results measured on machine with Intel Core 2 2.4 GHz 1 Gb RAM.

 

1. Calculation of N-th Fibonacci number

 

C#-program:

 

using System;

 

class ClassicComputeFib

{

 public static void Main(String[] args)

 {

  int n = System.Convert.ToInt32(args[0]);

  Console.WriteLine("For n = " + n + " value is " + cfib(n));

 }

 

 private static int cfib(int n)

 {

  if (n <= 1)

   return 1;

  else

   return cfib(n - 1) + cfib(n - 2);

 }

}

 

 

MC#-program:

 

using System;

 

class AsyncComputeFib {

 public static void Main( String[] args ) {

  int result;

  int n = System.Convert.ToInt32 ( args [0] );

  if ( n <= 1 )

   result = 1;

  else {

   AsyncComputeFib acf = new AsyncComputeFib();

   acf.Compute( n - 1, acf.c1 );

   acf.Compute( n - 2, acf.c2 );

   result = acf.Get();

  }

  Console.WriteLine( "For n = " + n + " value is " + result );

 }

 

 int Get() & Channel c1 ( int x ) & Channel c2 ( int y ) {

  return x + y;

 }

 

 public async Compute( int n, Channel (int) c ) {

  c ! ( cfib ( n ) );

 }

 

 private int cfib( int n ) {

  if ( n <= 1 )

   return 1;

  else

   return cfib( n - 1 ) + cfib( n - 2 );

 }

}

 

The comparison of execution times of abovementioned programs:

 

2. Product of big matrixes

This program multiplies two randomly generated square matrixes.

 

The comparison of execution times of abovementioned programs:

 

3. Example “Fast Fourier Transform”

 

Program code in C# language (serial algorithm)

 

Program code in MC# language (parallel algorithm)

 

The comparison of execution times of abovementioned programs:

 

 

4. Example “Dining Philosophers”

This program is the modification of corresponding program written in Polyphonic C#, which demonstrating the abilities of multithreaded programming.

(The source program was a little bit modified because the current implementation of MC# compiler doesn’t support channels shared among several bounds).

 

Program code (in MC# language)

 

Screenshot of the program:

 

 


Âåñü Ïåðåñëàâëü