![]() |
|
MC# as a language for multi-threaded programmingAsynchronous 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:
MC#-program:
The comparison of execution times of abovementioned programs:
2. Product of big matrixesThis 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:
|
|