public void Run(int n)
        {
            // create unit vector

            double[] u = new double[n];
            double[] tmp = new double[n];
            double[] v = new double[n];

            for (int i = 0; i < n; i++)
                u[i] = 1.0;

            int nthread = Environment.ProcessorCount;

            BarrierHandle barrier = new BarrierHandle(nthread);
            // objects contain result of each thread

            Approximate[] apx = new Approximate[nthread];

            // thread handle for waiting/joining

            Thread[] threads = new Thread[nthread];

            // create thread and hand out tasks

            int chunk = n / nthread;
            for (int i = 0; i < nthread; i++)
            {
                int r1 = i * chunk;
                int r2 = (i < (nthread - 1)) ? r1 + chunk : n;

                apx[i] = new Approximate(u, v, tmp, r1, r2);
                apx[i].Barrier = barrier;
                threads[i] = new Thread(new ThreadStart(apx[i].Evaluate));
                threads[i].Start();
            }

            // collect results

            double vBv = 0, vv = 0;
            for (int i = 0; i < nthread; i++)
            {
                threads[i].Join();

                vBv += apx[i].m_vBv;
                vv += apx[i].m_vv;
            }

            var res = Math.Sqrt(vBv / vv);
            Console.WriteLine("{0:f9}", res);
        }
Example #2
0
    public static double RunGame(int n)
    {
        // create unit vector
        double[] u   = new double[n];
        double[] tmp = new double[n];
        double[] v   = new double[n];

        for (int i = 0; i < n; i++)
        {
            u[i] = 1.0;
        }

        int nthread = Environment.ProcessorCount;

        BarrierHandle barrier = new BarrierHandle(nthread);

        // objects contain result of each thread
        Approximate[] apx = new Approximate[nthread];

        // thread handle for waiting/joining
        Thread[] threads = new Thread[nthread];

        // create thread and hand out tasks
        int chunk = n / nthread;

        for (int i = 0; i < nthread; i++)
        {
            int r1 = i * chunk;
            int r2 = (i < (nthread - 1)) ? r1 + chunk : n;

            apx[i]         = new Approximate(u, v, tmp, r1, r2);
            apx[i].Barrier = barrier;
            threads[i]     = new Thread(new ThreadStart(apx[i].Evaluate));
            threads[i].Start();
        }

        // collect results
        double vBv = 0, vv = 0;

        for (int i = 0; i < nthread; i++)
        {
            threads[i].Join();

            vBv += apx[i].m_vBv;
            vv  += apx[i].m_vv;
        }

        return(Math.Sqrt(vBv / vv));
    }
Example #3
0
    private static double RunGame(int n)
    {
        int V_3;

        double[] V_0 = new double[n];
        double[] V_1 = new double[n];
        double[] V_2 = new double[n];
        for (V_3 = RemoteConstantLoader.LoadInt32(0x1d); V_3 < n; V_3 += RemoteConstantLoader.LoadInt32(0x1f))
        {
            V_0[V_3] = RemoteConstantLoader.LoadFloat64(30);
        }
        int           V_4 = Environment.ProcessorCount;
        BarrierHandle V_5 = new BarrierHandle(V_4);

        Approximate[] V_6 = new Approximate[V_4];
        Thread[]      V_7 = new Thread[V_4];
        int           V_8 = n / V_4;

        for (V_3 = RemoteConstantLoader.LoadInt32(0x20); V_3 < V_4; V_3 += RemoteConstantLoader.LoadInt32(0x22))
        {
            int V_9  = V_3 * V_8;
            int V_10 = (V_3 < (V_4 - RemoteConstantLoader.LoadInt32(0x21))) ? (V_9 + V_8) : n;
            V_6[V_3]         = new Approximate(V_0, V_2, V_1, V_9, V_10);
            V_6[V_3].Barrier = V_5;
            V_7[V_3]         = new Thread(new ThreadStart(V_6[V_3].Evaluate));
            V_7[V_3].Start();
        }
        double V_11 = RemoteConstantLoader.LoadFloat64(0x23);
        double V_12 = RemoteConstantLoader.LoadFloat64(0x24);

        for (V_3 = RemoteConstantLoader.LoadInt32(0x25); V_3 < V_4; V_3 += RemoteConstantLoader.LoadInt32(0x26))
        {
            V_7[V_3].Join();
            V_11 += V_6[V_3].m_vBv;
            V_12 += V_6[V_3].m_vv;
        }
        return(Math.Sqrt(V_11 / V_12));
    }