//MC# Examples // nth Fibonacci number parallel computation using System; public class Fib { public handler Get2 long() & channel c1( long x ) & channel c2( long y ) { return x + y; } public async Compute( long n, channel( long ) c ) { //Console.WriteLine( "Compute: n=" + n ); if ( n <= 1 ) c ! ( n ); else { new Fib().Compute( n-1, c1 ); //Compute( n-1, c1 ); new Fib().Compute( n-2, c2 ); //Compute( n-2, c2 ); c ! ( (long)Get2 ? () ); } } } public class ComputeFib { handler Get long() & channel c( long x ) { return x; } public static void Main( string[] args ) { if ( args.Length < 1 ) { Console.WriteLine( "Usage: Fib.exe " ); return; } int n = System.Convert.ToInt32( args [ 0 ] ); ComputeFib cf = new ComputeFib(); Fib fib = new Fib(); fib.Compute( n, cf.c ); Console.WriteLine( "For n = " + n + " value is " + cf.Get?() ); } }