Пример #1
0
    public static void Main()
    {
        runstate = 2; // use codepoints
        Console.WriteLine("Kiwi Demo - L/U decomposition");
        SimuSolve ssolve = new SimuSolve(problemSize);

        Kiwi.KppMark("Start");

        generate_example_coefficients();

        runstate = 3; // use codepoints
        MatrixLib.copy2d(UUtop, coefficients);
        runstate = 4; // use codepoints
        ssolve.DecomposeVerbose(LLtop, UUtop);
        runstate = 5; // use codepoints
        Console.WriteLine("Kiwi L/U demo - coefficient matrix decomposed.");
        Kiwi.KppMark("Coefficients Created");

        for (int test = 0; test < 3; test++)
        {
            runstate = 10 + test; // use codepoints
            Console.WriteLine("\nKiwi L/U demo - L/U decomposition test with rhs no {0}.", test);
            generate_example_rhs(test, true);


            float [] sol = ssolve.SolveVerbose(LLtop, UUtop, target_rhs);

            // Now see if it works as a solution
            Console.Write("Substitute back - rhs given by solution is: y=");
            MatrixLib.printa(MatrixLib.mpx(res, coefficients, sol));

            runstate = 9;
            for (int i = 0; i < res.Length; i++)
            {
                out_idx  = i;
                out_data = res[i];
            }
        }
        runstate = 20;
        Kiwi.KppMark("ThreeTestsFinished");


        Console.WriteLine("Kiwi L/U demo - L/U decomposition demo complete at {0}.", Kiwi.tnow);
    }
Пример #2
0
    public static void Main()
    {
        bool kpp = true;

        elimit = limit;
        Kiwi.KppMark("START", "INITIALISE"); // Waypoint
        Console.WriteLine("Primes Up To " + limit);
        Kiwi.Pause();
        PA[0] = vol > 0; // Process some runtime input data on this thread - prevents Kiwic running the whole program at compile time.
        Kiwi.Pause();
        // Clear array

        count1 = 2; count = 0; // RESET VALUE FAILED AT ONE POINT: HENCE NEED THIS LINE
        for (int woz = 0; woz < limit; woz++)
        {
            Kiwi.Pause();
            PA[woz] = true;
            Console.WriteLine("Setting initial array flag to hold : addr={0} readback={1}", woz, PA[woz]); // Read back and print.
        }

        Kiwi.KppMark("wp2", "CROSSOFF"); // Waypoint
        int i, j;

        for (i = 2; i < limit; i++) // Can our predictor cope with the standard optimisations?
        {
            Kiwi.Pause();
            // Cross off the multiples - optimise by skipping where the base is already crossed off.
            if (evariant_master > 0)
            {
                bool pp = PA[i];
                Console.WriteLine(" tnow={2}: scaning up for live factor {0} = {1} ", i, pp, Kiwi.tnow);
                if (!pp)
                {
                    continue;
                }
                count1 += 1;
            }
            // Can further optimise by commencing the cross-off at the factor squared.
            j = (evariant_master > 1) ? i * i : i + i;
            if (j >= limit)
            {
                Console.WriteLine("Skip out on square");
                break;
            }
            for (; j < limit; j += i)
            {
                Console.WriteLine("Cross off {0} {1}   (count1={2})", i, j, count1);
                Kiwi.Pause(); PA[j] = false;
            }
        }
        Kiwi.KppMark("wp3", "COUNTING"); // Waypoint
        Console.WriteLine("Now counting");
        // Count how many there were and store them consecutively in the output array.
        for (int w = 0; w < limit; w++)
        {
            Kiwi.Pause();
            if (PA[w])
            {
                count += 1;
                if (false)
                {
//	             PY[count] = (uint)w;
//               PZ1[count] = w;
//		     PZ2[count] = w;
                }
            }
            Console.WriteLine("Tally counting {0} {1}", w, count);
            //Console.WriteLine("Tally counting {0} {1} at {2}", w, count, Kiwi.tnow);
        }


        Console.WriteLine("There are {0} primes below the natural number {1}.", count, limit);
        Console.WriteLine("Optimisation variant={1} (count1 is {0}).", count1, evariant_master);
        Kiwi.Pause();
        Kiwi.Pause();
        Kiwi.KppMark("FINISH"); // Waypoint
        Kiwi.Pause();
        finished = true;
        Kiwi.Pause();
    }