예제 #1
0
 /// <summary>
 /// Beware this is a very suboptimal solution to
 /// Fibonacci computation.
 /// It serves only as a starting point to illustrate
 /// Fork/Join framework application.
 /// </summary>
 public override void Run()
 {
     if (input <= 1)
     {
         this.output = input;
     }
     else
     {
         Fibonacci task1 = new Fibonacci(input - 1);
         Fibonacci task2 = new Fibonacci(input - 2);
         task1.Fork();
         task2.Fork();
         task1.Join();
         task2.Join();
         this.output = task1.output + task2.output;
     }
     lock (typeof(Fibonacci))
     {
         //Console.Out.WriteLine ("#{1}: fib({0}) = {2}", input, Thread.CurrentThread.GetHashCode(), output);
     }
 }
        public void ComputesFibonacci()
        {
            StringReader reader = new StringReader(Fibonacci.PreComputed);

            string line = null;
            IList list = new ArrayList();
            while ((line = reader.ReadLine()) != null)
            {
                string [] parts = line.Split(":"[0]);
                if (parts.Length < 2)
                    continue;
                int n = Int32.Parse(parts[0]);
                string fibN = parts[1].Trim();
                list.Insert(n, fibN);
            }

            int groupsixe=2;
            int num=10;
            FJTaskRunnerGroup group = new FJTaskRunnerGroup(groupsixe);
            Fibonacci f = new Fibonacci(num);
            group.Invoke(f);
            int result=f.GetAnswer();
            Assert.AreEqual(list[num], result.ToString());
        }
 /// <summary>
 /// Beware this is a very suboptimal solution to 
 /// Fibonacci computation.
 /// It serves only as a starting point to illustrate
 /// Fork/Join framework application.
 /// </summary>
 public override void Run()
 {
     if (input <= 1)
     {
         this.output = input;
     }
     else
     {
         Fibonacci task1 = new Fibonacci (input - 1);
         Fibonacci task2 = new Fibonacci (input - 2);
         task1.Fork ();
         task2.Fork ();
         task1.Join ();
         task2.Join ();
         this.output = task1.output + task2.output;
     }
     lock (typeof(Fibonacci))
     {
         //Console.Out.WriteLine ("#{1}: fib({0}) = {2}", input, Thread.CurrentThread.GetHashCode(), output);
     }
 }